fix: add correct windows and px keymap
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { RawCommands } from '../types'
|
import { RawCommands } from '../types'
|
||||||
|
import { isiOS } from '../utilities/isiOS'
|
||||||
const mac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false
|
import { isMacOS } from '../utilities/isMacOS'
|
||||||
|
|
||||||
function normalizeKeyName(name: string) {
|
function normalizeKeyName(name: string) {
|
||||||
const parts = name.split(/-(?!$)/)
|
const parts = name.split(/-(?!$)/)
|
||||||
@@ -27,7 +27,7 @@ function normalizeKeyName(name: string) {
|
|||||||
} else if (/^s(hift)?$/i.test(mod)) {
|
} else if (/^s(hift)?$/i.test(mod)) {
|
||||||
shift = true
|
shift = true
|
||||||
} else if (/^mod$/i.test(mod)) {
|
} else if (/^mod$/i.test(mod)) {
|
||||||
if (mac) {
|
if (isiOS() || isMacOS()) {
|
||||||
meta = true
|
meta = true
|
||||||
} else {
|
} else {
|
||||||
ctrl = true
|
ctrl = true
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Plugin, PluginKey, Selection } from 'prosemirror-state'
|
import { Plugin, PluginKey, Selection } from 'prosemirror-state'
|
||||||
import { createChainableState } from '../helpers/createChainableState'
|
import { createChainableState } from '../helpers/createChainableState'
|
||||||
|
import { isiOS } from '../utilities/isiOS'
|
||||||
|
import { isMacOS } from '../utilities/isMacOS'
|
||||||
import { CommandManager } from '../CommandManager'
|
import { CommandManager } from '../CommandManager'
|
||||||
import { Extension } from '../Extension'
|
import { Extension } from '../Extension'
|
||||||
|
|
||||||
@@ -38,13 +40,15 @@ export const Keymap = Extension.create({
|
|||||||
() => commands.selectNodeForward(),
|
() => commands.selectNodeForward(),
|
||||||
])
|
])
|
||||||
|
|
||||||
return {
|
const handleEnter = () => this.editor.commands.first(({ commands }) => [
|
||||||
Enter: () => this.editor.commands.first(({ commands }) => [
|
|
||||||
() => commands.newlineInCode(),
|
() => commands.newlineInCode(),
|
||||||
() => commands.createParagraphNear(),
|
() => commands.createParagraphNear(),
|
||||||
() => commands.liftEmptyBlock(),
|
() => commands.liftEmptyBlock(),
|
||||||
() => commands.splitBlock(),
|
() => commands.splitBlock(),
|
||||||
]),
|
])
|
||||||
|
|
||||||
|
const baseKeymap = {
|
||||||
|
Enter: handleEnter,
|
||||||
'Mod-Enter': () => this.editor.commands.exitCode(),
|
'Mod-Enter': () => this.editor.commands.exitCode(),
|
||||||
Backspace: handleBackspace,
|
Backspace: handleBackspace,
|
||||||
'Mod-Backspace': handleBackspace,
|
'Mod-Backspace': handleBackspace,
|
||||||
@@ -52,11 +56,31 @@ export const Keymap = Extension.create({
|
|||||||
Delete: handleDelete,
|
Delete: handleDelete,
|
||||||
'Mod-Delete': handleDelete,
|
'Mod-Delete': handleDelete,
|
||||||
'Mod-a': () => this.editor.commands.selectAll(),
|
'Mod-a': () => this.editor.commands.selectAll(),
|
||||||
'Ctrl-a': () => this.editor.commands.selectTextblockStart(),
|
}
|
||||||
'Ctrl-e': () => this.editor.commands.selectTextblockEnd(),
|
|
||||||
|
const pcKeymap = {
|
||||||
|
...baseKeymap,
|
||||||
Home: () => this.editor.commands.selectTextblockStart(),
|
Home: () => this.editor.commands.selectTextblockStart(),
|
||||||
End: () => this.editor.commands.selectTextblockStart(),
|
End: () => this.editor.commands.selectTextblockStart(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const macKeymap = {
|
||||||
|
...baseKeymap,
|
||||||
|
'Ctrl-h': handleBackspace,
|
||||||
|
'Alt-Backspace': handleBackspace,
|
||||||
|
'Ctrl-d': handleDelete,
|
||||||
|
'Ctrl-Alt-Backspace': handleDelete,
|
||||||
|
'Alt-Delete': handleDelete,
|
||||||
|
'Alt-d': handleDelete,
|
||||||
|
'Ctrl-a': () => this.editor.commands.selectTextblockStart(),
|
||||||
|
'Ctrl-e': () => this.editor.commands.selectTextblockEnd(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isiOS() || isMacOS()) {
|
||||||
|
return macKeymap
|
||||||
|
}
|
||||||
|
|
||||||
|
return pcKeymap
|
||||||
},
|
},
|
||||||
|
|
||||||
addProseMirrorPlugins() {
|
addProseMirrorPlugins() {
|
||||||
|
|||||||
5
packages/core/src/utilities/isMacOS.ts
Normal file
5
packages/core/src/utilities/isMacOS.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export function isMacOS(): boolean {
|
||||||
|
return typeof navigator !== 'undefined'
|
||||||
|
? /Mac/.test(navigator.platform)
|
||||||
|
: false
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user