mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Re-enable no-inferrable-types
This commit is contained in:
parent
df88ab18ff
commit
bb872c223d
10 changed files with 99 additions and 69 deletions
|
@ -108,7 +108,7 @@ module.exports = {
|
||||||
"@typescript-eslint/no-floating-promises": "off", //"error",
|
"@typescript-eslint/no-floating-promises": "off", //"error",
|
||||||
"@typescript-eslint/no-for-in-array": "error",
|
"@typescript-eslint/no-for-in-array": "error",
|
||||||
"@typescript-eslint/no-implied-eval": "error",
|
"@typescript-eslint/no-implied-eval": "error",
|
||||||
"@typescript-eslint/no-inferrable-types": "off", //"error",
|
"@typescript-eslint/no-inferrable-types": "error",
|
||||||
"@typescript-eslint/no-misused-new": "error",
|
"@typescript-eslint/no-misused-new": "error",
|
||||||
"@typescript-eslint/no-misused-promises": ["error",
|
"@typescript-eslint/no-misused-promises": ["error",
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,10 +12,10 @@ class BindingsCompletionOption extends Completions.CompletionOptionHTML
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
this.html = html`<tr class="BindingsCompletionOption option">
|
this.html = html`<tr class="BindingsCompletionOption option">
|
||||||
<td class="name">${binding.name}</td>
|
<td class="name">${binding.name}</td>
|
||||||
<td class="content">${binding.value}</td>
|
<td class="content">${binding.value}</td>
|
||||||
<td class="type">${binding.mode}</td>
|
<td class="type">${binding.mode}</td>
|
||||||
</tr>`
|
</tr>`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +36,10 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
this.lastExstr = exstr
|
this.lastExstr = exstr
|
||||||
let options = ""
|
let options = ""
|
||||||
let [prefix, query] = this.splitOnPrefix(exstr)
|
let [prefix, query] = this.splitOnPrefix(exstr)
|
||||||
const args = query ? query.split(/\s+/) : []
|
const args = query ? query.split(/\s+/) : []
|
||||||
let configName: string = "nmaps"
|
let configName = "nmaps"
|
||||||
let modeName = "normal"
|
let modeName = "normal"
|
||||||
let urlPattern: string = null
|
let urlPattern: string = null
|
||||||
|
|
||||||
// Hide self and stop if prefixes don't match
|
// Hide self and stop if prefixes don't match
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
|
@ -64,12 +64,14 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
this.options = Object.keys(patterns)
|
this.options = Object.keys(patterns)
|
||||||
.filter(pattern => pattern.startsWith(urlPattern))
|
.filter(pattern => pattern.startsWith(urlPattern))
|
||||||
.sort()
|
.sort()
|
||||||
.map(pattern => new BindingsCompletionOption(
|
.map(
|
||||||
pattern, {
|
pattern =>
|
||||||
name: pattern,
|
new BindingsCompletionOption(pattern, {
|
||||||
value: "",
|
name: pattern,
|
||||||
mode: "URL Pattern",
|
value: "",
|
||||||
}))
|
mode: "URL Pattern",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
return this.updateChain()
|
return this.updateChain()
|
||||||
}
|
}
|
||||||
|
@ -81,13 +83,18 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
if ("--mode".includes(margs[0])) {
|
if ("--mode".includes(margs[0])) {
|
||||||
const modeStr = margs.length > 1 ? margs[1] : ""
|
const modeStr = margs.length > 1 ? margs[1] : ""
|
||||||
this.options = Binding.modes
|
this.options = Binding.modes
|
||||||
.filter(k => k.startsWith(modeStr))
|
.filter(k => k.startsWith(modeStr))
|
||||||
.map(name => new BindingsCompletionOption(
|
.map(
|
||||||
options + "--mode=" + name, {
|
name =>
|
||||||
name,
|
new BindingsCompletionOption(
|
||||||
value: "",
|
options + "--mode=" + name,
|
||||||
mode: "Mode Name",
|
{
|
||||||
}))
|
name,
|
||||||
|
value: "",
|
||||||
|
mode: "Mode Name",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
return this.updateChain()
|
return this.updateChain()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +116,9 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
return this.updateChain()
|
return this.updateChain()
|
||||||
}
|
}
|
||||||
|
|
||||||
const bindings = urlPattern ? config.getURL(urlPattern, [configName]) : config.get(configName as any)
|
const bindings = urlPattern
|
||||||
|
? config.getURL(urlPattern, [configName])
|
||||||
|
: config.get(configName as any)
|
||||||
|
|
||||||
if (bindings === undefined) {
|
if (bindings === undefined) {
|
||||||
this.options = []
|
this.options = []
|
||||||
|
@ -118,14 +127,19 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
|
|
||||||
query = args.join(" ").toLowerCase()
|
query = args.join(" ").toLowerCase()
|
||||||
this.options = Object.keys(bindings)
|
this.options = Object.keys(bindings)
|
||||||
.filter(x => x.toLowerCase().startsWith(query) )
|
.filter(x => x.toLowerCase().startsWith(query))
|
||||||
.sort()
|
.sort()
|
||||||
.map(keystr => new BindingsCompletionOption(
|
.map(
|
||||||
options + keystr + " " + bindings[keystr], {
|
keystr =>
|
||||||
name: keystr,
|
new BindingsCompletionOption(
|
||||||
value: JSON.stringify(bindings[keystr]),
|
options + keystr + " " + bindings[keystr],
|
||||||
mode: `${configName} (${modeName})`,
|
{
|
||||||
}))
|
name: keystr,
|
||||||
|
value: JSON.stringify(bindings[keystr]),
|
||||||
|
mode: `${configName} (${modeName})`,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
return this.updateChain()
|
return this.updateChain()
|
||||||
}
|
}
|
||||||
|
@ -137,6 +151,4 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
||||||
// Call concrete class
|
// Call concrete class
|
||||||
return this.updateDisplay()
|
return this.updateDisplay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,17 +63,22 @@ class ScrollingData {
|
||||||
* It might be useful to make this function more configurable by making it
|
* It might be useful to make this function more configurable by making it
|
||||||
* accept an argument instead of using performance.now()
|
* accept an argument instead of using performance.now()
|
||||||
*/
|
*/
|
||||||
private getStep(): number {
|
private getStep(): number {
|
||||||
if (this.startTime === undefined) {
|
if (this.startTime === undefined) {
|
||||||
this.startTime = performance.now()
|
this.startTime = performance.now()
|
||||||
}
|
}
|
||||||
const elapsed: number = performance.now() - this.startTime
|
const elapsed: number = performance.now() - this.startTime
|
||||||
|
|
||||||
// If the animation should be done, return the position the element should have
|
// If the animation should be done, return the position the element should have
|
||||||
if (elapsed >= this.duration || this.elem[this.scrollDirection] === this.endPos)
|
if (
|
||||||
|
elapsed >= this.duration ||
|
||||||
|
this.elem[this.scrollDirection] === this.endPos
|
||||||
|
)
|
||||||
return this.endPos
|
return this.endPos
|
||||||
|
|
||||||
let pixelToScrollTo: number = this.startPos + (((this.endPos - this.startPos) * elapsed) / this.duration)
|
let pixelToScrollTo: number =
|
||||||
|
this.startPos +
|
||||||
|
((this.endPos - this.startPos) * elapsed) / this.duration
|
||||||
if (this.startPos < this.endPos) {
|
if (this.startPos < this.endPos) {
|
||||||
// We need to ceil() because only highdpi screens have a decimal this.elem[this.pos]
|
// We need to ceil() because only highdpi screens have a decimal this.elem[this.pos]
|
||||||
pixelToScrollTo = Math.ceil(pixelToScrollTo)
|
pixelToScrollTo = Math.ceil(pixelToScrollTo)
|
||||||
|
@ -104,7 +109,6 @@ class ScrollingData {
|
||||||
this.scrollStep() ? this.scheduleStep() : (this.scrolling = false),
|
this.scrollStep() ? this.scheduleStep() : (this.scrolling = false),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stores elements that are currently being horizontally scrolled
|
// Stores elements that are currently being horizontally scrolled
|
||||||
|
@ -116,8 +120,8 @@ const verticallyScrolling = new Map<Node, ScrollingData>()
|
||||||
* last duration milliseconds
|
* last duration milliseconds
|
||||||
*/
|
*/
|
||||||
export async function scroll(
|
export async function scroll(
|
||||||
xDistance: number = 0,
|
xDistance = 0,
|
||||||
yDistance: number = 0,
|
yDistance = 0,
|
||||||
e: Node,
|
e: Node,
|
||||||
duration?: number,
|
duration?: number,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
@ -189,15 +193,15 @@ export async function recursiveScroll(
|
||||||
startingFromCached = true
|
startingFromCached = true
|
||||||
node = lastRecursiveScrolled
|
node = lastRecursiveScrolled
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Try scrolling the active node or one of its parent elements
|
// Try scrolling the active node or one of its parent elements
|
||||||
|
|
||||||
// If nothing has been given focus explicitly use the activeElement
|
// If nothing has been given focus explicitly use the activeElement
|
||||||
if (!currentFocused || currentFocused.nodeName == "#document") currentFocused = document.activeElement
|
if (!currentFocused || currentFocused.nodeName == "#document")
|
||||||
|
currentFocused = document.activeElement
|
||||||
|
|
||||||
node = currentFocused
|
node = currentFocused
|
||||||
while (true) {
|
while (true) {
|
||||||
if ((await scroll(xDistance, yDistance, node))) return true
|
if (await scroll(xDistance, yDistance, node)) return true
|
||||||
node = node.parentElement
|
node = node.parentElement
|
||||||
if (!node) break
|
if (!node) break
|
||||||
}
|
}
|
||||||
|
@ -215,7 +219,9 @@ export async function recursiveScroll(
|
||||||
if (
|
if (
|
||||||
(await scroll(xDistance, yDistance, treeWalker.currentNode)) ||
|
(await scroll(xDistance, yDistance, treeWalker.currentNode)) ||
|
||||||
((treeWalker.currentNode as any).contentDocument &&
|
((treeWalker.currentNode as any).contentDocument &&
|
||||||
!(treeWalker.currentNode as any).src.startsWith("moz-extension://") &&
|
!(treeWalker.currentNode as any).src.startsWith(
|
||||||
|
"moz-extension://",
|
||||||
|
) &&
|
||||||
(await recursiveScroll(
|
(await recursiveScroll(
|
||||||
xDistance,
|
xDistance,
|
||||||
yDistance,
|
yDistance,
|
||||||
|
|
|
@ -19,10 +19,14 @@ export class PrevInput {
|
||||||
|
|
||||||
class ContentState {
|
class ContentState {
|
||||||
mode: ModeName = "normal"
|
mode: ModeName = "normal"
|
||||||
suffix: string = ""
|
suffix = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ContentStateProperty = "mode" | "cmdHistory" | "prevInputs" | "suffix"
|
export type ContentStateProperty =
|
||||||
|
| "mode"
|
||||||
|
| "cmdHistory"
|
||||||
|
| "prevInputs"
|
||||||
|
| "suffix"
|
||||||
|
|
||||||
export type ContentStateChangedCallback = (
|
export type ContentStateChangedCallback = (
|
||||||
property: ContentStateProperty,
|
property: ContentStateProperty,
|
||||||
|
|
|
@ -1031,7 +1031,7 @@ export class default_config {
|
||||||
* statistics, so somewhere around 10k samples.
|
* statistics, so somewhere around 10k samples.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
perfsamples: string = "10000"
|
perfsamples = "10000"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show (partial) command in the mode indicator.
|
* Show (partial) command in the mode indicator.
|
||||||
|
|
|
@ -144,12 +144,7 @@ export async function exists(cname: string): Promise<boolean> {
|
||||||
@param color
|
@param color
|
||||||
@param icon
|
@param icon
|
||||||
*/
|
*/
|
||||||
export function fromString(
|
export function fromString(name: string, color: string, icon: string, id = "") {
|
||||||
name: string,
|
|
||||||
color: string,
|
|
||||||
icon: string,
|
|
||||||
id: string = "",
|
|
||||||
) {
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
color: color as browser.contextualIdentities.IdentityColor,
|
color: color as browser.contextualIdentities.IdentityColor,
|
||||||
|
|
|
@ -278,13 +278,13 @@ export function wordAfterPos(text: string, position: number) {
|
||||||
/** @hidden
|
/** @hidden
|
||||||
* Rots by 13.
|
* Rots by 13.
|
||||||
*/
|
*/
|
||||||
export const rot13_helper = (s: string, n: number = 13): string => {
|
export const rot13_helper = (s: string, n = 13): string => {
|
||||||
let sa = s.split("")
|
let sa = s.split("")
|
||||||
sa = sa.map(x => charesar(x, n))
|
sa = sa.map(x => charesar(x, n))
|
||||||
return sa.join("")
|
return sa.join("")
|
||||||
}
|
}
|
||||||
|
|
||||||
export const charesar = (c: string, n: number = 13): string => {
|
export const charesar = (c: string, n = 13): string => {
|
||||||
const cn = c.charCodeAt(0)
|
const cn = c.charCodeAt(0)
|
||||||
if (cn >= 65 && cn <= 90)
|
if (cn >= 65 && cn <= 90)
|
||||||
return String.fromCharCode(((cn - 65 + n) % 26) + 65)
|
return String.fromCharCode(((cn - 65 + n) % 26) + 65)
|
||||||
|
|
|
@ -16,7 +16,7 @@ let modeState: NModeState
|
||||||
|
|
||||||
/** Init n [mode] mode. After parsing the defined number of commands, execute
|
/** Init n [mode] mode. After parsing the defined number of commands, execute
|
||||||
`endCmd`. `Escape` cancels the mode and executes `endCmd`. */
|
`endCmd`. `Escape` cancels the mode and executes `endCmd`. */
|
||||||
export function init(endCommand: string, mode = "normal", numCommands: number = 1) {
|
export function init(endCommand: string, mode = "normal", numCommands = 1) {
|
||||||
contentState.mode = "nmode"
|
contentState.mode = "nmode"
|
||||||
modeState = new NModeState()
|
modeState = new NModeState()
|
||||||
modeState.endCommand = endCommand
|
modeState.endCommand = endCommand
|
||||||
|
@ -40,10 +40,13 @@ export function parser(keys: KeyboardEvent[]) {
|
||||||
}
|
}
|
||||||
const response = keyseq.parse(keys, maps)
|
const response = keyseq.parse(keys, maps)
|
||||||
|
|
||||||
if ((response.exstr !== undefined && response.isMatch) || !response.isMatch) modeState.curCommands += 1
|
if ((response.exstr !== undefined && response.isMatch) || !response.isMatch)
|
||||||
|
modeState.curCommands += 1
|
||||||
if (modeState.curCommands >= modeState.numCommands) {
|
if (modeState.curCommands >= modeState.numCommands) {
|
||||||
const prefix =
|
const prefix =
|
||||||
(response.exstr === undefined) ? "" : ("composite " + response.exstr + "; ")
|
response.exstr === undefined
|
||||||
|
? ""
|
||||||
|
: "composite " + response.exstr + "; "
|
||||||
response.exstr = prefix + modeState.endCommand // NB: this probably breaks any `js` binds
|
response.exstr = prefix + modeState.endCommand // NB: this probably breaks any `js` binds
|
||||||
modeState = undefined
|
modeState = undefined
|
||||||
}
|
}
|
||||||
|
|
12
src/perf.ts
12
src/perf.ts
|
@ -192,9 +192,9 @@ export class StatsLogger {
|
||||||
// mapped symbol instead of the name so we're storing more like 50
|
// mapped symbol instead of the name so we're storing more like 50
|
||||||
// bytes per sample instead of 130 @_@
|
// bytes per sample instead of 130 @_@
|
||||||
public buffer: PerformanceEntry[] = []
|
public buffer: PerformanceEntry[] = []
|
||||||
private idx: number = 0
|
private idx = 0
|
||||||
private buffersize: number = 10000
|
private buffersize = 10000
|
||||||
private lastError: number = 0
|
private lastError = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Target for receiving stats entries from other threads - there
|
* Target for receiving stats entries from other threads - there
|
||||||
|
@ -301,8 +301,8 @@ export class StatsLogger {
|
||||||
*/
|
*/
|
||||||
export function renderStatsHistogram(
|
export function renderStatsHistogram(
|
||||||
samples: PerformanceEntry[],
|
samples: PerformanceEntry[],
|
||||||
buckets: number = 15,
|
buckets = 15,
|
||||||
width: number = 80,
|
width = 80,
|
||||||
): string {
|
): string {
|
||||||
const durs: number[] = samples.map(sample => sample.duration)
|
const durs: number[] = samples.map(sample => sample.duration)
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ export class StatsFilter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const TRI_PERFORMANCE_NAME_PREFIX: string = "tri"
|
const TRI_PERFORMANCE_NAME_PREFIX = "tri"
|
||||||
|
|
||||||
function performanceApiAvailable(): boolean {
|
function performanceApiAvailable(): boolean {
|
||||||
return performance.mark !== undefined
|
return performance.mark !== undefined
|
||||||
|
|
26
src/state.ts
26
src/state.ts
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
import Logger from "@src/lib/logging"
|
import Logger from "@src/lib/logging"
|
||||||
import * as messaging from "@src/lib/messaging"
|
import * as messaging from "@src/lib/messaging"
|
||||||
import {notBackground} from "@src/lib/webext"
|
import { notBackground } from "@src/lib/webext"
|
||||||
|
|
||||||
const logger = new Logger("state")
|
const logger = new Logger("state")
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class State {
|
||||||
jumppos: undefined,
|
jumppos: undefined,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
last_ex_str: string = "echo"
|
last_ex_str = "echo"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't change these from const or you risk breaking the Proxy below.
|
// Don't change these from const or you risk breaking the Proxy below.
|
||||||
|
@ -43,10 +43,11 @@ browser.storage.local
|
||||||
})
|
})
|
||||||
.catch((...args) => logger.error(...args))
|
.catch((...args) => logger.error(...args))
|
||||||
|
|
||||||
const state = (new Proxy(overlay, {
|
const state = new Proxy(overlay, {
|
||||||
/** Give defaults if overlay doesn't have the key */
|
/** Give defaults if overlay doesn't have the key */
|
||||||
get(target, property) {
|
get(target, property) {
|
||||||
if (notBackground()) throw "State object must be accessed with getAsync in content"
|
if (notBackground())
|
||||||
|
throw "State object must be accessed with getAsync in content"
|
||||||
if (property in target) {
|
if (property in target) {
|
||||||
return target[property]
|
return target[property]
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,7 +62,11 @@ const state = (new Proxy(overlay, {
|
||||||
|
|
||||||
logger.debug("State changed!", property, value)
|
logger.debug("State changed!", property, value)
|
||||||
if (notBackground()) {
|
if (notBackground()) {
|
||||||
browser.runtime.sendMessage({type: "state", command: "stateUpdate", args: {property, value}})
|
browser.runtime.sendMessage({
|
||||||
|
type: "state",
|
||||||
|
command: "stateUpdate",
|
||||||
|
args: { property, value },
|
||||||
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// Do we need a global storage lock?
|
// Do we need a global storage lock?
|
||||||
|
@ -69,10 +74,15 @@ const state = (new Proxy(overlay, {
|
||||||
browser.storage.local.set({ state: target } as any)
|
browser.storage.local.set({ state: target } as any)
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
}))
|
})
|
||||||
|
|
||||||
export async function getAsync(property) {
|
export async function getAsync(property) {
|
||||||
if (notBackground()) return browser.runtime.sendMessage({type: "state", command: "stateGet", args: [{prop: property}]})
|
if (notBackground())
|
||||||
|
return browser.runtime.sendMessage({
|
||||||
|
type: "state",
|
||||||
|
command: "stateGet",
|
||||||
|
args: [{ prop: property }],
|
||||||
|
})
|
||||||
else return state[property]
|
else return state[property]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +95,7 @@ messaging.addListener("state", (message, sender, sendResponse) => {
|
||||||
overlay[property] = value
|
overlay[property] = value
|
||||||
} else if (message.command == "stateGet") {
|
} else if (message.command == "stateGet") {
|
||||||
sendResponse(state[message.args[0].prop])
|
sendResponse(state[message.args[0].prop])
|
||||||
} else throw("Unsupported message to state, type " + message.command)
|
} else throw "Unsupported message to state, type " + message.command
|
||||||
})
|
})
|
||||||
|
|
||||||
export { state as default }
|
export { state as default }
|
||||||
|
|
Loading…
Add table
Reference in a new issue