Fix: Preserve text selection on tab switch for input/output

This commit is contained in:
Henry Harborne 2025-06-05 12:24:11 -04:00
parent c57556f49f
commit d0c1e5525e
2 changed files with 35 additions and 8 deletions

View file

@ -758,6 +758,15 @@ class InputWaiter {
* @param {string | ArrayBuffer} value
*/
updateInputValue(inputNum, value, force=false) {
// Preserve current selection
const inputElement = document.getElementById("input-text");
let selectionStart = null;
let selectionEnd = null;
if (inputElement) {
selectionStart = inputElement.selectionStart;
selectionEnd = inputElement.selectionEnd;
}
// Prepare the value as a buffer (full value) and a string sample (up to 4096 bytes)
let buffer;
let stringSample = "";
@ -796,6 +805,14 @@ class InputWaiter {
eolSequence: this.getEOLSeq()
}
}, transferable);
// Restore selection if it was set
if (inputElement && selectionStart !== null && selectionEnd !== null) {
requestAnimationFrame(() => {
inputElement.selectionStart = selectionStart;
inputElement.selectionEnd = selectionEnd;
});
}
}
/**