mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Use modesubconfigs instead of preventautofocusmodes
This commit is contained in:
parent
adfe579de4
commit
8a679fb9ba
3 changed files with 59 additions and 18 deletions
|
@ -3778,6 +3778,28 @@ export function seturl(pattern: string, key: string, ...values: string[]) {
|
|||
return config.setURL(pattern, ...validateSetArgs(key, values))
|
||||
}
|
||||
|
||||
/**
|
||||
* Usage: `setmode mode key values`
|
||||
*
|
||||
* @param mode The Mode the setting should be set for, e.g. `insert` or `ignore`.
|
||||
* @param key The name of the setting you want to set, e.g. `allowautofocus`
|
||||
* @param values The value you wish for, e.g. `true`
|
||||
*
|
||||
* Currently this command is only supported for the following settings:
|
||||
* - [[allowautofocus]]
|
||||
*
|
||||
* Example:
|
||||
* - `setmode ignore allowautofocus true`
|
||||
*/
|
||||
//#content
|
||||
export function setmode(mode: string, key: string, ...values: string[]) {
|
||||
if (!mode || !key || !values.length) {
|
||||
throw new Error("seturl syntax: mode key value")
|
||||
}
|
||||
|
||||
return config.set("modesubconfigs", mode, ...validateSetArgs(key, values))
|
||||
}
|
||||
|
||||
/** Set a key value pair in config.
|
||||
|
||||
Use to set any values found [here](/static/docs/classes/_src_lib_config_.default_config.html).
|
||||
|
@ -4007,7 +4029,7 @@ export async function unbind(...args: string[]) {
|
|||
*
|
||||
* This unbinds `I` in ignore mode on every website the URL of which contains `jupyter`, while keeping the binding active everywhere else.
|
||||
*
|
||||
* Also see [[bind]], [[bindurl]], [[seturl]], [[unbind]], [[unseturl]]
|
||||
* Also see [[bind]], [[bindurl]], [[seturl]], [[unbind]], [[unseturl]], [[setmode]], [[unsetmode]]
|
||||
*/
|
||||
//#background
|
||||
export async function unbindurl(pattern: string, mode: string, keys: string) {
|
||||
|
@ -4043,6 +4065,8 @@ export async function reset(mode: string, key: string) {
|
|||
* - [[unbindurl]]
|
||||
* - [[seturl]]
|
||||
* - [[unseturl]]
|
||||
* - [[setmode]]
|
||||
* - [[unsetmode]]
|
||||
*/
|
||||
//#background
|
||||
export async function reseturl(pattern: string, mode: string, key: string) {
|
||||
|
@ -4263,6 +4287,23 @@ export function unseturl(pattern: string, key: string) {
|
|||
return config.unsetURL(pattern, key.split("."))
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset a mode-specific setting.
|
||||
*
|
||||
* usage: `unsetmode mode key`
|
||||
*
|
||||
* @param mode The mode the setting should be unset on, e.g. `insert`.
|
||||
* @param key The key that should be unset.
|
||||
*
|
||||
* Example: `unsetmode ignore allowautofocus`
|
||||
*
|
||||
* Note that this removes a setting from the mode-specific config, it doesn't "invert" it. This means that if you have a setting set to `false` in your global config and the same setting set to `false` in a mode-specific setting, using `unseturl` will result in the setting still being set to `false`.
|
||||
*/
|
||||
//#content
|
||||
export function unsetmode(mode: string, key: string) {
|
||||
return config.unset("modesubconfigs", mode, ...key.split("."))
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset a config setting to default
|
||||
*/
|
||||
|
|
|
@ -94,6 +94,21 @@ export class default_config {
|
|||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal field to handle mode-specific configs. Use :setmode/:unsetmode to change these values.
|
||||
*
|
||||
* Changing this might do weird stuff.
|
||||
*/
|
||||
modesubconfigs: { [key: string]: DeepPartial<default_config> } = {
|
||||
"normal": {},
|
||||
"insert": {},
|
||||
"input": {},
|
||||
"ignore": {},
|
||||
"ex": {},
|
||||
"hint": {},
|
||||
"visual": {},
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal field to handle site-specific config priorities. Use :seturl/:unseturl to change this value.
|
||||
*/
|
||||
|
@ -749,21 +764,6 @@ export class default_config {
|
|||
*/
|
||||
allowautofocus: "true" | "false" = "true"
|
||||
|
||||
/**
|
||||
* Controls modes which the [[allowautofocus]] setting will affect.
|
||||
*
|
||||
* This lets you suppress the effects of [[allowautofocus]] to allow page behavior in certain modes - by default this setting always allows the setting to take effect.
|
||||
*/
|
||||
preventautofocusmodes: { [key: string]: "true" | "false" } = {
|
||||
normal: "true",
|
||||
insert: "true",
|
||||
input: "true",
|
||||
ignore: "true",
|
||||
ex: "true",
|
||||
hint: "true",
|
||||
visual: "true",
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a loop to prevent focus until you interact with a page. Only recommended for use via `seturl` for problematic sites as it can be a little heavy on CPU if running on all tabs. Should be used in conjuction with [[allowautofocus]]
|
||||
*/
|
||||
|
|
|
@ -538,8 +538,8 @@ function onPageFocus(elem: HTMLElement): boolean {
|
|||
if (isTextEditable(elem)) {
|
||||
LAST_USED_INPUT = elem
|
||||
}
|
||||
const suppressSetting = config.get("preventautofocusmodes", contentState.mode) === "false"
|
||||
return suppressSetting || config.get("allowautofocus") === "true"
|
||||
const setting = config.get("modesubconfigs", contentState.mode, "allowautofocus") || config.get("allowautofocus")
|
||||
return setting === "true"
|
||||
}
|
||||
|
||||
async function setInput(el) {
|
||||
|
|
Loading…
Add table
Reference in a new issue