mirror of https://github.com/status-im/codimd.git
fix: table editor key map might conflict with textcomplete keymap
and avoid add/remove keymap on every updateActiveState Signed-off-by: Max Wu <jackymaxj@gmail.com>
This commit is contained in:
parent
e03a326c26
commit
052c787c0a
|
@ -3116,6 +3116,27 @@ function matchInContainer (text) {
|
|||
}
|
||||
}
|
||||
|
||||
const textCompleteKeyMap = {
|
||||
Up: function () {
|
||||
return false
|
||||
},
|
||||
Right: function () {
|
||||
editor.doc.cm.execCommand('goCharRight')
|
||||
},
|
||||
Down: function () {
|
||||
return false
|
||||
},
|
||||
Left: function () {
|
||||
editor.doc.cm.execCommand('goCharLeft')
|
||||
},
|
||||
Enter: function () {
|
||||
return false
|
||||
},
|
||||
Backspace: function () {
|
||||
editor.doc.cm.execCommand('delCharBefore')
|
||||
}
|
||||
}
|
||||
|
||||
$(editor.getInputField())
|
||||
.textcomplete([
|
||||
{ // emoji strategy
|
||||
|
@ -3317,29 +3338,10 @@ $(editor.getInputField())
|
|||
},
|
||||
'textComplete:show': function (e) {
|
||||
$(this).data('autocompleting', true)
|
||||
editor.setOption('extraKeys', {
|
||||
Up: function () {
|
||||
return false
|
||||
},
|
||||
Right: function () {
|
||||
editor.doc.cm.execCommand('goCharRight')
|
||||
},
|
||||
Down: function () {
|
||||
return false
|
||||
},
|
||||
Left: function () {
|
||||
editor.doc.cm.execCommand('goCharLeft')
|
||||
},
|
||||
Enter: function () {
|
||||
return false
|
||||
},
|
||||
Backspace: function () {
|
||||
editor.doc.cm.execCommand('delCharBefore')
|
||||
}
|
||||
})
|
||||
editor.addKeyMap(textCompleteKeyMap)
|
||||
},
|
||||
'textComplete:hide': function (e) {
|
||||
$(this).data('autocompleting', false)
|
||||
editor.setOption('extraKeys', editorInstance.defaultExtraKeys)
|
||||
editor.removeKeyMap(textCompleteKeyMap)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -166,19 +166,25 @@ export function initTableEditor (editor) {
|
|||
'Alt-Shift-Ctrl-Down': () => { tableEditor.moveRow(1, opts) },
|
||||
'Alt-Shift-Cmd-Down': () => { tableEditor.moveRow(1, opts) }
|
||||
})
|
||||
let lastActive
|
||||
// enable keymap if the cursor is in a table
|
||||
function updateActiveState () {
|
||||
const tableTools = $('.toolbar .table-tools')
|
||||
const active = tableEditor.cursorIsInTable(opts)
|
||||
// avoid to update if state not changed
|
||||
if (lastActive === active) {
|
||||
return
|
||||
}
|
||||
if (active) {
|
||||
tableTools.show()
|
||||
tableTools.parent().scrollLeft(tableTools.parent()[0].scrollWidth)
|
||||
editor.setOption('extraKeys', keyMap)
|
||||
editor.addKeyMap(keyMap)
|
||||
} else {
|
||||
tableTools.hide()
|
||||
editor.setOption('extraKeys', null)
|
||||
editor.removeKeyMap(keyMap)
|
||||
tableEditor.resetSmartCursor()
|
||||
}
|
||||
lastActive = active
|
||||
}
|
||||
// event subscriptions
|
||||
editor.on('cursorActivity', () => {
|
||||
|
|
Loading…
Reference in New Issue