Skip to content

Commit ee8bd9d

Browse files
authored
fix: table editor key map might conflict with textcomplete keym… (#1328)
fix: table editor key map might conflict with textcomplete keymap
2 parents e03a326 + 052c787 commit ee8bd9d

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

public/js/index.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,27 @@ function matchInContainer (text) {
31163116
}
31173117
}
31183118

3119+
const textCompleteKeyMap = {
3120+
Up: function () {
3121+
return false
3122+
},
3123+
Right: function () {
3124+
editor.doc.cm.execCommand('goCharRight')
3125+
},
3126+
Down: function () {
3127+
return false
3128+
},
3129+
Left: function () {
3130+
editor.doc.cm.execCommand('goCharLeft')
3131+
},
3132+
Enter: function () {
3133+
return false
3134+
},
3135+
Backspace: function () {
3136+
editor.doc.cm.execCommand('delCharBefore')
3137+
}
3138+
}
3139+
31193140
$(editor.getInputField())
31203141
.textcomplete([
31213142
{ // emoji strategy
@@ -3317,29 +3338,10 @@ $(editor.getInputField())
33173338
},
33183339
'textComplete:show': function (e) {
33193340
$(this).data('autocompleting', true)
3320-
editor.setOption('extraKeys', {
3321-
Up: function () {
3322-
return false
3323-
},
3324-
Right: function () {
3325-
editor.doc.cm.execCommand('goCharRight')
3326-
},
3327-
Down: function () {
3328-
return false
3329-
},
3330-
Left: function () {
3331-
editor.doc.cm.execCommand('goCharLeft')
3332-
},
3333-
Enter: function () {
3334-
return false
3335-
},
3336-
Backspace: function () {
3337-
editor.doc.cm.execCommand('delCharBefore')
3338-
}
3339-
})
3341+
editor.addKeyMap(textCompleteKeyMap)
33403342
},
33413343
'textComplete:hide': function (e) {
33423344
$(this).data('autocompleting', false)
3343-
editor.setOption('extraKeys', editorInstance.defaultExtraKeys)
3345+
editor.removeKeyMap(textCompleteKeyMap)
33443346
}
33453347
})

public/js/lib/editor/table-editor.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,25 @@ export function initTableEditor (editor) {
166166
'Alt-Shift-Ctrl-Down': () => { tableEditor.moveRow(1, opts) },
167167
'Alt-Shift-Cmd-Down': () => { tableEditor.moveRow(1, opts) }
168168
})
169+
let lastActive
169170
// enable keymap if the cursor is in a table
170171
function updateActiveState () {
171172
const tableTools = $('.toolbar .table-tools')
172173
const active = tableEditor.cursorIsInTable(opts)
174+
// avoid to update if state not changed
175+
if (lastActive === active) {
176+
return
177+
}
173178
if (active) {
174179
tableTools.show()
175180
tableTools.parent().scrollLeft(tableTools.parent()[0].scrollWidth)
176-
editor.setOption('extraKeys', keyMap)
181+
editor.addKeyMap(keyMap)
177182
} else {
178183
tableTools.hide()
179-
editor.setOption('extraKeys', null)
184+
editor.removeKeyMap(keyMap)
180185
tableEditor.resetSmartCursor()
181186
}
187+
lastActive = active
182188
}
183189
// event subscriptions
184190
editor.on('cursorActivity', () => {

0 commit comments

Comments
 (0)