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())
|
$(editor.getInputField())
|
||||||
.textcomplete([
|
.textcomplete([
|
||||||
{ // emoji strategy
|
{ // emoji strategy
|
||||||
|
@ -3317,29 +3338,10 @@ $(editor.getInputField())
|
||||||
},
|
},
|
||||||
'textComplete:show': function (e) {
|
'textComplete:show': function (e) {
|
||||||
$(this).data('autocompleting', true)
|
$(this).data('autocompleting', true)
|
||||||
editor.setOption('extraKeys', {
|
editor.addKeyMap(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')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
'textComplete:hide': function (e) {
|
'textComplete:hide': function (e) {
|
||||||
$(this).data('autocompleting', false)
|
$(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-Ctrl-Down': () => { tableEditor.moveRow(1, opts) },
|
||||||
'Alt-Shift-Cmd-Down': () => { tableEditor.moveRow(1, opts) }
|
'Alt-Shift-Cmd-Down': () => { tableEditor.moveRow(1, opts) }
|
||||||
})
|
})
|
||||||
|
let lastActive
|
||||||
// enable keymap if the cursor is in a table
|
// enable keymap if the cursor is in a table
|
||||||
function updateActiveState () {
|
function updateActiveState () {
|
||||||
const tableTools = $('.toolbar .table-tools')
|
const tableTools = $('.toolbar .table-tools')
|
||||||
const active = tableEditor.cursorIsInTable(opts)
|
const active = tableEditor.cursorIsInTable(opts)
|
||||||
|
// avoid to update if state not changed
|
||||||
|
if (lastActive === active) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (active) {
|
if (active) {
|
||||||
tableTools.show()
|
tableTools.show()
|
||||||
tableTools.parent().scrollLeft(tableTools.parent()[0].scrollWidth)
|
tableTools.parent().scrollLeft(tableTools.parent()[0].scrollWidth)
|
||||||
editor.setOption('extraKeys', keyMap)
|
editor.addKeyMap(keyMap)
|
||||||
} else {
|
} else {
|
||||||
tableTools.hide()
|
tableTools.hide()
|
||||||
editor.setOption('extraKeys', null)
|
editor.removeKeyMap(keyMap)
|
||||||
tableEditor.resetSmartCursor()
|
tableEditor.resetSmartCursor()
|
||||||
}
|
}
|
||||||
|
lastActive = active
|
||||||
}
|
}
|
||||||
// event subscriptions
|
// event subscriptions
|
||||||
editor.on('cursorActivity', () => {
|
editor.on('cursorActivity', () => {
|
||||||
|
|
Loading…
Reference in New Issue