mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Extract methods bufferPageKeyForClInput and consumeBufferedPageKeys
This commit is contained in:
parent
6b620276b6
commit
50f4288ffc
2 changed files with 15 additions and 11 deletions
|
@ -55,6 +55,7 @@ import state, * as State from "@src/state"
|
||||||
import * as R from "ramda"
|
import * as R from "ramda"
|
||||||
import { MinimalKey, minimalKeyFromKeyboardEvent } from "@src/lib/keyseq"
|
import { MinimalKey, minimalKeyFromKeyboardEvent } from "@src/lib/keyseq"
|
||||||
import { TabGroupCompletionSource } from "@src/completions/TabGroup"
|
import { TabGroupCompletionSource } from "@src/completions/TabGroup"
|
||||||
|
import {ownTabId} from "@src/lib/webext";
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
const logger = new Logger("cmdline")
|
const logger = new Logger("cmdline")
|
||||||
|
@ -163,11 +164,7 @@ const noblur = () => setTimeout(() => commandline_state.clInput.focus(), 0)
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
export function focus() {
|
export function focus() {
|
||||||
commandline_state.clInput.focus()
|
function consumeBufferedPageKeys(bufferedPageKeys: string[]) {
|
||||||
commandline_state.clInput.removeEventListener("blur", noblur)
|
|
||||||
commandline_state.clInput.addEventListener("blur", noblur)
|
|
||||||
logger.debug("commandline_frame clInput focus()")
|
|
||||||
Messaging.messageOwnTab("buffered_page_keys", "").then((bufferedPageKeys : string[]) => {
|
|
||||||
const clInputStillFocused = window.document.activeElement === commandline_state.clInput;
|
const clInputStillFocused = window.document.activeElement === commandline_state.clInput;
|
||||||
logger.debug("buffered_page_keys response received", bufferedPageKeys,
|
logger.debug("buffered_page_keys response received", bufferedPageKeys,
|
||||||
"clInputStillFocused = " + clInputStillFocused)
|
"clInputStillFocused = " + clInputStillFocused)
|
||||||
|
@ -181,7 +178,6 @@ export function focus() {
|
||||||
"currentClInputValue = " + currentClInputValue);
|
"currentClInputValue = " + currentClInputValue);
|
||||||
// Native events are assumed to be character keydowns events,
|
// Native events are assumed to be character keydowns events,
|
||||||
// i.e. characters appended at the end of clInput.
|
// i.e. characters appended at the end of clInput.
|
||||||
// Insert page keys just after the command.
|
|
||||||
commandline_state.clInput.value =
|
commandline_state.clInput.value =
|
||||||
initialClInputValue
|
initialClInputValue
|
||||||
+ bufferedPageKeys.join("")
|
+ bufferedPageKeys.join("")
|
||||||
|
@ -189,7 +185,12 @@ export function focus() {
|
||||||
// Update completion.
|
// Update completion.
|
||||||
clInputValueChanged()
|
clInputValueChanged()
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
logger.debug("commandline_frame clInput focus()")
|
||||||
|
commandline_state.clInput.focus()
|
||||||
|
commandline_state.clInput.removeEventListener("blur", noblur)
|
||||||
|
commandline_state.clInput.addEventListener("blur", noblur)
|
||||||
|
Messaging.messageTab(ownTabId(), "buffered_page_keys").then(consumeBufferedPageKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hidden **/
|
/** @hidden **/
|
||||||
|
|
|
@ -232,10 +232,9 @@ function* ParserController() {
|
||||||
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, unless they should be buffered to be later fed to clInput */
|
||||||
export function acceptKey(keyevent: KeyboardEvent) {
|
export function acceptKey(keyevent: KeyboardEvent) {
|
||||||
logger.debug("controller_content mustBufferPageKeysForClInput = " + mustBufferPageKeysForClInput)
|
function bufferPageKeyForClInput(keyevent: KeyboardEvent) {
|
||||||
if (mustBufferPageKeysForClInput) {
|
|
||||||
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) {
|
||||||
|
@ -245,6 +244,10 @@ export function acceptKey(keyevent: KeyboardEvent) {
|
||||||
keyevent.preventDefault()
|
keyevent.preventDefault()
|
||||||
keyevent.stopImmediatePropagation()
|
keyevent.stopImmediatePropagation()
|
||||||
canceller.push(keyevent)
|
canceller.push(keyevent)
|
||||||
} else
|
}
|
||||||
|
logger.debug("controller_content mustBufferPageKeysForClInput = " + mustBufferPageKeysForClInput)
|
||||||
|
if (mustBufferPageKeysForClInput)
|
||||||
|
bufferPageKeyForClInput(keyevent)
|
||||||
|
else
|
||||||
return generator.next(keyevent)
|
return generator.next(keyevent)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue