Skip to content

Build your personal knowledge base with Trilium Notes

cleanup of find in text implementation

zadam074820dae55c
diff --git a/src/public/app/widgets/find.js b/src/public/app/widgets/find.js
index bbead9d0ea..7c46ccde61 100644
--- a/src/public/app/widgets/find.js
+++ b/src/public/app/widgets/find.js
@@ -145,10 +145,10 @@ export default class FindWidget extends NoteContextAwareWidget {
if (!['text', 'code', 'render'].includes(this.note.type)) {
return;
}
-
+
this.handler = await this.getHandler();
- var searchTerm = await this.handler.getInitialSearchTerm();
- searchTerm = searchTerm=="" ? window.getSelection().toString():searchTerm;
+
+ const selectedText = window.getSelection().toString() || "";
this.$findBox.show();
this.$input.focus();
@@ -156,18 +156,21 @@ export default class FindWidget extends NoteContextAwareWidget {
const isAlreadyVisible = this.$findBox.is(":visible");
if (isAlreadyVisible) {
- this.$input.val(searchTerm || "");
- if (searchTerm !== "") {
- this.$input.select();
+ if (selectedText) {
+ this.$input.val(selectedText);
+ }
+
+ if (this.$input.val()) {
await this.performFind();
}
+
this.$input.select();
} else {
this.$totalFound.text(0);
this.$currentFound.text(0);
- searchTerm = await this.handler.getInitialSearchTerm();
- this.$input.val(searchTerm || "");
- if (searchTerm !== "") {
+ this.$input.val(selectedText);
+
+ if (selectedText) {
this.$input.select();
await this.performFind();
}
diff --git a/src/public/app/widgets/find_in_code.js b/src/public/app/widgets/find_in_code.js
index 54784b7543..87239eb097 100644
--- a/src/public/app/widgets/find_in_code.js
+++ b/src/public/app/widgets/find_in_code.js
@@ -16,23 +16,6 @@ export default class FindInCode {
return this.parent.noteContext.getCodeEditor();
}
- async getInitialSearchTerm() {
- const codeEditor = await this.getCodeEditor();
-
- // highlightSelectionMatches is the overlay that highlights
- // the words under the cursor. This occludes the search
- // markers style, save it, disable it. Will be restored when
- // the focus is back into the note
- this.oldHighlightSelectionMatches = codeEditor.getOption("highlightSelectionMatches");
- codeEditor.setOption("highlightSelectionMatches", false);
-
- // Fill in the findbox with the current selection if any
- const selectedText = codeEditor.getSelection()
- if (selectedText !== "") {
- return selectedText;
- }
- }
-
async performFind(searchTerm, matchCase, wholeWord) {
let findResult = null;
let totalFound = 0;
diff --git a/src/public/app/widgets/find_in_html.js b/src/public/app/widgets/find_in_html.js
index 2feb3d5feb..349c70d515 100644
--- a/src/public/app/widgets/find_in_html.js
+++ b/src/public/app/widgets/find_in_html.js
@@ -16,10 +16,6 @@ export default class FindInHtml {
this.$results = null;
}
- async getInitialSearchTerm() {
- return ""; // FIXME
- }
-
async performFind(searchTerm, matchCase, wholeWord) {
await libraryLoader.requireLibrary(libraryLoader.MARKJS);
diff --git a/src/public/app/widgets/find_in_text.js b/src/public/app/widgets/find_in_text.js
index b45d4a9903..66dbabe1e9 100644
--- a/src/public/app/widgets/find_in_text.js
+++ b/src/public/app/widgets/find_in_text.js
@@ -8,19 +8,6 @@ export default class FindInText {
return this.parent.noteContext.getTextEditor();
}
- async getInitialSearchTerm() {
- const textEditor = await this.getTextEditor();
-
- const selection = textEditor.model.document.selection;
- const range = selection.getFirstRange();
-
- // FIXME
- for (const item of range.getItems()) {
- // Fill in the findbox with the current selection if any
- return item.data;
- }
- }
-
async performFind(searchTerm, matchCase, wholeWord) {
// Do this even if the searchTerm is empty so the markers are cleared and
// the counters updated