From 96cc6f6100a568b2e7e23d4d9926f055882aa255 Mon Sep 17 00:00:00 2001 From: glacambre Date: Wed, 29 May 2019 10:01:53 +0200 Subject: [PATCH] finding.ts: Make find re-use last search pattern if needed --- src/content/finding.ts | 4 +++- src/excmds.ts | 1 - src/state.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/content/finding.ts b/src/content/finding.ts index 5c1987c7..950a601a 100644 --- a/src/content/finding.ts +++ b/src/content/finding.ts @@ -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) diff --git a/src/excmds.ts b/src/excmds.ts index 0ee37154..6c524fbf 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -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) } diff --git a/src/state.ts b/src/state.ts index 5c4d4df2..a97e48f6 100644 --- a/src/state.ts +++ b/src/state.ts @@ -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 }> = [ {