From 2c6f35433e4eb86b80cd7e7064c9d7695b05ec3f Mon Sep 17 00:00:00 2001 From: Oliver Geer Date: Fri, 20 Jun 2025 17:51:27 +0100 Subject: [PATCH] Remove janky blur/focus - This was a "fix" at the wrong level (by me), and caused code-input's aim of acting like a textarea to be violated. - TODO: See why this was added in the first place (I did it by my own will, but it's unclear why now) before merging --- code-input.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/code-input.js b/code-input.js index 7bace3b..bba9362 100644 --- a/code-input.js +++ b/code-input.js @@ -482,7 +482,6 @@ var codeInput = { * to syntax-highlight it. */ needsHighlight = false; // Just inputted - handleEventsFromTextarea = true; // Turn to false when unusual internal events are called on the textarea originalAriaDescription; /** @@ -523,14 +522,6 @@ var codeInput = { this.syncSize(); - // If editing here, scroll to the caret by focusing, though this shouldn't count as a focus event - if(this.textareaElement === document.activeElement) { - this.handleEventsFromTextarea = false; - this.textareaElement.blur(); - this.textareaElement.focus(); - this.handleEventsFromTextarea = true; - } - this.pluginEvt("afterHighlight"); } @@ -646,9 +637,7 @@ var codeInput = { this.classList.add("code-input_mouse-focused"); }); textarea.addEventListener("blur", () => { - if(this.handleEventsFromTextarea) { - this.classList.remove("code-input_mouse-focused"); - } + this.classList.remove("code-input_mouse-focused"); }); this.innerHTML = ""; // Clear Content @@ -874,22 +863,20 @@ var codeInput = { this.boundEventCallbacks[listener] = boundCallback; if (codeInput.textareaSyncEvents.includes(type)) { - // Synchronise with textarea, only when handleEventsFromTextarea is true - // This callback is modified to only run when the handleEventsFromTextarea is set. - let conditionalBoundCallback = function(evt) { if(this.handleEventsFromTextarea) boundCallback(evt); }.bind(this); - this.boundEventCallbacks[listener] = conditionalBoundCallback; + // Synchronise with textarea + this.boundEventCallbacks[listener] = boundCallback; if (options === undefined) { if(this.textareaElement == null) { this.addEventListener("code-input_load", () => { this.textareaElement.addEventListener(type, boundCallback); }); } else { - this.textareaElement.addEventListener(type, conditionalBoundCallback); + this.textareaElement.addEventListener(type, boundCallback); } } else { if(this.textareaElement == null) { this.addEventListener("code-input_load", () => { this.textareaElement.addEventListener(type, boundCallback, options); }); } else { - this.textareaElement.addEventListener(type, conditionalBoundCallback, options); + this.textareaElement.addEventListener(type, boundCallback, options); } } } else { @@ -949,10 +936,12 @@ var codeInput = { if (val === null || val === undefined) { val = ""; } + // Save in editable textarea element this.textareaElement.value = val; // Trigger highlight this.scheduleHighlight(); + return val; }