From 3c1346e213a9635f56f92b23066ea0638319de25 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 27 Apr 2023 07:37:43 +0200 Subject: [PATCH 01/13] Add a regexp option to search configuration FEATURE: The new `regexp` option to `search` can be used to control whether queries have the regexp flag on by default. See https://discuss.codemirror.net/t/regexp-missing-in-default-searchconfig-search-ts/6374 --- src/search.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/search.ts b/src/search.ts index 91260c7..22e127d 100644 --- a/src/search.ts +++ b/src/search.ts @@ -29,6 +29,10 @@ interface SearchConfig { /// Defaults to false. wholeWord?: boolean + /// Used to turn on regular expression search in the default query. + /// Defaults to false. + regexp?: boolean + /// Can be used to override the way the search panel is implemented. /// Should create a [Panel](#view.Panel) that contains a form /// which lets the user: @@ -59,6 +63,7 @@ const searchConfigFacet: Facet> = Facet.def top: false, caseSensitive: false, literal: false, + regexp: false, wholeWord: false, createPanel: view => new SearchPanel(view), scrollToMatch: range => EditorView.scrollIntoView(range) @@ -515,6 +520,7 @@ function defaultQuery(state: EditorState, fallback?: SearchQuery) { search: (fallback?.literal ?? config.literal) ? selText : selText.replace(/\n/g, "\\n"), caseSensitive: fallback?.caseSensitive ?? config.caseSensitive, literal: fallback?.literal ?? config.literal, + regexp: fallback?.regexp ?? config.regexp, wholeWord: fallback?.wholeWord ?? config.wholeWord }) } From 9ecdd11b62c02cf4e3f6c012b1b3a67210b2c7a9 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 25 May 2023 12:15:04 +0200 Subject: [PATCH 02/13] Move to @codemirror/buildhelper 1.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a5805c..543fc43 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "crelt": "^1.0.5" }, "devDependencies": { - "@codemirror/buildhelper": "^0.1.5" + "@codemirror/buildhelper": "^1.0.0" }, "repository": { "type": "git", From 388f05bab89ba3f87604041eb2125cb70d053710 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 5 Jun 2023 09:36:51 +0200 Subject: [PATCH 03/13] Mark version 6.5.0 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ab7907..6bb0482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.5.0 (2023-06-05) + +### New features + +The new `regexp` option to `search` can be used to control whether queries have the regexp flag on by default. + ## 6.4.0 (2023-04-25) ### Bug fixes diff --git a/package.json b/package.json index 543fc43..fdb61e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codemirror/search", - "version": "6.4.0", + "version": "6.5.0", "description": "Search functionality for the CodeMirror code editor", "scripts": { "test": "cm-runtests", From ce452167163b7bc18210fcf22b2672ec3275bc76 Mon Sep 17 00:00:00 2001 From: Brady Madden Date: Tue, 18 Jul 2023 12:40:59 -0400 Subject: [PATCH 04/13] Make gotoLine move scroll position to middle FIX: Make `gotoLine` prefer to scroll the target line to the middle of the view. --- src/goto-line.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/goto-line.ts b/src/goto-line.ts index 891d43b..5ab156d 100644 --- a/src/goto-line.ts +++ b/src/goto-line.ts @@ -38,10 +38,10 @@ function createLineDialog(view: EditorView): Panel { line = line * (sign == "-" ? -1 : 1) + startLine.number } let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line))) + let selection = EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length))) view.dispatch({ - effects: dialogEffect.of(false), - selection: EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length))), - scrollIntoView: true + effects: [dialogEffect.of(false), EditorView.scrollIntoView(selection.from, {y: 'center'})], + selection, }) view.focus() } From 7748622fee5d06382decac450740e4bf409db6bd Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 4 Aug 2023 09:19:43 +0200 Subject: [PATCH 05/13] Make SearchCursor ignore matches that match only part of a normalized character FIX: Fix an issue in `SearchCursor` where character normalization could produce nonsensical matches. Closes https://github.com/codemirror/dev/issues/1219 --- src/cursor.ts | 12 +++++++----- test/test-cursor.ts | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cursor.ts b/src/cursor.ts index 54ddefc..97f77dd 100644 --- a/src/cursor.ts +++ b/src/cursor.ts @@ -77,11 +77,13 @@ export class SearchCursor implements Iterator<{from: number, to: number}>{ for (let i = 0, pos = start;; i++) { let code = norm.charCodeAt(i) let match = this.match(code, pos) - if (match) { - this.value = match - return this - } - if (i == norm.length - 1) break + if (i == norm.length - 1) { + if (match) { + this.value = match + return this + } + break + } if (pos == start && i < str.length && str.charCodeAt(i) == code) pos++ } } diff --git a/test/test-cursor.ts b/test/test-cursor.ts index abce812..ee1ffe4 100644 --- a/test/test-cursor.ts +++ b/test/test-cursor.ts @@ -60,6 +60,10 @@ describe("SearchCursor", () => { while (!cursor.nextOverlapping().done) matches.push([cursor.value.from, cursor.value.to]) ist(JSON.stringify(matches), "[[0,4],[2,6],[4,8]]") }) + + it("will not match partial normalized content", () => { + testMatches(new SearchCursor(Text.of(["ยด"]), " "), []) + }) }) describe("RegExpCursor", () => { From 6b30555fbdcdcef977054d42209c6c4be365fa55 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 4 Aug 2023 09:36:38 +0200 Subject: [PATCH 06/13] Mark version 6.5.1 --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bb0482..f0b1b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 6.5.1 (2023-08-04) + +### Bug fixes + +Make `gotoLine` prefer to scroll the target line to the middle of the view. + +Fix an issue in `SearchCursor` where character normalization could produce nonsensical matches. + ## 6.5.0 (2023-06-05) ### New features diff --git a/package.json b/package.json index fdb61e9..2119e41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codemirror/search", - "version": "6.5.0", + "version": "6.5.1", "description": "Search functionality for the CodeMirror code editor", "scripts": { "test": "cm-runtests", From 9dc666b9af542c8e6101ffa54966679cfb8042ee Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sat, 26 Aug 2023 13:00:20 +0200 Subject: [PATCH 07/13] Use Prec.low rather than Prec.lowest for match highlighting FIX: Don't use the very lowest precedence for match highlighting decorations. --- src/search.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.ts b/src/search.ts index 22e127d..755663a 100644 --- a/src/search.ts +++ b/src/search.ts @@ -777,6 +777,6 @@ const baseTheme = EditorView.baseTheme({ const searchExtensions = [ searchState, - Prec.lowest(searchHighlighter), + Prec.low(searchHighlighter), baseTheme ] From 8d646e8449da23d492a7b3a5e3b9f8f8ae4e1a37 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sat, 26 Aug 2023 13:05:56 +0200 Subject: [PATCH 08/13] Mark version 6.5.2 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b1b00..10ecc4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.5.2 (2023-08-26) + +### Bug fixes + +Don't use the very lowest precedence for match highlighting decorations. + ## 6.5.1 (2023-08-04) ### Bug fixes diff --git a/package.json b/package.json index 2119e41..5f79611 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codemirror/search", - "version": "6.5.1", + "version": "6.5.2", "description": "Search functionality for the CodeMirror code editor", "scripts": { "test": "cm-runtests", From 65aace33037b3e4a423c9cdbb25a959bf9205dfa Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 30 Aug 2023 16:24:55 +0200 Subject: [PATCH 09/13] Populate the goto-line dialog with the current line As a way to query the current line number when using a screen reader. FIX: The `gotoLine` dialog is now populated with the current line number when you open it. Issue https://github.com/codemirror/dev/issues/845 See https://github.com/microsoft/vscode/issues/52429#issuecomment-447120835 --- src/goto-line.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/goto-line.ts b/src/goto-line.ts index 5ab156d..d7080d1 100644 --- a/src/goto-line.ts +++ b/src/goto-line.ts @@ -3,7 +3,8 @@ import {EditorView, Command, Panel, getPanel, showPanel} from "@codemirror/view" import elt from "crelt" function createLineDialog(view: EditorView): Panel { - let input = elt("input", {class: "cm-textfield", name: "line"}) as HTMLInputElement + let line = String(view.state.doc.lineAt(view.state.selection.main.head).number) + let input = elt("input", {class: "cm-textfield", name: "line", value: line}) as HTMLInputElement let dom = elt("form", { class: "cm-gotoLine", onkeydown: (event: KeyboardEvent) => { @@ -75,7 +76,7 @@ export const gotoLine: Command = view => { view.dispatch({effects}) panel = getPanel(view, createLineDialog) } - if (panel) panel.dom.querySelector("input")!.focus() + if (panel) panel.dom.querySelector("input")!.select() return true } From 14fb632bfad63f7f73254a21032a49e290cefbcc Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 14 Sep 2023 07:37:14 +0200 Subject: [PATCH 10/13] Mark version 6.5.3 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ecc4e..0855e66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.5.3 (2023-09-14) + +### Bug fixes + +The `gotoLine` dialog is now populated with the current line number when you open it. + ## 6.5.2 (2023-08-26) ### Bug fixes diff --git a/package.json b/package.json index 5f79611..aae4de3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codemirror/search", - "version": "6.5.2", + "version": "6.5.3", "description": "Search functionality for the CodeMirror code editor", "scripts": { "test": "cm-runtests", From ab086a1b85983749a7652a112c7d3f1671f7c40c Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 20 Sep 2023 15:13:49 +0200 Subject: [PATCH 11/13] Fix a bug in word boundary check FIX: Fix a bug that caused whole-word search to incorrectly check for word boundaries in some circumstances. See https://discuss.codemirror.net/t/wholeword-search-fails-to-identify-certain-words/7119 --- src/cursor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cursor.ts b/src/cursor.ts index 97f77dd..dd0770f 100644 --- a/src/cursor.ts +++ b/src/cursor.ts @@ -112,7 +112,7 @@ export class SearchCursor implements Iterator<{from: number, to: number}>{ else this.matches.push(1, pos) } - if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferPos)) match = null + if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferStart)) match = null return match } From 7a4a57e52b4af5807d195296c9933c4c7df947f5 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 20 Sep 2023 15:13:56 +0200 Subject: [PATCH 12/13] Mark version 6.5.4 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0855e66..c1da63b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.5.4 (2023-09-20) + +### Bug fixes + +Fix a bug that caused whole-word search to incorrectly check for word boundaries in some circumstances. + ## 6.5.3 (2023-09-14) ### Bug fixes diff --git a/package.json b/package.json index aae4de3..43f337c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codemirror/search", - "version": "6.5.3", + "version": "6.5.4", "description": "Search functionality for the CodeMirror code editor", "scripts": { "test": "cm-runtests", From 8491f3d143b09c5831b040674242a282857a83a7 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 7 Nov 2023 14:28:01 +0100 Subject: [PATCH 13/13] Don't unescape backslash codes in replaced content FIX: Fix a bug that caused codes like `\n` to be unescaped in strings inserted via replace placeholders like `$&`. Closes https://github.com/codemirror/dev/issues/1291 --- src/search.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/search.ts b/src/search.ts index 755663a..0daf463 100644 --- a/src/search.ts +++ b/src/search.ts @@ -293,11 +293,11 @@ class RegExpQuery extends QueryType { } getReplacement(result: RegExpResult) { - return this.spec.unquote(this.spec.replace.replace(/\$([$&\d+])/g, (m, i) => + return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$" : i == "&" ? result.match[0] : i != "0" && +i < result.match.length ? result.match[i] - : m)) + : m) } matchAll(state: EditorState, limit: number) {