Capture the "TAB" key only when the user has selected text.

This commit is contained in:
Alex T.
2025-04-27 22:20:31 -07:00
parent 5eb1dba1d6
commit af5fe16db7
@@ -2339,6 +2339,38 @@ EasyMDE.prototype.render = function (el) {
var self = this
var keyMaps = {}
function moveToNextField(cm) {
const form = cm.getInputField().form
if (form) {
const elements = Array.from(form.elements)
const index = elements.indexOf(cm.getInputField())
if (index !== -1 && index + 1 < elements.length && elements[index + 1]) {
elements[index + 1].focus()
}
}
}
function moveToPreviousField(cm) {
const form = cm.getInputField().form
if (form) {
const elements = Array.from(form.elements)
const index = elements.indexOf(cm.getInputField())
if (index !== -1) {
for (let i = index - 1; i >= 0; i--) {
const element = elements[i]
if (
element &&
element.tagName === 'INPUT' &&
!element.closest('.editor-toolbar')
) {
element.focus()
break
}
}
}
}
}
for (var key in options.shortcuts) {
// null stands for "do not bind this command"
if (options.shortcuts[key] !== null && bindings[key] !== null) {
@@ -2356,8 +2388,22 @@ EasyMDE.prototype.render = function (el) {
}
keyMaps['Enter'] = 'newlineAndIndentContinueMarkdownList'
keyMaps['Tab'] = 'tabAndIndentMarkdownList'
keyMaps['Shift-Tab'] = 'shiftTabAndUnindentMarkdownList'
keyMaps['Tab'] = (cm) => {
const selection = cm.getSelection()
if (selection && selection.length > 0) {
cm.execCommand('indentMore')
} else {
moveToNextField(cm)
}
}
keyMaps['Shift-Tab'] = (cm) => {
const selection = cm.getSelection()
if (selection && selection.length > 0) {
cm.execCommand('indentLess')
} else {
moveToPreviousField(cm)
}
}
keyMaps['Esc'] = function (cm) {
if (cm.getOption('fullScreen')) toggleFullScreen(self)
}