Merge pull request #3947 from SiriusXT/master

FindInText: Automatically search the selected text
This commit is contained in:
zadam 2023-05-18 13:27:37 +02:00 committed by GitHub
commit 1089e84f56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -145,19 +145,27 @@ 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;
this.$findBox.show();
this.$input.focus();
this.handler = await this.getHandler();
const isAlreadyVisible = this.$findBox.is(":visible");
if (isAlreadyVisible) {
this.$input.val(searchTerm || "");
if (searchTerm !== "") {
this.$input.select();
await this.performFind();
}
this.$input.select();
} else {
this.$totalFound.text(0);
this.$currentFound.text(0);
const searchTerm = await this.handler.getInitialSearchTerm();
searchTerm = await this.handler.getInitialSearchTerm();
this.$input.val(searchTerm || "");
if (searchTerm !== "") {
this.$input.select();