Avoid interprocess message for notifying commandline hide, and insert content script keys at the beginning if clInput already received normal keyboard events

This commit is contained in:
petoncle 2023-10-28 23:22:16 +02:00
parent 28242d8a5e
commit 5779121d5c
3 changed files with 28 additions and 9 deletions

View file

@ -83,6 +83,9 @@ const commandline_state = {
refresh_completions,
state,
clInputFocused: false,
clInputNormalEventsReceived: false,
clInputInitialValue: "",
contentProcessKeysReceivedAfterClInputFocused: 0
}
// first theming of commandline iframe
@ -179,18 +182,29 @@ export function focus() {
}
}
/** @hidden **/
export function hide() {
logger.debug("Called hide()")
commandline_state.clInputFocused = false
}
let keysFromContentProcess: string[] = []
export function bufferUntilClInputFocused([key]) {
logger.debug("Command line process received content process keydown event: " + key)
if (commandline_state.clInputFocused) {
logger.debug("Dispatching received keydown event " + key + " since clInputFocused is true")
commandline_state.clInput.value += key
logger.debug("Dispatching received keydown event " + key + " since clInputFocused is true," +
" clInputNormalEventsReceived = " + commandline_state.clInputNormalEventsReceived +
" contentProcessKeysReceivedAfterClInputFocused = " + commandline_state.contentProcessKeysReceivedAfterClInputFocused +
" clInputInitialValue = " + commandline_state.clInputInitialValue)
if (!commandline_state.clInputNormalEventsReceived) {
// Insert at the end.
commandline_state.clInput.value += key
}
else {
// Normal keys are assumed to always be at the end.
let normalKeyCount = commandline_state.contentProcessKeysReceivedAfterClInputFocused;
let initialCommandLength = commandline_state.clInputInitialValue.length;
// Insert received key at the beginning.
commandline_state.clInput.value =
commandline_state.clInput.value.substring(0, initialCommandLength + normalKeyCount)
+ key
+ commandline_state.clInput.value.substring(initialCommandLength + normalKeyCount)
commandline_state.contentProcessKeysReceivedAfterClInputFocused++;
}
clInputValueChanged()
}
else {
@ -220,6 +234,7 @@ commandline_state.clInput.addEventListener(
function (keyevent: KeyboardEvent) {
if (!keyevent.isTrusted) return
logger.info("Called keydown event listener")
commandline_state.clInputNormalEventsReceived = true
commandline_state.keyEvents.push(minimalKeyFromKeyboardEvent(keyevent))
const response = keyParser(commandline_state.keyEvents)
if (response.isMatch) {
@ -385,6 +400,7 @@ export function fillcmdline(
// 3. Stop forwarding key events from content process to command line process.
if (trailspace) commandline_state.clInput.value = newcommand + " "
else commandline_state.clInput.value = newcommand
commandline_state.clInputInitialValue = commandline_state.clInput.value
commandline_state.isVisible = true
let result = Promise.resolve([])
// Focus is lost for some reason.

View file

@ -88,7 +88,6 @@ export function hide() {
try {
cmdline_iframe.classList.add("hidden")
cmdline_iframe.setAttribute("style", "height: 0px !important;")
Messaging.messageOwnTab("commandline_frame", "hide")
} catch (e) {
// Using cmdline_logger here is OK because cmdline_logger won't try to
// call hide(), thus we avoid the recursion that happens for show() and

View file

@ -138,6 +138,10 @@ export function getCommandlineFns(cmdline_state: {
)
cmdline_state.activeCompletions = undefined
cmdline_state.isVisible = false
console.debug("Called hide_and_clear()")
cmdline_state.clInputFocused = false
cmdline_state.clInputNormalEventsReceived = false
cmdline_state.contentProcessKeysReceivedAfterClInputFocused = 0
},
/**