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-for-in-array": "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-promises": ["error",
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
let options = ""
|
||||
let [prefix, query] = this.splitOnPrefix(exstr)
|
||||
const args = query ? query.split(/\s+/) : []
|
||||
let configName: string = "nmaps"
|
||||
let configName = "nmaps"
|
||||
let modeName = "normal"
|
||||
let urlPattern: string = null
|
||||
|
||||
|
@ -64,12 +64,14 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
this.options = Object.keys(patterns)
|
||||
.filter(pattern => pattern.startsWith(urlPattern))
|
||||
.sort()
|
||||
.map(pattern => new BindingsCompletionOption(
|
||||
pattern, {
|
||||
.map(
|
||||
pattern =>
|
||||
new BindingsCompletionOption(pattern, {
|
||||
name: pattern,
|
||||
value: "",
|
||||
mode: "URL Pattern",
|
||||
}))
|
||||
}),
|
||||
)
|
||||
|
||||
return this.updateChain()
|
||||
}
|
||||
|
@ -82,12 +84,17 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
const modeStr = margs.length > 1 ? margs[1] : ""
|
||||
this.options = Binding.modes
|
||||
.filter(k => k.startsWith(modeStr))
|
||||
.map(name => new BindingsCompletionOption(
|
||||
options + "--mode=" + name, {
|
||||
.map(
|
||||
name =>
|
||||
new BindingsCompletionOption(
|
||||
options + "--mode=" + name,
|
||||
{
|
||||
name,
|
||||
value: "",
|
||||
mode: "Mode Name",
|
||||
}))
|
||||
},
|
||||
),
|
||||
)
|
||||
return this.updateChain()
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +116,9 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
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) {
|
||||
this.options = []
|
||||
|
@ -118,14 +127,19 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
query = args.join(" ").toLowerCase()
|
||||
this.options = Object.keys(bindings)
|
||||
.filter(x => x.toLowerCase().startsWith(query) )
|
||||
.filter(x => x.toLowerCase().startsWith(query))
|
||||
.sort()
|
||||
.map(keystr => new BindingsCompletionOption(
|
||||
options + keystr + " " + bindings[keystr], {
|
||||
.map(
|
||||
keystr =>
|
||||
new BindingsCompletionOption(
|
||||
options + keystr + " " + bindings[keystr],
|
||||
{
|
||||
name: keystr,
|
||||
value: JSON.stringify(bindings[keystr]),
|
||||
mode: `${configName} (${modeName})`,
|
||||
}))
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
return this.updateChain()
|
||||
}
|
||||
|
@ -137,6 +151,4 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
// Call concrete class
|
||||
return this.updateDisplay()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -70,10 +70,15 @@ class ScrollingData {
|
|||
const elapsed: number = performance.now() - this.startTime
|
||||
|
||||
// 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
|
||||
|
||||
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) {
|
||||
// We need to ceil() because only highdpi screens have a decimal this.elem[this.pos]
|
||||
pixelToScrollTo = Math.ceil(pixelToScrollTo)
|
||||
|
@ -104,7 +109,6 @@ class ScrollingData {
|
|||
this.scrollStep() ? this.scheduleStep() : (this.scrolling = false),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Stores elements that are currently being horizontally scrolled
|
||||
|
@ -116,8 +120,8 @@ const verticallyScrolling = new Map<Node, ScrollingData>()
|
|||
* last duration milliseconds
|
||||
*/
|
||||
export async function scroll(
|
||||
xDistance: number = 0,
|
||||
yDistance: number = 0,
|
||||
xDistance = 0,
|
||||
yDistance = 0,
|
||||
e: Node,
|
||||
duration?: number,
|
||||
): Promise<boolean> {
|
||||
|
@ -189,15 +193,15 @@ export async function recursiveScroll(
|
|||
startingFromCached = true
|
||||
node = lastRecursiveScrolled
|
||||
} else {
|
||||
|
||||
// Try scrolling the active node or one of its parent elements
|
||||
|
||||
// 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
|
||||
while (true) {
|
||||
if ((await scroll(xDistance, yDistance, node))) return true
|
||||
if (await scroll(xDistance, yDistance, node)) return true
|
||||
node = node.parentElement
|
||||
if (!node) break
|
||||
}
|
||||
|
@ -215,7 +219,9 @@ export async function recursiveScroll(
|
|||
if (
|
||||
(await scroll(xDistance, yDistance, treeWalker.currentNode)) ||
|
||||
((treeWalker.currentNode as any).contentDocument &&
|
||||
!(treeWalker.currentNode as any).src.startsWith("moz-extension://") &&
|
||||
!(treeWalker.currentNode as any).src.startsWith(
|
||||
"moz-extension://",
|
||||
) &&
|
||||
(await recursiveScroll(
|
||||
xDistance,
|
||||
yDistance,
|
||||
|
|
|
@ -19,10 +19,14 @@ export class PrevInput {
|
|||
|
||||
class ContentState {
|
||||
mode: ModeName = "normal"
|
||||
suffix: string = ""
|
||||
suffix = ""
|
||||
}
|
||||
|
||||
export type ContentStateProperty = "mode" | "cmdHistory" | "prevInputs" | "suffix"
|
||||
export type ContentStateProperty =
|
||||
| "mode"
|
||||
| "cmdHistory"
|
||||
| "prevInputs"
|
||||
| "suffix"
|
||||
|
||||
export type ContentStateChangedCallback = (
|
||||
property: ContentStateProperty,
|
||||
|
|
|
@ -1031,7 +1031,7 @@ export class default_config {
|
|||
* statistics, so somewhere around 10k samples.
|
||||
*
|
||||
*/
|
||||
perfsamples: string = "10000"
|
||||
perfsamples = "10000"
|
||||
|
||||
/**
|
||||
* Show (partial) command in the mode indicator.
|
||||
|
|
|
@ -144,12 +144,7 @@ export async function exists(cname: string): Promise<boolean> {
|
|||
@param color
|
||||
@param icon
|
||||
*/
|
||||
export function fromString(
|
||||
name: string,
|
||||
color: string,
|
||||
icon: string,
|
||||
id: string = "",
|
||||
) {
|
||||
export function fromString(name: string, color: string, icon: string, id = "") {
|
||||
return {
|
||||
name,
|
||||
color: color as browser.contextualIdentities.IdentityColor,
|
||||
|
|
|
@ -278,13 +278,13 @@ export function wordAfterPos(text: string, position: number) {
|
|||
/** @hidden
|
||||
* 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("")
|
||||
sa = sa.map(x => charesar(x, n))
|
||||
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)
|
||||
if (cn >= 65 && cn <= 90)
|
||||
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
|
||||
`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"
|
||||
modeState = new NModeState()
|
||||
modeState.endCommand = endCommand
|
||||
|
@ -40,10 +40,13 @@ export function parser(keys: KeyboardEvent[]) {
|
|||
}
|
||||
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) {
|
||||
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
|
||||
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
|
||||
// bytes per sample instead of 130 @_@
|
||||
public buffer: PerformanceEntry[] = []
|
||||
private idx: number = 0
|
||||
private buffersize: number = 10000
|
||||
private lastError: number = 0
|
||||
private idx = 0
|
||||
private buffersize = 10000
|
||||
private lastError = 0
|
||||
|
||||
/**
|
||||
* Target for receiving stats entries from other threads - there
|
||||
|
@ -301,8 +301,8 @@ export class StatsLogger {
|
|||
*/
|
||||
export function renderStatsHistogram(
|
||||
samples: PerformanceEntry[],
|
||||
buckets: number = 15,
|
||||
width: number = 80,
|
||||
buckets = 15,
|
||||
width = 80,
|
||||
): string {
|
||||
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 {
|
||||
return performance.mark !== undefined
|
||||
|
|
26
src/state.ts
26
src/state.ts
|
@ -12,7 +12,7 @@
|
|||
|
||||
import Logger from "@src/lib/logging"
|
||||
import * as messaging from "@src/lib/messaging"
|
||||
import {notBackground} from "@src/lib/webext"
|
||||
import { notBackground } from "@src/lib/webext"
|
||||
|
||||
const logger = new Logger("state")
|
||||
|
||||
|
@ -26,7 +26,7 @@ class State {
|
|||
jumppos: undefined,
|
||||
},
|
||||
]
|
||||
last_ex_str: string = "echo"
|
||||
last_ex_str = "echo"
|
||||
}
|
||||
|
||||
// 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))
|
||||
|
||||
const state = (new Proxy(overlay, {
|
||||
const state = new Proxy(overlay, {
|
||||
/** Give defaults if overlay doesn't have the key */
|
||||
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) {
|
||||
return target[property]
|
||||
} else {
|
||||
|
@ -61,7 +62,11 @@ const state = (new Proxy(overlay, {
|
|||
|
||||
logger.debug("State changed!", property, value)
|
||||
if (notBackground()) {
|
||||
browser.runtime.sendMessage({type: "state", command: "stateUpdate", args: {property, value}})
|
||||
browser.runtime.sendMessage({
|
||||
type: "state",
|
||||
command: "stateUpdate",
|
||||
args: { property, value },
|
||||
})
|
||||
return true
|
||||
}
|
||||
// Do we need a global storage lock?
|
||||
|
@ -69,10 +74,15 @@ const state = (new Proxy(overlay, {
|
|||
browser.storage.local.set({ state: target } as any)
|
||||
return true
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
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]
|
||||
}
|
||||
|
||||
|
@ -85,7 +95,7 @@ messaging.addListener("state", (message, sender, sendResponse) => {
|
|||
overlay[property] = value
|
||||
} else if (message.command == "stateGet") {
|
||||
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 }
|
||||
|
|
Loading…
Add table
Reference in a new issue