From 3d5576bb738723842f3fe04850c1ab02b4fcbe10 Mon Sep 17 00:00:00 2001 From: petoncle Date: Sun, 29 Oct 2023 20:41:48 +0100 Subject: [PATCH] Clean logs and move code around --- src/commandline_frame.ts | 17 ++++++++--------- src/content/commandline_content.ts | 5 ++++- src/content/controller_content.ts | 27 +++++++++++++++------------ src/excmds.ts | 3 +-- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/commandline_frame.ts b/src/commandline_frame.ts index 9e5afa09..96601120 100644 --- a/src/commandline_frame.ts +++ b/src/commandline_frame.ts @@ -166,7 +166,7 @@ export function focus() { commandline_state.clInput.focus() commandline_state.clInput.removeEventListener("blur", noblur) commandline_state.clInput.addEventListener("blur", noblur) - logger.debug("Called focus()") + logger.debug("commandline_frame focus()") Messaging.messageOwnTab("buffered_page_keys", "").then((bufferedPageKeys : string[]) => { let clInputStillFocused = window.document.activeElement === commandline_state.clInput; logger.debug("buffered_page_keys response received", bufferedPageKeys, @@ -213,7 +213,7 @@ commandline_state.clInput.addEventListener( "keydown", function (keyevent: KeyboardEvent) { if (!keyevent.isTrusted) return - logger.debug("Called clInput keydown event listener", keyevent) + logger.debug("commandline_frame clInput keydown event listener", keyevent) commandline_state.keyEvents.push(minimalKeyFromKeyboardEvent(keyevent)) const response = keyParser(commandline_state.keyEvents) if (response.isMatch) { @@ -288,6 +288,11 @@ export function refresh_completions(exstr) { /** @hidden **/ let onInputPromise: Promise = Promise.resolve() +/** @hidden **/ +commandline_state.clInput.addEventListener("input", () => { + logger.debug("commandline_frame clInput input event listener") + clInputValueChanged(); +}) function clInputValueChanged() { const exstr = commandline_state.clInput.value @@ -310,12 +315,6 @@ function clInputValueChanged() { }, 100) } -/** @hidden **/ -commandline_state.clInput.addEventListener("input", () => { - logger.debug("Called clInput input event listener") - clInputValueChanged(); -}) - /** @hidden **/ let cmdline_history_current = "" @@ -373,7 +372,7 @@ export function fillcmdline( trailspace = true, ffocus = true, ) { - logger.debug("Called commandline_frame fillcmdline, trailspace = " + trailspace + " ffocus = " + ffocus) + logger.debug("commandline_frame fillcmdline(newcommand = " + newcommand + " trailspace = " + trailspace + " ffocus = " + ffocus + ")") if (trailspace) commandline_state.clInput.value = newcommand + " " else commandline_state.clInput.value = newcommand commandline_state.initialClInputValue = commandline_state.clInput.value diff --git a/src/content/commandline_content.ts b/src/content/commandline_content.ts index fea7a9e1..5786051e 100644 --- a/src/content/commandline_content.ts +++ b/src/content/commandline_content.ts @@ -63,7 +63,7 @@ export function show(hidehover = false) { * * Inspired by VVimpulation: https://github.com/amedama41/vvimpulation/commit/53065d015d1e9a892496619b51be83771f57b3d5 */ - logger.debug("Called show()") + logger.debug("commandline_content show()") if (hidehover) { const a = window.document.createElement("A") ;(a as any).href = "" @@ -96,6 +96,9 @@ export function hide() { } } +/** + * TODO: Discuss removal of this method? + */ export function focus() { try { // I don't think this is necessary because clInput is going to be focused. diff --git a/src/content/controller_content.ts b/src/content/controller_content.ts index abd28261..b2bdfa2f 100644 --- a/src/content/controller_content.ts +++ b/src/content/controller_content.ts @@ -100,6 +100,17 @@ class KeyCanceller { export const canceller = new KeyCanceller() +let mustBufferPageKeysForClInput = false +let bufferedPageKeys: string[] = [] +Messaging.addListener("buffered_page_keys", (message, sender, sendResponse) => { + logger.debug("buffered_page_keys request received, responding with", bufferedPageKeys) + sendResponse(Promise.resolve(bufferedPageKeys)) + // At this point, clInput is focused and the page cannot get any more keyboard events + // until it is refocused. + mustBufferPageKeysForClInput = false + bufferedPageKeys = [] +}) + /** Accepts keyevents, resolves them to maps, maps to exstrs, executes exstrs */ function* ParserController() { const parsers: { @@ -193,7 +204,7 @@ function* ParserController() { if (response.exstr) { exstr = response.exstr if (exstr.startsWith("fillcmdline ")) { // Ugh. That's ugly. I needed a way to know if this command is going to open the cmdline. - logger.debug("Setting mustBufferPageKeysForClInput to true") + logger.debug("Starting buffering of page keys") mustBufferPageKeysForClInput = true bufferedPageKeys = [] } @@ -217,27 +228,19 @@ function* ParserController() { } } } -Messaging.addListener("buffered_page_keys", (message, sender, sendResponse) => { - logger.debug("buffered_page_keys request received, responding with", bufferedPageKeys) - // At this point, clInput is focused and the page will not get any more keyboard events. - sendResponse(Promise.resolve(bufferedPageKeys)) - mustBufferPageKeysForClInput = false - bufferedPageKeys = [] -}) -let mustBufferPageKeysForClInput = false -let bufferedPageKeys: string[] = [] + export const generator = ParserController() // var rather than let stops weirdness in repl. generator.next() /** Feed keys to the ParserController */ export function acceptKey(keyevent: KeyboardEvent) { - logger.debug("mustBufferPageKeysForClInput = " + mustBufferPageKeysForClInput) + logger.debug("controller_content mustBufferPageKeysForClInput = " + mustBufferPageKeysForClInput) if (mustBufferPageKeysForClInput) { let isCharacterKey = keyevent.key.length == 1 && !keyevent.metaKey && !keyevent.ctrlKey && !keyevent.altKey && !keyevent.metaKey; if (isCharacterKey) { bufferedPageKeys.push(keyevent.key); - logger.debug("Buffering page keys for clInput", bufferedPageKeys) + logger.debug("Buffering page keys", bufferedPageKeys) } keyevent.preventDefault() keyevent.stopImmediatePropagation() diff --git a/src/excmds.ts b/src/excmds.ts index d6002d14..af528ee9 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -3861,12 +3861,11 @@ export function sleep(time_ms: number) { /** @hidden */ //#content export function showcmdline(focus = true) { - logger.debug("Called showcmdline") + logger.debug("excmds showcmdline()") const hidehover = true CommandLineContent.show(hidehover) let done = Promise.resolve() if (focus) { - CommandLineContent.focus() done = Messaging.messageOwnTab("commandline_frame", "focus") } return done