From fc26306b7eded684844befbc0474cba8434cc628 Mon Sep 17 00:00:00 2001 From: Mitch Capper Date: Wed, 16 Mar 2022 15:46:12 -0700 Subject: [PATCH] Avoid scrolling to cursor when Control/Alt/Shift/Escape is hit This behavior now matches other editors --- src/muya/lib/config/index.js | 7 ++++++- src/muya/lib/eventHandler/keyboard.js | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/muya/lib/config/index.js b/src/muya/lib/config/index.js index ece057e5..5a6123f5 100644 --- a/src/muya/lib/config/index.js +++ b/src/muya/lib/config/index.js @@ -54,7 +54,12 @@ export const EVENT_KEYS = Object.freeze(generateKeyHash([ 'ArrowLeft', 'ArrowRight', 'Tab', - 'Escape' + 'Escape', + 'Control', + 'Alt', + 'Shift', + 'PageUp', + 'PageDown' ])) export const LOWERCASE_TAGS = Object.freeze(generateKeyHash([ diff --git a/src/muya/lib/eventHandler/keyboard.js b/src/muya/lib/eventHandler/keyboard.js index c4462cf8..3e9acc9f 100644 --- a/src/muya/lib/eventHandler/keyboard.js +++ b/src/muya/lib/eventHandler/keyboard.js @@ -68,6 +68,10 @@ class Keyboard { ) { return } + if (event.key === EVENT_KEYS.Control || event.key === EVENT_KEYS.Alt || event.key === EVENT_KEYS.Escape || event.key === EVENT_KEYS.Shift || event.key === EVENT_KEYS.PageUp || event.key === EVENT_KEYS.PageDown) { // we don't want to focus on the cursor if the user just hits one of these keys. Other editors do not. + return + } + // Cursor outside editor area or over not editable elements. if (event.target.closest('[contenteditable=false]')) { return