mirror of
https://github.com/tridactyl/tridactyl.git
synced 2026-09-10 07:16:33 -04:00
Re-enable prefer-regexp-exec
This commit is contained in:
parent
ff5c0d7323
commit
d5192f6dac
|
|
@ -129,7 +129,7 @@ module.exports = {
|
|||
"@typescript-eslint/prefer-for-of": "error",
|
||||
"@typescript-eslint/prefer-function-type": "error",
|
||||
"@typescript-eslint/prefer-namespace-keyword": "error",
|
||||
"@typescript-eslint/prefer-regexp-exec": "off", //"error",
|
||||
"@typescript-eslint/prefer-regexp-exec": "error",
|
||||
"@typescript-eslint/quotes": [
|
||||
"error",
|
||||
"double",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import * as omnibox from "@src/background/omnibox"
|
|||
import * as R from "ramda"
|
||||
|
||||
// Add various useful modules to the window for debugging
|
||||
; (window as any).tri = Object.assign(Object.create(null), {
|
||||
;(window as any).tri = Object.assign(Object.create(null), {
|
||||
messaging,
|
||||
excmds: excmds_background,
|
||||
convert,
|
||||
|
|
@ -54,9 +54,9 @@ import { HintingCmds } from "@src/background/hinting"
|
|||
// here.
|
||||
controller.setExCmds({
|
||||
"": excmds_background,
|
||||
"ex": CmdlineCmds,
|
||||
"text": EditorCmds,
|
||||
"hint": HintingCmds
|
||||
ex: CmdlineCmds,
|
||||
text: EditorCmds,
|
||||
hint: HintingCmds,
|
||||
})
|
||||
|
||||
// {{{ tri.contentLocation
|
||||
|
|
@ -78,13 +78,11 @@ browser.tabs.onActivated.addListener(ev => {
|
|||
})
|
||||
})
|
||||
// Update on navigation too (but remember that sometimes people open tabs in the background :) )
|
||||
browser.webNavigation.onDOMContentLoaded.addListener(
|
||||
() => {
|
||||
browser.tabs.query({ currentWindow: true, active: true }).then(t => {
|
||||
(window as any).tri.contentLocation = new URL(t[0].url)
|
||||
})
|
||||
},
|
||||
)
|
||||
browser.webNavigation.onDOMContentLoaded.addListener(() => {
|
||||
browser.tabs.query({ currentWindow: true, active: true }).then(t => {
|
||||
(window as any).tri.contentLocation = new URL(t[0].url)
|
||||
})
|
||||
})
|
||||
|
||||
// Prevent Tridactyl from being updated while it is running in the hope of fixing #290
|
||||
browser.runtime.onUpdateAvailable.addListener(_ => undefined)
|
||||
|
|
@ -98,7 +96,7 @@ browser.runtime.onStartup.addListener(_ => {
|
|||
} else {
|
||||
native.run("hostname").then(hostname => {
|
||||
for (const host of hosts) {
|
||||
if (hostname.content.match(host)) {
|
||||
if (new RegExp(host).exec(hostname.content)) {
|
||||
controller.acceptExCmd(aucmds[host])
|
||||
}
|
||||
}
|
||||
|
|
@ -164,9 +162,7 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
["blocking"],
|
||||
)
|
||||
|
||||
browser.tabs.onCreated.addListener(
|
||||
aucon.tabCreatedListener,
|
||||
)
|
||||
browser.tabs.onCreated.addListener(aucon.tabCreatedListener)
|
||||
|
||||
// }}}
|
||||
|
||||
|
|
@ -182,7 +178,7 @@ const messages = {
|
|||
downloadUrl: download_background.downloadUrl,
|
||||
downloadUrlAs: download_background.downloadUrlAs,
|
||||
},
|
||||
browser_proxy_background: {shim: proxy_background.shim}
|
||||
browser_proxy_background: { shim: proxy_background.shim },
|
||||
}
|
||||
export type Messages = typeof messages
|
||||
|
||||
|
|
@ -211,6 +207,6 @@ omnibox.init()
|
|||
|
||||
// {{{ Obey Mozilla's orders https://github.com/tridactyl/tridactyl/issues/1800
|
||||
|
||||
native.unfixamo();
|
||||
native.unfixamo()
|
||||
|
||||
/// }}}
|
||||
|
|
|
|||
|
|
@ -38,18 +38,17 @@ class BufferCompletionOption extends Completions.CompletionOptionHTML
|
|||
const favIconUrl = tab.favIconUrl
|
||||
? tab.favIconUrl
|
||||
: Completions.DEFAULT_FAVICON
|
||||
this.html = html`<tr class="BufferCompletionOption option container_${container.color} container_${container.icon} container_${container.name}"
|
||||
>
|
||||
<td class="prefix">${pre.padEnd(2)}</td>
|
||||
<td class="container"></td>
|
||||
<td class="icon"><img src="${favIconUrl}" /></td>
|
||||
<td class="title">${tab.index + 1}: ${tab.title}</td>
|
||||
<td class="content">
|
||||
<a class="url" target="_blank" href=${tab.url}
|
||||
>${tab.url}</a
|
||||
>
|
||||
</td>
|
||||
</tr>`
|
||||
this.html = html`<tr
|
||||
class="BufferCompletionOption option container_${container.color} container_${container.icon} container_${container.name}"
|
||||
>
|
||||
<td class="prefix">${pre.padEnd(2)}</td>
|
||||
<td class="container"></td>
|
||||
<td class="icon"><img src="${favIconUrl}" /></td>
|
||||
<td class="title">${tab.index + 1}: ${tab.title}</td>
|
||||
<td class="content">
|
||||
<a class="url" target="_blank" href=${tab.url}>${tab.url}</a>
|
||||
</td>
|
||||
</tr>`
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -126,15 +125,17 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
/** Return the scoredOption[] result for the nth tab */
|
||||
private nthTabscoredOptions(
|
||||
n: number,
|
||||
options: BufferCompletionOption[]
|
||||
options: BufferCompletionOption[],
|
||||
): Completions.ScoredOption[] {
|
||||
for (const [index, option] of enumerate(options)) {
|
||||
if (option.tabIndex === n) {
|
||||
return [{
|
||||
index,
|
||||
option,
|
||||
score: 0,
|
||||
}, ]
|
||||
return [
|
||||
{
|
||||
index,
|
||||
option,
|
||||
score: 0,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -142,10 +143,10 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
/** Return the scoredOption[] result for the tab index startswith n */
|
||||
private TabscoredOptionsStartsWithN(
|
||||
n: number,
|
||||
options: BufferCompletionOption[]
|
||||
options: BufferCompletionOption[],
|
||||
): Completions.ScoredOption[] {
|
||||
const nstr = (n + 1).toString()
|
||||
const res = [];
|
||||
const res = []
|
||||
for (const [index, option] of enumerate(options)) {
|
||||
if ((option.tabIndex + 1).toString().startsWith(nstr)) {
|
||||
res.push({
|
||||
|
|
@ -158,7 +159,7 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
// old input will change order: 12 => 123 => 12
|
||||
res.sort((a, b) => a.option.tabIndex - b.option.tabIndex)
|
||||
return res;
|
||||
return res
|
||||
}
|
||||
|
||||
private async fillOptions() {
|
||||
|
|
@ -167,17 +168,19 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
})
|
||||
const options = []
|
||||
// Get alternative tab, defined as last accessed tab.
|
||||
tabs.sort((a, b) => (b.lastAccessed - a.lastAccessed))
|
||||
tabs.sort((a, b) => b.lastAccessed - a.lastAccessed)
|
||||
const alt = tabs[1]
|
||||
|
||||
const useMruTabOrder = (config.get("tabsort") === "mru")
|
||||
const useMruTabOrder = config.get("tabsort") === "mru"
|
||||
if (!useMruTabOrder) {
|
||||
tabs.sort((a, b) => (a.index - b.index))
|
||||
tabs.sort((a, b) => a.index - b.index)
|
||||
}
|
||||
|
||||
const container_all = await browserBg.contextualIdentities.query({})
|
||||
const container_map = new Map()
|
||||
container_all.forEach(elem => container_map.set(elem.cookieStoreId, elem))
|
||||
container_all.forEach(elem =>
|
||||
container_map.set(elem.cookieStoreId, elem),
|
||||
)
|
||||
// firefox-default is not in contextualIdenetities
|
||||
container_map.set("firefox-default", Containers.DefaultContainer)
|
||||
|
||||
|
|
@ -191,7 +194,7 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
(tab.index + 1).toString(),
|
||||
tab,
|
||||
tab === alt,
|
||||
tab_container
|
||||
tab_container,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -219,7 +222,7 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
// When the user is asking for tabmove completions, don't autoselect if the query looks like a relative move https://github.com/tridactyl/tridactyl/issues/825
|
||||
this.shouldSetStateFromScore = !(
|
||||
prefix === "tabmove " && query.match("^[+-][0-9]+$")
|
||||
prefix === "tabmove " && /^[+-][0-9]+$/.exec(query)
|
||||
)
|
||||
|
||||
if (!this.options) {
|
||||
|
|
|
|||
|
|
@ -1019,7 +1019,7 @@ export async function scrollpx(a: number, b: number) {
|
|||
*/
|
||||
//#content
|
||||
export function scrollto(a: number | string, b: number | "x" | "y" = "y") {
|
||||
if (typeof a === "string" && a.match(/c$/i)) {
|
||||
if (typeof a === "string" && /c$/i.exec(a)) {
|
||||
a = (Number(a.replace(/c$/, "")) * 100) / (2 * Math.PI)
|
||||
}
|
||||
a = Number(a)
|
||||
|
|
@ -1199,10 +1199,10 @@ export async function open(...urlarr: string[]) {
|
|||
const url = urlarr.join(" ")
|
||||
|
||||
// Setting window.location to about:blank results in a page we can't access, tabs.update works.
|
||||
if (!ABOUT_WHITELIST.includes(url) && url.match(/^(about|file):.*/)) {
|
||||
if (!ABOUT_WHITELIST.includes(url) && /^(about|file):.*/.exec(url)) {
|
||||
// Open URLs that firefox won't let us by running `firefox <URL>` on the command line
|
||||
return nativeopen(url)
|
||||
} else if (url.match(/^javascript:/)) {
|
||||
} else if (/^javascript:/.exec(url)) {
|
||||
const bookmarklet = url.replace(/^javascript:/, "")
|
||||
document.body.append(
|
||||
html`
|
||||
|
|
@ -1236,7 +1236,7 @@ export async function bmarks(opt: string, ...urlarr: string[]) {
|
|||
export async function open_quiet(...urlarr: string[]) {
|
||||
const url = urlarr.join(" ")
|
||||
|
||||
if (!ABOUT_WHITELIST.includes(url) && url.match(/^(about|file):.*/)) {
|
||||
if (!ABOUT_WHITELIST.includes(url) && /^(about|file):.*/.exec(url)) {
|
||||
return nativeopen(url)
|
||||
}
|
||||
|
||||
|
|
@ -2134,7 +2134,7 @@ export async function tabopen(...addressarr: string[]) {
|
|||
const query = await argParse(addressarr)
|
||||
|
||||
const address = query.join(" ")
|
||||
if (!ABOUT_WHITELIST.includes(address) && address.match(/^(about|file):.*/)) {
|
||||
if (!ABOUT_WHITELIST.includes(address) && /^(about|file):.*/.exec(address)) {
|
||||
return nativeopen(address)
|
||||
}
|
||||
|
||||
|
|
@ -2579,7 +2579,7 @@ export async function winopen(...args: string[]) {
|
|||
}
|
||||
|
||||
const address = args.join(" ")
|
||||
if (!ABOUT_WHITELIST.includes(address) && address.match(/^(about|file):.*/)) {
|
||||
if (!ABOUT_WHITELIST.includes(address) && /^(about|file):.*/.exec(address)) {
|
||||
return nativeopen(firefoxArgs, address)
|
||||
}
|
||||
|
||||
|
|
@ -3099,7 +3099,7 @@ export async function tab(index: number | "#") {
|
|||
//#background
|
||||
export async function taball(id: string) {
|
||||
const windows = (await browser.windows.getAll()).map(w => w.id).sort((a, b) => a - b)
|
||||
if (id === null || id === undefined || !id.match(/\d+\.\d+/)) {
|
||||
if (id === null || id === undefined || /\d+\.\d+/.exec(id)) {
|
||||
const tab = await activeTab()
|
||||
const prevId = id
|
||||
id = windows.indexOf(tab.windowId) + "." + (tab.index + 1)
|
||||
|
|
@ -3567,7 +3567,7 @@ export async function sanitise(...args: string[]) {
|
|||
// If the -t flag has been given and there is an arg after it
|
||||
if (flagpos > -1) {
|
||||
if (flagpos < args.length - 1) {
|
||||
const match = args[flagpos + 1].match("^([0-9])+(m|h|d|w)$")
|
||||
const match = /^([0-9])+(m|h|d|w)$/.exec(args[flagpos + 1])
|
||||
// If the arg of the flag matches Pentadactyl's sanitisetimespan format
|
||||
if (match !== null && match.length === 3) {
|
||||
// Compute the timespan in milliseconds and get a Date object
|
||||
|
|
|
|||
|
|
@ -120,10 +120,7 @@ export function mouseEvent(
|
|||
}
|
||||
|
||||
export function elementsWithText() {
|
||||
return getElemsBySelector("*", [
|
||||
isVisible,
|
||||
hint => hint.textContent !== "",
|
||||
])
|
||||
return getElemsBySelector("*", [isVisible, hint => hint.textContent !== ""])
|
||||
}
|
||||
|
||||
/** Iterable of elements that match xpath.
|
||||
|
|
@ -304,7 +301,7 @@ export function getAllDocumentFrames(doc = document) {
|
|||
export function getSelector(e: HTMLElement) {
|
||||
function uniqueSelector(e: HTMLElement) {
|
||||
// Only matching alphanumeric selectors because others chars might have special meaning in CSS
|
||||
if (e.id && e.id.match("^[a-zA-Z0-9]+$")) return "#" + e.id
|
||||
if (e.id && /^[a-zA-Z0-9]+$/.exec(e.id)) return "#" + e.id
|
||||
// If we reached the top of the document
|
||||
if (!e.parentElement) return "HTML"
|
||||
// Compute the position of the element
|
||||
|
|
@ -537,7 +534,10 @@ function onPageFocus(elem: HTMLElement, args: any[]): boolean {
|
|||
async function setInput(el) {
|
||||
const tab = await activeTabId()
|
||||
// store maximum of 10 elements to stop this getting bonkers huge
|
||||
const arr = (await State.getAsync("prevInputs")).concat({ tab, inputId: el.id })
|
||||
const arr = (await State.getAsync("prevInputs")).concat({
|
||||
tab,
|
||||
inputId: el.id,
|
||||
})
|
||||
state.prevInputs = arr.slice(Math.max(arr.length - 10, 0))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
// We have a single dependency on config: getting the value of the WORDPATTERN setting
|
||||
// Perhaps we could find a way to get rid of it?
|
||||
import * as config from "@src/lib/config"
|
||||
|
|
@ -165,7 +164,11 @@ export function needs_text(fn: editor_function, arg?: any): editor_function {
|
|||
/**
|
||||
* Returns line and column number.
|
||||
*/
|
||||
export function getLineAndColNumber(text: string, start: number, end: number): [string, number, number] {
|
||||
export function getLineAndColNumber(
|
||||
text: string,
|
||||
start: number,
|
||||
end: number,
|
||||
): [string, number, number] {
|
||||
const lines = text.split("\n")
|
||||
let totalChars = 0
|
||||
for (let i = 0; i < lines.length; ++i) {
|
||||
|
|
@ -188,21 +191,18 @@ export function getWordBoundaries(
|
|||
): [number, number] {
|
||||
if (position < 0 || position > text.length)
|
||||
throw new Error(
|
||||
`getWordBoundaries: position (${position}) should be within text ("${text}") boundaries (0, ${
|
||||
text.length
|
||||
})`,
|
||||
`getWordBoundaries: position (${position}) should be within text ("${text}") boundaries (0, ${text.length})`,
|
||||
)
|
||||
const pattern = new RegExp(config.get("wordpattern"), "g")
|
||||
let boundary1 = position < text.length ? position : text.length - 1
|
||||
const direction = before ? -1 : 1
|
||||
// if the caret is not in a word, try to find the word before or after it
|
||||
// For `before`, we should check the char before the caret
|
||||
if (before && boundary1 > 0)
|
||||
boundary1 -= 1
|
||||
if (before && boundary1 > 0) boundary1 -= 1
|
||||
while (
|
||||
boundary1 >= 0 &&
|
||||
boundary1 < text.length &&
|
||||
!text[boundary1].match(pattern)
|
||||
!pattern.exec(text[boundary1])
|
||||
) {
|
||||
boundary1 += direction
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ export function getWordBoundaries(
|
|||
while (
|
||||
boundary1 >= 0 &&
|
||||
boundary1 < text.length &&
|
||||
!text[boundary1].match(pattern)
|
||||
!pattern.exec(text[boundary1])
|
||||
) {
|
||||
boundary1 -= direction
|
||||
}
|
||||
|
|
@ -222,12 +222,10 @@ export function getWordBoundaries(
|
|||
if (boundary1 < 0) boundary1 = 0
|
||||
else if (boundary1 >= text.length) boundary1 = text.length - 1
|
||||
|
||||
if (!text[boundary1].match(pattern)) {
|
||||
if (!pattern.exec(text[boundary1])) {
|
||||
// there is no word in text
|
||||
throw new Error(
|
||||
`getWordBoundaries: no characters matching wordpattern (${
|
||||
pattern.source
|
||||
}) in text (${text})`,
|
||||
`getWordBoundaries: no characters matching wordpattern (${pattern.source}) in text (${text})`,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +233,7 @@ export function getWordBoundaries(
|
|||
while (
|
||||
boundary1 >= 0 &&
|
||||
boundary1 < text.length &&
|
||||
!!text[boundary1].match(pattern)
|
||||
!!pattern.exec(text[boundary1])
|
||||
) {
|
||||
boundary1 += direction
|
||||
}
|
||||
|
|
@ -247,7 +245,7 @@ export function getWordBoundaries(
|
|||
while (
|
||||
boundary2 >= 0 &&
|
||||
boundary2 < text.length &&
|
||||
!!text[boundary2].match(pattern)
|
||||
!!pattern.exec(text[boundary2])
|
||||
) {
|
||||
boundary2 -= direction
|
||||
}
|
||||
|
|
@ -268,10 +266,10 @@ export function wordAfterPos(text: string, position: number) {
|
|||
throw new Error(`wordAfterPos: position (${position}) is less that 0`)
|
||||
const pattern = new RegExp(config.get("wordpattern"), "g")
|
||||
// move position out of the current word
|
||||
while (position < text.length && !!text[position].match(pattern))
|
||||
while (position < text.length && !!pattern.exec(text[position]))
|
||||
position += 1
|
||||
// try to find characters that match wordpattern
|
||||
while (position < text.length && !text[position].match(pattern))
|
||||
while (position < text.length && !pattern.exec(text[position]))
|
||||
position += 1
|
||||
if (position >= text.length) return -1
|
||||
return position
|
||||
|
|
@ -289,8 +287,8 @@ export const rot13_helper = (s: string, n: number = 13): string => {
|
|||
export const charesar = (c: string, n: number = 13): string => {
|
||||
const cn = c.charCodeAt(0)
|
||||
if (cn >= 65 && cn <= 90)
|
||||
return String.fromCharCode((((cn - 65) + n) % 26) + 65)
|
||||
return String.fromCharCode(((cn - 65 + n) % 26) + 65)
|
||||
if (cn >= 97 && cn <= 122)
|
||||
return String.fromCharCode((((cn - 97) + n) % 26) + 97)
|
||||
return String.fromCharCode(((cn - 97 + n) % 26) + 97)
|
||||
return c
|
||||
}
|
||||
|
|
|
|||
|
|
@ -426,12 +426,12 @@ export async function parseProfilesIni(content: string, basePath: string) {
|
|||
let current = "General"
|
||||
const result = {}
|
||||
for (const line of lines) {
|
||||
let match = line.match(/^\[([^\]]+)\]$/)
|
||||
let match = /^\[([^\]]+)\]$/.exec(line)
|
||||
if (match !== null) {
|
||||
current = match[1]
|
||||
result[current] = {}
|
||||
} else {
|
||||
match = line.match(/^([^=]+)=([^=]+)$/)
|
||||
match = /^([^=]+)=([^=]+)$/.exec(line)
|
||||
if (match !== null) {
|
||||
result[current][match[1]] = match[2]
|
||||
}
|
||||
|
|
@ -635,7 +635,7 @@ export function parsePrefs(prefFileContent: string) {
|
|||
)
|
||||
// Fragile parsing
|
||||
return prefFileContent.split("\n").reduce((prefs, line) => {
|
||||
const matches = line.match(regex)
|
||||
const matches = regex.exec(line)
|
||||
if (!matches) {
|
||||
return prefs
|
||||
}
|
||||
|
|
|
|||
|
|
@ -278,7 +278,6 @@ export class StatsLogger {
|
|||
private incrementIdx() {
|
||||
this.idx = (this.idx + 1) % this.buffersize
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -388,7 +387,7 @@ const extractRegExp = new RegExp(
|
|||
// sample itself.
|
||||
)
|
||||
function extractMetricName(counterName: string): MetricNameInfo {
|
||||
const matchresult = counterName.match(extractRegExp)
|
||||
const matchresult = extractRegExp.exec(counterName)
|
||||
if (!matchresult) return
|
||||
const [ownerName, functionName, uniqueSuffix] = matchresult.slice(1)
|
||||
|
||||
|
|
@ -416,5 +415,9 @@ class MetricName {
|
|||
}
|
||||
|
||||
function sendStats(list: PerformanceEntryList) {
|
||||
messaging.message("performance_background", "receiveStatsJson", JSON.stringify(list))
|
||||
messaging.message(
|
||||
"performance_background",
|
||||
"receiveStatsJson",
|
||||
JSON.stringify(list),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue