From daa4fbfecfa4e050a72d61a8e54375341792769e Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 22 Jan 2026 11:57:37 +0100 Subject: [PATCH] code editor: keep fullscreen code editor focused and opened upon validation --- src/client/ui/ui-code-editor.mjs | 50 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/client/ui/ui-code-editor.mjs b/src/client/ui/ui-code-editor.mjs index ecfe8e51..62105432 100644 --- a/src/client/ui/ui-code-editor.mjs +++ b/src/client/ui/ui-code-editor.mjs @@ -133,7 +133,6 @@ class CodeEditor { var editor = this.editor, input = this.input - editor.fullscreen = false input.style.display = 'none' input._ace_input = editor.textarea input.tabIndex = -1 @@ -141,11 +140,6 @@ class CodeEditor { editor.setValue(input.value) editor.textarea.osc_input = input editor.textarea.tabIndex = 0 - editor.selection.setRange({start:0,end:0}) - if (!this.widget || widget.hash !== this.widget.hash) { - // preserve active line if widget is the same - editor.gotoLine(0) - } editor.removeAllListeners('focus') this.editor.on('focus', (e)=>{ @@ -161,27 +155,36 @@ class CodeEditor { this.editor.dirty = true }) - setTimeout(()=>{ - var pos = this.editor.getCursorPosition() - if (pos.row === undefined || pos.column === undefined) { - this.editor.gotoLine(0) - } - }) - this.typing = false setCommandEnabled(this.editor, 'indent', false) setCommandEnabled(this.editor, 'outdent', false) - this.editor.on('changeSelection', ()=>{ - if (this.typing) return - let pos = this.editor.getCursorPosition() - if (pos.row || pos.column) { - setCommandEnabled(this.editor, 'indent', true) - setCommandEnabled(this.editor, 'outdent', true) + setTimeout(()=>{ + if (this.pos) { + this.editor.moveCursorTo(this.pos.row, this.pos.column) + } else { + var pos = this.editor.getCursorPosition() + if (pos.row === undefined || pos.column === undefined) { + this.editor.gotoLine(0) + } + } - this.typing = true + + this.typing = false + this.editor.on('changeSelection', ()=>{ + if (this.typing) return + let pos = this.editor.getCursorPosition() + if (pos.row || pos.column) { + setCommandEnabled(this.editor, 'indent', true) + setCommandEnabled(this.editor, 'outdent', true) + } + this.typing = true + }) }) + + this.editor.on('blur', (e)=>{ + this.pos = this.editor.getCursorPosition() this.editor.setHighlightActiveLine(false) this.editor.setHighlightGutterLine(false) this.editor.selection.setRange({start:0,end:0}) @@ -242,13 +245,18 @@ class CodeEditor { field.appendChild(this.helpBtn) field.appendChild(this.fsBtn) + editor.selection.setRange({start:0,end:0}) + if (this.hash !== widget.hash) { // preserve undo history if widget is the same editor.getSession().getUndoManager().reset() this.hash = widget.hash + this.pos = null + } else if (editor.fullscreen) { + this.fullscreen() } - editor.resize() + editor.resize() }