mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Send all keys typed in content page instead of just one key
Tab messages are not always received in order
This commit is contained in:
parent
5779121d5c
commit
6b61b69455
3 changed files with 43 additions and 30 deletions
|
@ -82,6 +82,8 @@ const commandline_state = {
|
||||||
keyEvents: new Array<MinimalKey>(),
|
keyEvents: new Array<MinimalKey>(),
|
||||||
refresh_completions,
|
refresh_completions,
|
||||||
state,
|
state,
|
||||||
|
keysFromContentProcess: [],
|
||||||
|
consumedKeyCount: 0,
|
||||||
clInputFocused: false,
|
clInputFocused: false,
|
||||||
clInputNormalEventsReceived: false,
|
clInputNormalEventsReceived: false,
|
||||||
clInputInitialValue: "",
|
clInputInitialValue: "",
|
||||||
|
@ -172,20 +174,27 @@ export function focus() {
|
||||||
commandline_state.clInput.addEventListener("blur", noblur)
|
commandline_state.clInput.addEventListener("blur", noblur)
|
||||||
commandline_state.clInputFocused = true
|
commandline_state.clInputFocused = true
|
||||||
Messaging.messageOwnTab("cl_input_focused", "unused")
|
Messaging.messageOwnTab("cl_input_focused", "unused")
|
||||||
|
const keysFromContentProcess = commandline_state.keysFromContentProcess;
|
||||||
if (keysFromContentProcess.length !== 0) {
|
if (keysFromContentProcess.length !== 0) {
|
||||||
logger.debug("Consuming " + JSON.stringify(keysFromContentProcess));
|
logger.debug("Consuming " + JSON.stringify(keysFromContentProcess.slice(commandline_state.consumedKeyCount)));
|
||||||
for (const key of keysFromContentProcess) {
|
for (let keyIndex = commandline_state.consumedKeyCount; keyIndex < keysFromContentProcess.length; keyIndex++) {
|
||||||
|
const key = keysFromContentProcess[keyIndex];
|
||||||
commandline_state.clInput.value += key
|
commandline_state.clInput.value += key
|
||||||
clInputValueChanged()
|
clInputValueChanged()
|
||||||
|
commandline_state.consumedKeyCount++;
|
||||||
}
|
}
|
||||||
keysFromContentProcess = []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let keysFromContentProcess: string[] = []
|
export function bufferUntilClInputFocused(bufferedClInputKeys) {
|
||||||
export function bufferUntilClInputFocused([key]) {
|
logger.debug("Command line process received content process keys: " + bufferedClInputKeys)
|
||||||
logger.debug("Command line process received content process keydown event: " + key)
|
if (bufferedClInputKeys.length < commandline_state.keysFromContentProcess.length)
|
||||||
|
return
|
||||||
|
commandline_state.keysFromContentProcess = bufferedClInputKeys;
|
||||||
|
const keysFromContentProcess = commandline_state.keysFromContentProcess;
|
||||||
if (commandline_state.clInputFocused) {
|
if (commandline_state.clInputFocused) {
|
||||||
|
for (let keyIndex = commandline_state.consumedKeyCount; keyIndex < keysFromContentProcess.length; keyIndex++) {
|
||||||
|
const key = keysFromContentProcess[keyIndex];
|
||||||
logger.debug("Dispatching received keydown event " + key + " since clInputFocused is true," +
|
logger.debug("Dispatching received keydown event " + key + " since clInputFocused is true," +
|
||||||
" clInputNormalEventsReceived = " + commandline_state.clInputNormalEventsReceived +
|
" clInputNormalEventsReceived = " + commandline_state.clInputNormalEventsReceived +
|
||||||
" contentProcessKeysReceivedAfterClInputFocused = " + commandline_state.contentProcessKeysReceivedAfterClInputFocused +
|
" contentProcessKeysReceivedAfterClInputFocused = " + commandline_state.contentProcessKeysReceivedAfterClInputFocused +
|
||||||
|
@ -193,8 +202,7 @@ export function bufferUntilClInputFocused([key]) {
|
||||||
if (!commandline_state.clInputNormalEventsReceived) {
|
if (!commandline_state.clInputNormalEventsReceived) {
|
||||||
// Insert at the end.
|
// Insert at the end.
|
||||||
commandline_state.clInput.value += key
|
commandline_state.clInput.value += key
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Normal keys are assumed to always be at the end.
|
// Normal keys are assumed to always be at the end.
|
||||||
let normalKeyCount = commandline_state.contentProcessKeysReceivedAfterClInputFocused;
|
let normalKeyCount = commandline_state.contentProcessKeysReceivedAfterClInputFocused;
|
||||||
let initialCommandLength = commandline_state.clInputInitialValue.length;
|
let initialCommandLength = commandline_state.clInputInitialValue.length;
|
||||||
|
@ -205,10 +213,9 @@ export function bufferUntilClInputFocused([key]) {
|
||||||
+ commandline_state.clInput.value.substring(initialCommandLength + normalKeyCount)
|
+ commandline_state.clInput.value.substring(initialCommandLength + normalKeyCount)
|
||||||
commandline_state.contentProcessKeysReceivedAfterClInputFocused++;
|
commandline_state.contentProcessKeysReceivedAfterClInputFocused++;
|
||||||
}
|
}
|
||||||
|
commandline_state.consumedKeyCount++;
|
||||||
clInputValueChanged()
|
clInputValueChanged()
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
keysFromContentProcess.push(key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,7 @@ function* ParserController() {
|
||||||
if (exstr.startsWith("fillcmdline ")) { // Ugh. That's ugly. I needed a way to know if this command is going to open the cmdline.
|
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 clInputFocused to false")
|
logger.debug("Setting clInputFocused to false")
|
||||||
clInputFocused = false
|
clInputFocused = false
|
||||||
|
bufferedClInputKeys = []
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
|
@ -221,6 +222,7 @@ Messaging.addListener("cl_input_focused", () => {
|
||||||
clInputFocused = true
|
clInputFocused = true
|
||||||
})
|
})
|
||||||
let clInputFocused: boolean = true
|
let clInputFocused: boolean = true
|
||||||
|
let bufferedClInputKeys: string[] = []
|
||||||
export const generator = ParserController() // var rather than let stops weirdness in repl.
|
export const generator = ParserController() // var rather than let stops weirdness in repl.
|
||||||
generator.next()
|
generator.next()
|
||||||
|
|
||||||
|
@ -231,8 +233,9 @@ export function acceptKey(keyevent: KeyboardEvent) {
|
||||||
let isCharacterKey = keyevent.key.length == 1
|
let isCharacterKey = keyevent.key.length == 1
|
||||||
&& !keyevent.metaKey && !keyevent.ctrlKey && !keyevent.altKey && !keyevent.metaKey;
|
&& !keyevent.metaKey && !keyevent.ctrlKey && !keyevent.altKey && !keyevent.metaKey;
|
||||||
if (isCharacterKey) {
|
if (isCharacterKey) {
|
||||||
logger.debug("Sending keyboardEvent for buffering ", keyevent)
|
bufferedClInputKeys.push(keyevent.key);
|
||||||
Messaging.messageOwnTab("commandline_frame", "bufferUntilClInputFocused", [keyevent.key]);
|
logger.debug("Sending keyboardEvent for buffering ", bufferedClInputKeys)
|
||||||
|
Messaging.messageOwnTab("commandline_frame", "bufferUntilClInputFocused", [ bufferedClInputKeys ]);
|
||||||
}
|
}
|
||||||
keyevent.preventDefault()
|
keyevent.preventDefault()
|
||||||
keyevent.stopImmediatePropagation()
|
keyevent.stopImmediatePropagation()
|
||||||
|
|
|
@ -139,8 +139,11 @@ export function getCommandlineFns(cmdline_state: {
|
||||||
cmdline_state.activeCompletions = undefined
|
cmdline_state.activeCompletions = undefined
|
||||||
cmdline_state.isVisible = false
|
cmdline_state.isVisible = false
|
||||||
console.debug("Called hide_and_clear()")
|
console.debug("Called hide_and_clear()")
|
||||||
|
cmdline_state.keysFromContentProcess = []
|
||||||
|
cmdline_state.consumedKeyCount = 0
|
||||||
cmdline_state.clInputFocused = false
|
cmdline_state.clInputFocused = false
|
||||||
cmdline_state.clInputNormalEventsReceived = false
|
cmdline_state.clInputNormalEventsReceived = false
|
||||||
|
cmdline_state.clInputInitialValue = ""
|
||||||
cmdline_state.contentProcessKeysReceivedAfterClInputFocused = 0
|
cmdline_state.contentProcessKeysReceivedAfterClInputFocused = 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue