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.
This commit is contained in:
mozbug 2020-03-15 23:28:45 +08:00
parent 84ae795f34
commit 5f5fe2e671

View file

@ -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)