mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 07:01:41 +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
|
// 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)
|
||||||
}
|
}
|
||||||
|
@ -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(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user