ignore key events if cursor is not set (#906)

This commit is contained in:
Felix Häusler 2019-04-10 16:41:40 +02:00 committed by Ran Luo
parent 82d4c74f62
commit 960b065a88
2 changed files with 11 additions and 9 deletions

View File

@ -18,21 +18,19 @@ class ClickEvent {
// Hide format box // Hide format box
eventCenter.dispatch('muya-format-picker', { reference: null }) 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() const { start, end } = selection.getCursorRange()
// Cursor out of editor
if (!start || !end) { if (!start || !end) {
// right click on paragraph icons
return 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 = { contentState.cursor = {
start, start,
end 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) const sectionChanges = contentState.selectionChange(contentState.cursor)
eventCenter.dispatch('contextmenu', event, sectionChanges) eventCenter.dispatch('contextmenu', event, sectionChanges)
} }
@ -68,7 +66,7 @@ class ClickEvent {
formatType: 'image', formatType: 'image',
data: event.target.getAttribute('src') data: event.target.getAttribute('src')
}) })
selectionText(markedImageText) selectionText(markedImageText)
} else if (mathText) { } else if (mathText) {
selectionText(mathText) selectionText(mathText)
} else if (rubyText) { } else if (rubyText) {

View File

@ -62,10 +62,14 @@ class Keyboard {
return 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]')) { if (event.target.closest('[contenteditable=false]')) {
return return
} }
const { start, end } = selection.getCursorRange()
if (!start || !end) {
return
}
if (timer) clearTimeout(timer) if (timer) clearTimeout(timer)
timer = setTimeout(() => { timer = setTimeout(() => {
@ -199,7 +203,7 @@ class Keyboard {
if (!start || !end) { if (!start || !end) {
return return
} }
if ( if (
!this.isComposed !this.isComposed
) { ) {