finding.ts: Make find re-use last search pattern if needed

This commit is contained in:
glacambre 2019-05-29 10:01:53 +02:00
parent d221ee6585
commit 96cc6f6100
No known key found for this signature in database
GPG key ID: B9625DB1767553AC
3 changed files with 4 additions and 3 deletions

View file

@ -1,6 +1,7 @@
import * as config from "@src/lib/config"
import * as DOM from "@src/lib/dom"
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
// 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
const findcase = config.get("findcase")
const sensitive = findcase === "sensitive" || (findcase === "smart" && searchQuery.match("[A-Z]"))
state.lastSearchQuery = searchQuery
const results = await browserBg.find.find(searchQuery, {
tabId: await activeTabId(),
caseSensitive: sensitive,
@ -102,7 +104,7 @@ function drawHighlights(highlights) {
export function jumpToNextMatch(n: number) {
if (!lastHighlights) {
return
return state.lastSearchQuery ? jumpToMatch(state.lastSearchQuery, n < 0) : undefined
}
if (!host.firstChild) {
drawHighlights(lastHighlights)

View file

@ -999,7 +999,6 @@ export function find(...args: string[]) {
if (reverse) args.splice(flagpos, 1)
const searchQuery = args.join(" ")
state.lastSearch = searchQuery
return finding.jumpToMatch(searchQuery, reverse)
}

View file

@ -18,7 +18,7 @@ import Logger from "@src/lib/logging"
const logger = new Logger("state")
class State {
lastSearch: string = undefined
lastSearchQuery: string = undefined
cmdHistory: string[] = []
prevInputs: Array<{ inputId: string; tab: number; jumppos?: number }> = [
{