diff --git a/src/lib/searchHistory.js b/src/lib/searchHistory.js index 5adb63431..a4174b822 100644 --- a/src/lib/searchHistory.js +++ b/src/lib/searchHistory.js @@ -44,19 +44,22 @@ class SearchHistory { /** * Add item to history * @param {string} item Item to add + * @param {object} [options] + * @param {boolean} [options.preserveWhitespace=false] Keep leading and trailing whitespace */ - addToHistory(item) { - if (!item || typeof item !== "string" || item.trim().length === 0) { + addToHistory(item, { preserveWhitespace = false } = {}) { + if (typeof item !== "string") { return; } - const trimmedItem = item.trim(); + const historyItem = preserveWhitespace ? item : item.trim(); + if (!historyItem.length) return; // Remove existing item if present - this.history = this.history.filter((h) => h !== trimmedItem); + this.history = this.history.filter((h) => h !== historyItem); // Add to beginning - this.history.unshift(trimmedItem); + this.history.unshift(historyItem); // Limit history size this.history = this.history.slice(0, MAX_HISTORY_ITEMS); diff --git a/src/sidebarApps/searchInFiles/index.js b/src/sidebarApps/searchInFiles/index.js index 35ef095b0..0fc6c42bc 100644 --- a/src/sidebarApps/searchInFiles/index.js +++ b/src/sidebarApps/searchInFiles/index.js @@ -4,6 +4,7 @@ import autosize from "autosize"; import { getDocText } from "cm/editorUtils"; import Checkbox from "components/checkbox"; import Sidebar, { preventSlide } from "components/sidebar"; +import select from "dialogs/select"; import escapeStringRegexp from "escape-string-regexp"; import Reactive from "html-tag-js/reactive"; import Ref from "html-tag-js/ref"; @@ -11,6 +12,7 @@ import fileIndex from "lib/fileIndex"; import files, { Tree, whenReady as waitForFileList } from "lib/fileList"; import openFile from "lib/openFile"; import { addedFolder } from "lib/openFolder"; +import searchHistory from "lib/searchHistory"; import settings from "lib/settings"; import helpers from "utils/helpers"; import { createSearchResultView } from "./cmResultView"; @@ -35,6 +37,8 @@ const $include = Ref(); const $wholeWord = Ref(); const $caseSensitive = Ref(); const $useIndex = Ref(); +const $btnSearchHistory = Ref(); +const $btnReplaceHistory = Ref(); const $btnReplaceAll = Ref(); const $resultOverview = Ref(); const $resultHeader = Ref(); @@ -128,6 +132,7 @@ let pendingNativeSearchFinishVersion = null; let nativeSearchId = null; let activeSearchTasks = 0; let activeReplaceTasks = 0; +let applyingHistoryPattern = false; addEventListener($regExp, "change", onInput); addEventListener($wholeWord, "change", onInput); @@ -136,6 +141,12 @@ addEventListener($useIndex, "change", onInput); addEventListener($search, "input", onInput); addEventListener($include, "input", onInput); addEventListener($exclude, "input", onInput); +addEventListener($btnSearchHistory, "click", () => + openPatternHistory($search, strings["search"]), +); +addEventListener($btnReplaceHistory, "click", () => + openPatternHistory($replace, strings["replace"]), +); addEventListener($btnReplaceAll, "click", replaceAll); files.on("push-file", () => { @@ -257,7 +268,16 @@ export default [ type="search" name="search" placeholder={strings["search"]} + onchange={rememberSearchPattern} + oninput={onSearchPatternInput} + onkeydown={onSearchHistoryKeydown} /> +
@@ -266,7 +286,16 @@ export default [ type="search" name="replace" placeholder={strings["replace"]} + onchange={rememberReplacePattern} + oninput={onReplacePatternInput} + onkeydown={onReplaceHistoryKeydown} /> +