fix: Fixes backspacing to work fully properly.
This commit is contained in:
parent
e85838d438
commit
ea9279b16d
1 changed files with 12 additions and 13 deletions
|
@ -22,27 +22,26 @@ export async function readFromKeyboard(stream: ServerChannel, disableEcho: boole
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (readStreamData.includes("\x7F")) {
|
} else if (readStreamData.includes("\x7F")) {
|
||||||
// TODO (greysoh): investigate maybe potential deltaCursor overflow (haven't tested)
|
|
||||||
// TODO (greysoh): investigate deltaCursor underflow
|
|
||||||
// TODO (greysoh): make it not run like shit (I don't know how to describe it)
|
|
||||||
|
|
||||||
if (line.length == 0) return setTimeout(eventLoop, 5); // Here because if we do it in the parent if statement, shit breaks
|
if (line.length == 0) return setTimeout(eventLoop, 5); // Here because if we do it in the parent if statement, shit breaks
|
||||||
line = line.substring(0, lineIndex - 1) + line.substring(lineIndex);
|
line = line.substring(0, lineIndex - 1) + line.substring(lineIndex);
|
||||||
|
|
||||||
if (!disableEcho) {
|
if (!disableEcho) {
|
||||||
let deltaCursor = line.length - lineIndex;
|
const deltaCursor = line.length - lineIndex;
|
||||||
|
|
||||||
|
if (deltaCursor == line.length) return setTimeout(eventLoop, 5);
|
||||||
|
|
||||||
// wtf?
|
|
||||||
if (deltaCursor < 0) {
|
if (deltaCursor < 0) {
|
||||||
console.log("FIXME: somehow, our deltaCursor value is negative! please investigate me");
|
// Use old technique if the delta is < 0, as the new one is tailored to the start + 1 to end - 1
|
||||||
return setTimeout(eventLoop, 5);
|
stream.write("\u0008 \u0008");
|
||||||
|
} else {
|
||||||
|
// Jump forward to the front, and remove the last character
|
||||||
|
stream.write(rightEscape.repeat(deltaCursor) + " " + ourBackspace);
|
||||||
|
|
||||||
|
// Go backwards & rerender text & go backwards again (wtf?)
|
||||||
|
stream.write(leftEscape.repeat(deltaCursor + 1) + line.substring(lineIndex - 1) + leftEscape.repeat(deltaCursor + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jump forward to the front, and remove the last character
|
lineIndex -= 1;
|
||||||
stream.write(rightEscape.repeat(deltaCursor) + " " + ourBackspace);
|
|
||||||
|
|
||||||
// Go backwards & rerender text & go backwards again (wtf?)
|
|
||||||
stream.write(leftEscape.repeat(deltaCursor + 1) + line.substring(lineIndex - 1) + leftEscape.repeat(deltaCursor + 1));
|
|
||||||
}
|
}
|
||||||
} else if (readStreamData.includes("\x1B")) {
|
} else if (readStreamData.includes("\x1B")) {
|
||||||
if (readStreamData.includes(rightEscape)) {
|
if (readStreamData.includes(rightEscape)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue