mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Attempt to buffer keyboard events until command line is opened
This commit is contained in:
parent
f224e6cf44
commit
4a31b3ac20
4 changed files with 122 additions and 59 deletions
|
@ -162,9 +162,42 @@ const noblur = () => setTimeout(() => commandline_state.clInput.focus(), 0)
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
export function focus() {
|
export function focus() {
|
||||||
|
setTimeout(() => {
|
||||||
|
logger.info("Called focus() after 2000ms")
|
||||||
|
Messaging.messageOwnTab("clInputFocused", "unused")
|
||||||
commandline_state.clInput.focus()
|
commandline_state.clInput.focus()
|
||||||
commandline_state.clInput.removeEventListener("blur", noblur)
|
commandline_state.clInput.removeEventListener("blur", noblur)
|
||||||
commandline_state.clInput.addEventListener("blur", noblur)
|
commandline_state.clInput.addEventListener("blur", noblur)
|
||||||
|
if (buffer.length !== 0) {
|
||||||
|
logger.info("Dispatching " + JSON.stringify(buffer));
|
||||||
|
buffer.forEach(e => processKeyboardEvent(e))
|
||||||
|
buffer.splice(-1)
|
||||||
|
}
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
let buffer: KeyboardEvent[] = []
|
||||||
|
export function bufferUntil([ code,
|
||||||
|
key,
|
||||||
|
altKey,
|
||||||
|
ctrlKey,
|
||||||
|
metaKey,
|
||||||
|
shiftKey]) {
|
||||||
|
const keyevent = new KeyboardEvent('keydown', {
|
||||||
|
code: code,
|
||||||
|
key: key,
|
||||||
|
altKey: altKey,
|
||||||
|
ctrlKey: ctrlKey,
|
||||||
|
metaKey: metaKey,
|
||||||
|
shiftKey: shiftKey,
|
||||||
|
})
|
||||||
|
logger.info("Received keyboardEvent for buffering", keyevent)
|
||||||
|
if (window.document.activeElement === commandline_state.clInput) {
|
||||||
|
processKeyboardEvent(keyevent)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
buffer.push(keyevent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
|
@ -182,12 +215,19 @@ let prev_cmd_called_history = false
|
||||||
// Save programmer time by generating an immediately resolved promise
|
// Save programmer time by generating an immediately resolved promise
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
const QUEUE: Promise<any>[] = [(async () => {})()]
|
const QUEUE: Promise<any>[] = [(async () => {})()]
|
||||||
|
logger.info("Setting event listeners of commandline_state.clInput")
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
commandline_state.clInput.addEventListener(
|
commandline_state.clInput.addEventListener(
|
||||||
"keydown",
|
"keydown",
|
||||||
function (keyevent: KeyboardEvent) {
|
function (keyevent: KeyboardEvent) {
|
||||||
if (!keyevent.isTrusted) return
|
if (!keyevent.isTrusted) return
|
||||||
|
processKeyboardEvent(keyevent);
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
||||||
|
function processKeyboardEvent(keyevent: KeyboardEvent) {
|
||||||
commandline_state.keyEvents.push(minimalKeyFromKeyboardEvent(keyevent))
|
commandline_state.keyEvents.push(minimalKeyFromKeyboardEvent(keyevent))
|
||||||
const response = keyParser(commandline_state.keyEvents)
|
const response = keyParser(commandline_state.keyEvents)
|
||||||
if (response.isMatch) {
|
if (response.isMatch) {
|
||||||
|
@ -240,9 +280,7 @@ commandline_state.clInput.addEventListener(
|
||||||
} else {
|
} else {
|
||||||
commandline_state.keyEvents = response.keys
|
commandline_state.keyEvents = response.keys
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
export function refresh_completions(exstr) {
|
export function refresh_completions(exstr) {
|
||||||
if (!commandline_state.activeCompletions) enableCompletions()
|
if (!commandline_state.activeCompletions) enableCompletions()
|
||||||
|
|
|
@ -63,7 +63,7 @@ export function show(hidehover = false) {
|
||||||
*
|
*
|
||||||
* Inspired by VVimpulation: https://github.com/amedama41/vvimpulation/commit/53065d015d1e9a892496619b51be83771f57b3d5
|
* Inspired by VVimpulation: https://github.com/amedama41/vvimpulation/commit/53065d015d1e9a892496619b51be83771f57b3d5
|
||||||
*/
|
*/
|
||||||
|
logger.info("Called show()")
|
||||||
if (hidehover) {
|
if (hidehover) {
|
||||||
const a = window.document.createElement("A")
|
const a = window.document.createElement("A")
|
||||||
;(a as any).href = ""
|
;(a as any).href = ""
|
||||||
|
@ -98,7 +98,7 @@ export function hide() {
|
||||||
|
|
||||||
export function focus() {
|
export function focus() {
|
||||||
try {
|
try {
|
||||||
cmdline_iframe.focus()
|
// cmdline_iframe.focus()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Note: We can't use cmdline_logger.error because it will try to log
|
// Note: We can't use cmdline_logger.error because it will try to log
|
||||||
// the error in the commandline, which will need to focus() it again,
|
// the error in the commandline, which will need to focus() it again,
|
||||||
|
|
|
@ -14,6 +14,7 @@ import * as hinting from "@src/content/hinting"
|
||||||
import * as gobblemode from "@src/parsers/gobblemode"
|
import * as gobblemode from "@src/parsers/gobblemode"
|
||||||
import * as generic from "@src/parsers/genericmode"
|
import * as generic from "@src/parsers/genericmode"
|
||||||
import * as nmode from "@src/parsers/nmode"
|
import * as nmode from "@src/parsers/nmode"
|
||||||
|
import * as Messaging from "@src/lib/messaging";
|
||||||
|
|
||||||
const logger = new Logger("controller")
|
const logger = new Logger("controller")
|
||||||
|
|
||||||
|
@ -191,6 +192,10 @@ function* ParserController() {
|
||||||
|
|
||||||
if (response.exstr) {
|
if (response.exstr) {
|
||||||
exstr = response.exstr
|
exstr = response.exstr
|
||||||
|
if (exstr.startsWith("fillcmdline ")) {
|
||||||
|
logger.info("Setting bufferUntilClInputFocused to true")
|
||||||
|
bufferUntilClInputFocused = true
|
||||||
|
}
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
keyEvents = response.keys
|
keyEvents = response.keys
|
||||||
|
@ -211,11 +216,30 @@ function* ParserController() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Messaging.addListener("clInputFocused", () => {
|
||||||
|
logger.info("Callback clInputFocused")
|
||||||
|
bufferUntilClInputFocused = false
|
||||||
|
})
|
||||||
|
let bufferUntilClInputFocused: boolean = false
|
||||||
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()
|
||||||
|
|
||||||
/** Feed keys to the ParserController */
|
/** Feed keys to the ParserController */
|
||||||
export function acceptKey(keyevent: KeyboardEvent) {
|
export function acceptKey(keyevent: KeyboardEvent) {
|
||||||
|
logger.info("bufferUntilClInputFocused = " + bufferUntilClInputFocused)
|
||||||
|
if (bufferUntilClInputFocused) {
|
||||||
|
logger.info("Sending keyboardEvent for buffering " + keyevent.key)
|
||||||
|
Messaging.messageOwnTab("commandline_frame", "bufferUntil",
|
||||||
|
[keyevent.code,
|
||||||
|
keyevent.key,
|
||||||
|
keyevent.altKey,
|
||||||
|
keyevent.ctrlKey,
|
||||||
|
keyevent.metaKey,
|
||||||
|
keyevent.shiftKey]
|
||||||
|
);
|
||||||
|
keyevent.preventDefault()
|
||||||
|
keyevent.stopImmediatePropagation()
|
||||||
|
canceller.push(keyevent)
|
||||||
|
} else
|
||||||
return generator.next(keyevent)
|
return generator.next(keyevent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ export type TabMessageType =
|
||||||
| "lock"
|
| "lock"
|
||||||
| "alive"
|
| "alive"
|
||||||
| "tab_changes"
|
| "tab_changes"
|
||||||
|
| "clInputFocused"
|
||||||
|
|
||||||
export type NonTabMessageType =
|
export type NonTabMessageType =
|
||||||
| "owntab_background"
|
| "owntab_background"
|
||||||
|
|
Loading…
Add table
Reference in a new issue