From d7f0435a5a3a587ee2a88cb017ff8e46b3b7594f Mon Sep 17 00:00:00 2001 From: petoncle Date: Sun, 29 Oct 2023 12:18:13 +0100 Subject: [PATCH] Simplify page key buffer consumption --- src/commandline_frame.ts | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/commandline_frame.ts b/src/commandline_frame.ts index d4100eb8..a29e8140 100644 --- a/src/commandline_frame.ts +++ b/src/commandline_frame.ts @@ -175,22 +175,17 @@ export function focus() { return if (bufferedPageKeys.length !== 0) { const currentClInputValue = commandline_state.clInput.value; - // Native events are assumed to be characters added at the end of clInput. - const clInputNativeEventKeysReceived = commandline_state.initialClInputValue.length > currentClInputValue.length + let initialClInputValue = commandline_state.initialClInputValue; logger.debug("Consuming buffered page keys", bufferedPageKeys, - "initialClInputValue = " + commandline_state.initialClInputValue, + "initialClInputValue = " + initialClInputValue, "currentClInputValue = " + currentClInputValue); - if (clInputNativeEventKeysReceived) { - // Insert page keys at the end. - commandline_state.clInput.value += bufferedPageKeys.join("") - } else { - let initialClInputValueLength = commandline_state.initialClInputValue.length; - // Insert page keys just after the command. - commandline_state.clInput.value = - currentClInputValue.substring(0, initialClInputValueLength) - + bufferedPageKeys.join("") - + currentClInputValue.substring(initialClInputValueLength) - } + // Native events are assumed to be characters added at the end of clInput. + // If the user edits the command (initial clInput value) before the buffered page keys are received, we are out of luck. + // Insert page keys just after the command. + commandline_state.clInput.value = + initialClInputValue + + bufferedPageKeys.join("") + + currentClInputValue.substring(initialClInputValue.length) // Update completion. clInputValueChanged() }