This commit is contained in:
Henry Harborne 2025-06-05 17:25:59 +01:00 committed by GitHub
commit ff5c1ce1b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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;
});
}
}
/**

View file

@ -551,17 +551,27 @@ class OutputWaiter {
if (!this.outputExists(inputNum)) {
this.addOutput(inputNum);
}
if (Object.prototype.hasOwnProperty.call(data, "dish")) {
data.dish = new Dish(data.dish);
// Preserve current selection
const outputElement = document.getElementById("output-text");
let selectionStart = null;
let selectionEnd = null;
if (outputElement) {
selectionStart = outputElement.selectionStart;
selectionEnd = outputElement.selectionEnd;
}
this.outputs[inputNum].data = data;
this.outputs[inputNum].statusMessage = statusMessage;
if (set) {
this.set(inputNum);
const tabItem = this.manager.tabs.getTabItem(inputNum, "output");
if (tabItem) tabItem.style.background = "";
if (set) this.set(inputNum);
// Restore selection if it was set
if (outputElement && selectionStart !== null && selectionEnd !== null) {
requestAnimationFrame(() => {
outputElement.selectionStart = selectionStart;
outputElement.selectionEnd = selectionEnd;
});
}
}
}
/**