From 84ae795f343dbd6bc65968b81a09ca010b6d98a6 Mon Sep 17 00:00:00 2001 From: mozbug Date: Sun, 15 Mar 2020 21:05:41 +0800 Subject: [PATCH 1/4] show insert mode indicator properly --- src/content.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content.ts b/src/content.ts index c96f8bde..57646300 100644 --- a/src/content.ts +++ b/src/content.ts @@ -302,7 +302,7 @@ config.getAsync("modeindicator").then(mode => { dom.isTextEditable(document.activeElement) && !["input", "ignore"].includes(mode) ) { - statusIndicator.textContent = "insert" + result = "insert" // this doesn't work; statusIndicator.style is full of empty string // statusIndicator.style.borderColor = "green !important" // need to fix loss of focus by click: doesn't do anything here. @@ -310,7 +310,7 @@ config.getAsync("modeindicator").then(mode => { mode === "insert" && !dom.isTextEditable(document.activeElement) ) { - statusIndicator.textContent = "normal" + result = "normal" // statusIndicator.style.borderColor = "lightgray !important" } else { result = mode From 5f5fe2e6716ac23144593e5878b1bf2da9575af6 Mon Sep 17 00:00:00 2001 From: mozbug Date: Sun, 15 Mar 2020 23:28:45 +0800 Subject: [PATCH 2/4] Avoid unnecessary `suffix` message. In insert mode, each keypress will send a suffix message through Proxy and the suffix == "". Which is useless and rather heavy. Avoid that. --- src/content/controller_content.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/content/controller_content.ts b/src/content/controller_content.ts index 1dc9376e..30b842ea 100644 --- a/src/content/controller_content.ts +++ b/src/content/controller_content.ts @@ -106,6 +106,7 @@ function* ParserController() { while (true) { let exstr = "" + let previousSuffix = null let keyEvents: KeyEventLike[] = [] try { while (true) { @@ -145,6 +146,11 @@ function* ParserController() { contentState.mode = "normal" } + const newMode = contentState.mode + if (newMode !== currentMode) { + previousSuffix = null + } + // Accumulate key events. The parser will cut this // down whenever it's not a valid prefix of a known // binding, so it can't grow indefinitely unless you @@ -172,17 +178,20 @@ function* ParserController() { if (response.exstr) { exstr = response.exstr break - } else { + } else if (!["input", "insert", "ignore"].includes(newMode)) { keyEvents = response.keys // show current keyEvents as a suffix of the contentState - contentState.suffix = keyEvents + const suffix = keyEvents .map(x => PrintableKey(x)) .join("") - logger.debug("suffix: ", contentState.suffix) + if (previousSuffix !== suffix) + contentState.suffix = suffix + previousSuffix = suffix + logger.debug("suffix: ", suffix) } } - controller.acceptExCmd(exstr) contentState.suffix = "" + controller.acceptExCmd(exstr) } catch (e) { // Rumsfeldian errors are caught here logger.error("An error occurred in the content controller: ", e) From 6f9ecbbc777dc3ef77a7c7fec030fca1f55b3563 Mon Sep 17 00:00:00 2001 From: mozbug Date: Sun, 15 Mar 2020 23:33:20 +0800 Subject: [PATCH 3/4] Reset keyEvents on mode change. Fix #1769 --- src/content/controller_content.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/content/controller_content.ts b/src/content/controller_content.ts index 30b842ea..cf260398 100644 --- a/src/content/controller_content.ts +++ b/src/content/controller_content.ts @@ -148,6 +148,7 @@ function* ParserController() { const newMode = contentState.mode if (newMode !== currentMode) { + keyEvents = [] previousSuffix = null } From a64d60bd20633c1a982b62d27c7a8b339ec87405 Mon Sep 17 00:00:00 2001 From: mozbug Date: Mon, 23 Mar 2020 23:15:16 +0800 Subject: [PATCH 4/4] Remove mode check on keypress suffix update --- src/content/controller_content.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/content/controller_content.ts b/src/content/controller_content.ts index cf260398..2fceac9e 100644 --- a/src/content/controller_content.ts +++ b/src/content/controller_content.ts @@ -179,15 +179,16 @@ function* ParserController() { if (response.exstr) { exstr = response.exstr break - } else if (!["input", "insert", "ignore"].includes(newMode)) { + } else { keyEvents = response.keys // show current keyEvents as a suffix of the contentState const suffix = keyEvents .map(x => PrintableKey(x)) .join("") - if (previousSuffix !== suffix) + if (previousSuffix !== suffix) { contentState.suffix = suffix - previousSuffix = suffix + previousSuffix = suffix + } logger.debug("suffix: ", suffix) } }