mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 17:41:40 -05:00
finding.ts: Make find re-use last search pattern if needed
This commit is contained in:
parent
d221ee6585
commit
96cc6f6100
3 changed files with 4 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
import * as config from "@src/lib/config"
|
import * as config from "@src/lib/config"
|
||||||
import * as DOM from "@src/lib/dom"
|
import * as DOM from "@src/lib/dom"
|
||||||
import { browserBg, activeTabId } from "@src/lib/webext"
|
import { browserBg, activeTabId } from "@src/lib/webext"
|
||||||
|
import state from "@src/state"
|
||||||
|
|
||||||
// The host is the shadow root of a span used to contain all highlighting
|
// The host is the shadow root of a span used to contain all highlighting
|
||||||
// elements. This is the least disruptive way of highlighting text in a page.
|
// elements. This is the least disruptive way of highlighting text in a page.
|
||||||
|
@ -55,6 +56,7 @@ export async function jumpToMatch(searchQuery, reverse) {
|
||||||
// First, search for the query
|
// First, search for the query
|
||||||
const findcase = config.get("findcase")
|
const findcase = config.get("findcase")
|
||||||
const sensitive = findcase === "sensitive" || (findcase === "smart" && searchQuery.match("[A-Z]"))
|
const sensitive = findcase === "sensitive" || (findcase === "smart" && searchQuery.match("[A-Z]"))
|
||||||
|
state.lastSearchQuery = searchQuery
|
||||||
const results = await browserBg.find.find(searchQuery, {
|
const results = await browserBg.find.find(searchQuery, {
|
||||||
tabId: await activeTabId(),
|
tabId: await activeTabId(),
|
||||||
caseSensitive: sensitive,
|
caseSensitive: sensitive,
|
||||||
|
@ -102,7 +104,7 @@ function drawHighlights(highlights) {
|
||||||
|
|
||||||
export function jumpToNextMatch(n: number) {
|
export function jumpToNextMatch(n: number) {
|
||||||
if (!lastHighlights) {
|
if (!lastHighlights) {
|
||||||
return
|
return state.lastSearchQuery ? jumpToMatch(state.lastSearchQuery, n < 0) : undefined
|
||||||
}
|
}
|
||||||
if (!host.firstChild) {
|
if (!host.firstChild) {
|
||||||
drawHighlights(lastHighlights)
|
drawHighlights(lastHighlights)
|
||||||
|
|
|
@ -999,7 +999,6 @@ export function find(...args: string[]) {
|
||||||
if (reverse) args.splice(flagpos, 1)
|
if (reverse) args.splice(flagpos, 1)
|
||||||
|
|
||||||
const searchQuery = args.join(" ")
|
const searchQuery = args.join(" ")
|
||||||
state.lastSearch = searchQuery
|
|
||||||
return finding.jumpToMatch(searchQuery, reverse)
|
return finding.jumpToMatch(searchQuery, reverse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import Logger from "@src/lib/logging"
|
||||||
const logger = new Logger("state")
|
const logger = new Logger("state")
|
||||||
|
|
||||||
class State {
|
class State {
|
||||||
lastSearch: string = undefined
|
lastSearchQuery: string = undefined
|
||||||
cmdHistory: string[] = []
|
cmdHistory: string[] = []
|
||||||
prevInputs: Array<{ inputId: string; tab: number; jumppos?: number }> = [
|
prevInputs: Array<{ inputId: string; tab: number; jumppos?: number }> = [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue