mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 18:01:45 +08:00
ignore key events if cursor is not set (#906)
This commit is contained in:
parent
82d4c74f62
commit
960b065a88
@ -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)
|
||||
}
|
||||
|
@ -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(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user