From 960b065a8801a39c2cda277968ff66a0d9d11a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4usler?= Date: Wed, 10 Apr 2019 16:41:40 +0200 Subject: [PATCH] ignore key events if cursor is not set (#906) --- src/muya/lib/eventHandler/clickEvent.js | 12 +++++------- src/muya/lib/eventHandler/keyboard.js | 8 ++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/muya/lib/eventHandler/clickEvent.js b/src/muya/lib/eventHandler/clickEvent.js index bc582128..c2e76879 100644 --- a/src/muya/lib/eventHandler/clickEvent.js +++ b/src/muya/lib/eventHandler/clickEvent.js @@ -18,21 +18,19 @@ class ClickEvent { // Hide format box eventCenter.dispatch('muya-format-picker', { reference: null }) - // Commit native cursor position because right-clicking doesn't update the cursor postion. const { start, end } = selection.getCursorRange() + + // Cursor out of editor if (!start || !end) { - // right click on paragraph icons return } - // if you want to show `insert row or column`, you need to put cursor on cell text... + + // Commit native cursor position because right-clicking doesn't update the cursor postion. contentState.cursor = { start, end } - // TODO: Should we render to update the cursor or is this not necessary because we'll render - // when leaving or clicking on the context menu? - const sectionChanges = contentState.selectionChange(contentState.cursor) eventCenter.dispatch('contextmenu', event, sectionChanges) } @@ -68,7 +66,7 @@ class ClickEvent { formatType: 'image', data: event.target.getAttribute('src') }) - selectionText(markedImageText) + selectionText(markedImageText) } else if (mathText) { selectionText(mathText) } else if (rubyText) { diff --git a/src/muya/lib/eventHandler/keyboard.js b/src/muya/lib/eventHandler/keyboard.js index 4356189f..dfd37377 100644 --- a/src/muya/lib/eventHandler/keyboard.js +++ b/src/muya/lib/eventHandler/keyboard.js @@ -62,10 +62,14 @@ class Keyboard { return } - // prevent dispatch `selectionChange` and `selectionFormats` by click the toolbar of table/html block and front icons + // Cursor outside editor area or over not editable elements. if (event.target.closest('[contenteditable=false]')) { return } + const { start, end } = selection.getCursorRange() + if (!start || !end) { + return + } if (timer) clearTimeout(timer) timer = setTimeout(() => { @@ -199,7 +203,7 @@ class Keyboard { if (!start || !end) { return } - + if ( !this.isComposed ) {