prosemirror-keymap
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -0,1 +1,7 @@ | ||
## 1.2.1 (2023-02-14) | ||
### Bug fixes | ||
Work around macOS putting the unmodified character in `KeyboardEvent.key` when Cmd is held down, fixing shift-cmd-letter bindings. | ||
## 1.2.0 (2022-05-30) | ||
@@ -2,0 +8,0 @@ |
@@ -45,3 +45,3 @@ import { keyName, base } from 'w3c-keyname'; | ||
} | ||
function modifiers(name, event, shift) { | ||
function modifiers(name, event, shift = true) { | ||
if (event.altKey) | ||
@@ -53,3 +53,3 @@ name = "Alt-" + name; | ||
name = "Meta-" + name; | ||
if (shift !== false && event.shiftKey) | ||
if (shift && event.shiftKey) | ||
name = "Shift-" + name; | ||
@@ -100,23 +100,25 @@ return name; | ||
return function (view, event) { | ||
let name = keyName(event), isChar = name.length == 1 && name != " ", baseName; | ||
let direct = map[modifiers(name, event, !isChar)]; | ||
let name = keyName(event), baseName, direct = map[modifiers(name, event)]; | ||
if (direct && direct(view.state, view.dispatch, view)) | ||
return true; | ||
if (isChar && (event.shiftKey || event.altKey || event.metaKey || name.charCodeAt(0) > 127) && | ||
(baseName = base[event.keyCode]) && baseName != name) { | ||
// Try falling back to the keyCode when there's a modifier | ||
// active or the character produced isn't ASCII, and our table | ||
// produces a different name from the the keyCode. See #668, | ||
// #1060 | ||
let fromCode = map[modifiers(baseName, event, true)]; | ||
if (fromCode && fromCode(view.state, view.dispatch, view)) | ||
return true; | ||
// A character key | ||
if (name.length == 1 && name != " ") { | ||
if (event.shiftKey) { | ||
// In case the name was already modified by shift, try looking | ||
// it up without its shift modifier | ||
let noShift = map[modifiers(name, event, false)]; | ||
if (noShift && noShift(view.state, view.dispatch, view)) | ||
return true; | ||
} | ||
if ((event.shiftKey || event.altKey || event.metaKey || name.charCodeAt(0) > 127) && | ||
(baseName = base[event.keyCode]) && baseName != name) { | ||
// Try falling back to the keyCode when there's a modifier | ||
// active or the character produced isn't ASCII, and our table | ||
// produces a different name from the the keyCode. See #668, | ||
// #1060 | ||
let fromCode = map[modifiers(baseName, event)]; | ||
if (fromCode && fromCode(view.state, view.dispatch, view)) | ||
return true; | ||
} | ||
} | ||
else if (isChar && event.shiftKey) { | ||
// Otherwise, if shift is active, also try the binding with the | ||
// Shift- prefix enabled. See #997 | ||
let withShift = map[modifiers(name, event, true)]; | ||
if (withShift && withShift(view.state, view.dispatch, view)) | ||
return true; | ||
} | ||
return false; | ||
@@ -123,0 +125,0 @@ }; |
{ | ||
"name": "prosemirror-keymap", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Keymap plugin for ProseMirror", | ||
@@ -18,3 +18,3 @@ "type": "module", | ||
"name": "Marijn Haverbeke", | ||
"email": "marijnh@gmail.com", | ||
"email": "marijn@haverbeke.berlin", | ||
"web": "http://marijnhaverbeke.nl" | ||
@@ -21,0 +21,0 @@ } |
# prosemirror-keymap | ||
[ [**WEBSITE**](https://prosemirror.net) | [**ISSUES**](https://github.com/prosemirror/prosemirror/issues) | [**FORUM**](https://discuss.prosemirror.net) | [**GITTER**](https://gitter.im/ProseMirror/prosemirror) | [**CHANGELOG**](https://github.com/ProseMirror/prosemirror-keymap/blob/master/CHANGELOG.md) ] | ||
[ [**WEBSITE**](https://prosemirror.net) | [**ISSUES**](https://github.com/prosemirror/prosemirror/issues) | [**FORUM**](https://discuss.prosemirror.net) | [**CHANGELOG**](https://github.com/ProseMirror/prosemirror-keymap/blob/master/CHANGELOG.md) ] | ||
@@ -5,0 +5,0 @@ This is a [core module](https://prosemirror.net/docs/ref/#keymap) of [ProseMirror](https://prosemirror.net). |
@@ -33,7 +33,7 @@ import {base, keyName} from "w3c-keyname" | ||
function modifiers(name: string, event: KeyboardEvent, shift: boolean) { | ||
function modifiers(name: string, event: KeyboardEvent, shift = true) { | ||
if (event.altKey) name = "Alt-" + name | ||
if (event.ctrlKey) name = "Ctrl-" + name | ||
if (event.metaKey) name = "Meta-" + name | ||
if (shift !== false && event.shiftKey) name = "Shift-" + name | ||
if (shift && event.shiftKey) name = "Shift-" + name | ||
return name | ||
@@ -81,18 +81,21 @@ } | ||
return function(view, event) { | ||
let name = keyName(event), isChar = name.length == 1 && name != " ", baseName | ||
let direct = map[modifiers(name, event, !isChar)] | ||
let name = keyName(event), baseName, direct = map[modifiers(name, event)] | ||
if (direct && direct(view.state, view.dispatch, view)) return true | ||
if (isChar && (event.shiftKey || event.altKey || event.metaKey || name.charCodeAt(0) > 127) && | ||
(baseName = base[event.keyCode]) && baseName != name) { | ||
// Try falling back to the keyCode when there's a modifier | ||
// active or the character produced isn't ASCII, and our table | ||
// produces a different name from the the keyCode. See #668, | ||
// #1060 | ||
let fromCode = map[modifiers(baseName, event, true)] | ||
if (fromCode && fromCode(view.state, view.dispatch, view)) return true | ||
} else if (isChar && event.shiftKey) { | ||
// Otherwise, if shift is active, also try the binding with the | ||
// Shift- prefix enabled. See #997 | ||
let withShift = map[modifiers(name, event, true)] | ||
if (withShift && withShift(view.state, view.dispatch, view)) return true | ||
// A character key | ||
if (name.length == 1 && name != " ") { | ||
if (event.shiftKey) { | ||
// In case the name was already modified by shift, try looking | ||
// it up without its shift modifier | ||
let noShift = map[modifiers(name, event, false)] | ||
if (noShift && noShift(view.state, view.dispatch, view)) return true | ||
} | ||
if ((event.shiftKey || event.altKey || event.metaKey || name.charCodeAt(0) > 127) && | ||
(baseName = base[event.keyCode]) && baseName != name) { | ||
// Try falling back to the keyCode when there's a modifier | ||
// active or the character produced isn't ASCII, and our table | ||
// produces a different name from the the keyCode. See #668, | ||
// #1060 | ||
let fromCode = map[modifiers(baseName, event)] | ||
if (fromCode && fromCode(view.state, view.dispatch, view)) return true | ||
} | ||
} | ||
@@ -99,0 +102,0 @@ return false |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23588
11
322