mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Add type checking to first arg of config.get
Also document noiframeon, which I discovered was undocumented because of the type checking. It makes splatted config.gets rather uglier with `...args` -> `args[0] as keyof config.default_config, args.slice(1)...`. It has apparently also broken config completions.
This commit is contained in:
parent
7b6508a3e1
commit
7717c18e92
2 changed files with 14 additions and 6 deletions
|
@ -3020,7 +3020,7 @@ export function bind(...args: string[]) {
|
|||
for (let i = 0; i < args_obj.key.length; i++) {
|
||||
// Check if any initial subsequence of the key exists and will shadow the new binding
|
||||
const key_sub = args_obj.key.slice(0, i)
|
||||
if (config.get(args_obj.configName, key_sub)) {
|
||||
if (config.get(args_obj.configName as keyof config.default_config, key_sub)) {
|
||||
fillcmdline_notrail("# Warning: bind `" + key_sub + "` exists and will shadow `" + args_obj.key + "`. Try running `:unbind --mode=" + args_obj.mode + " " + key_sub + "`")
|
||||
break
|
||||
}
|
||||
|
@ -3028,7 +3028,7 @@ export function bind(...args: string[]) {
|
|||
p = config.set(args_obj.configName, args_obj.key, args_obj.excmd)
|
||||
} else if (args_obj.key.length) {
|
||||
// Display the existing bind
|
||||
p = fillcmdline_notrail("#", args_obj.key, "=", config.get(args_obj.configName, args_obj.key))
|
||||
p = fillcmdline_notrail("#", args_obj.key, "=", config.get(args_obj.configName as keyof config.default_config, args_obj.key))
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
@ -3457,7 +3457,9 @@ export async function quickmark(key: string, ...addressarr: string[]) {
|
|||
//#background
|
||||
export function get(...keys: string[]) {
|
||||
const target = keys.join(".").split(".")
|
||||
const value = config.get(...target)
|
||||
const value = config.get(
|
||||
target[0] as keyof config.default_config, ...target.slice(1)
|
||||
)
|
||||
console.log(value)
|
||||
if (typeof value === "object") {
|
||||
fillcmdline_notrail(`# ${keys.join(".")} = ${JSON.stringify(value)}`)
|
||||
|
@ -3487,7 +3489,7 @@ export function viewconfig(key?: string) {
|
|||
else
|
||||
window.location.href =
|
||||
"data:application/json," +
|
||||
JSON.stringify(config.get(key))
|
||||
JSON.stringify(config.get(key as keyof config.default_config))
|
||||
.replace(/#/g, "%23")
|
||||
.replace(/ /g, "%20")
|
||||
// base 64 encoding is a cleverer way of doing this, but it doesn't seem to work for the whole config.
|
||||
|
|
|
@ -47,7 +47,7 @@ export type LoggingLevel = "never" | "error" | "warning" | "info" | "debug"
|
|||
*
|
||||
* You can change anything here using `set key1.key2.key3 value` or specific things any of the various helper commands such as `bind` or `command`. You can also jump to the help section of a setting using `:help $settingname`. Some of the settings have an input field containing their current value. You can modify these values and save them by pressing `<Enter>` but using `:set $setting $value` is a good habit to take as it doesn't force you to leave the page you're visiting to change your settings.
|
||||
*/
|
||||
class default_config {
|
||||
export class default_config {
|
||||
/**
|
||||
* Internal version number Tridactyl uses to know whether it needs to update from old versions of the configuration.
|
||||
*
|
||||
|
@ -699,6 +699,11 @@ class default_config {
|
|||
*/
|
||||
noiframe: "true" | "false" = "false"
|
||||
|
||||
/**
|
||||
* @deprecated A list of URLs on which to not load the iframe. Use `seturl [URL] noiframe true` instead, as shown in [[noiframe]].
|
||||
*/
|
||||
noiframeon: string[] = []
|
||||
|
||||
/**
|
||||
* Insert / input mode edit-in-$EDITOR command to run
|
||||
* This has to be a command that stays in the foreground for the whole editing session
|
||||
|
@ -998,7 +1003,8 @@ export function getURL(url: string, target: string[]) {
|
|||
defaults, if one exists, else undefined.
|
||||
@hidden
|
||||
*/
|
||||
export function get(...target) {
|
||||
export function get(target_typed?: keyof default_config, ...target: string[]) {
|
||||
target = [(target_typed as string)].concat(target)
|
||||
// Window.tri might not be defined when called from the untrusted page context
|
||||
let loc = window.location
|
||||
if ((window as any).tri && (window as any).tri.contentLocation)
|
||||
|
|
Loading…
Add table
Reference in a new issue