Skip to content

Commit 06f9189

Browse files
[6.x] Pressing "esc" should blur CodeMirror inputs (#13474)
1 parent f3779da commit 06f9189

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

resources/js/components/fieldtypes/markdown/MarkdownFieldtype.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,13 @@ export default {
527527
* Execute a keyboard shortcut, when applicable
528528
*/
529529
shortcut(e) {
530+
// Handle ESC to blur/unfocus the editor
531+
if (e.keyCode === 27) {
532+
e.preventDefault();
533+
this.codemirror.getInputField().blur();
534+
return;
535+
}
536+
530537
const mod = e.metaKey || e.ctrlKey;
531538
if (!mod) return;
532539

resources/js/components/ui/CodeEditor.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ function initCodeMirror() {
139139
140140
codemirror.value.on('focus', () => emit('focus'));
141141
codemirror.value.on('blur', () => emit('blur'));
142+
143+
codemirror.value.on('keydown', (cm, e) => {
144+
// Handle ESC to blur/unfocus the editor
145+
if (e.keyCode === 27) {
146+
e.preventDefault();
147+
codemirror.value.getInputField().blur();
148+
}
149+
});
142150
}
143151
144152
watch(

0 commit comments

Comments
 (0)