Skip to content

Commit

Permalink
fix refocusing find widget, closes #3252
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Oct 28, 2022
1 parent 64d3ec9 commit 521d950
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions src/public/app/widgets/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,27 @@ export default class FindWidget extends NoteContextAwareWidget {
return;
}

if (!['text', 'code', 'render'].includes(this.note.type) || !this.$findBox.is(":hidden")) {
if (!['text', 'code', 'render'].includes(this.note.type)) {
return;
}

this.handler = await this.getHandler();

this.$findBox.show();
this.$input.focus();
this.$totalFound.text(0);
this.$currentFound.text(0);

const searchTerm = await this.handler.getInitialSearchTerm();
this.handler = await this.getHandler();

this.$input.val(searchTerm || "");
const isAlreadyVisible = this.$findBox.is(":visible");

// Directly perform the search if there's some text to
// find, without delaying or waiting for enter
if (searchTerm !== "") {
if (isAlreadyVisible) {
this.$input.select();
await this.performFind();
} else {
this.$totalFound.text(0);
this.$currentFound.text(0);
const searchTerm = await this.handler.getInitialSearchTerm();
this.$input.val(searchTerm || "");
if (searchTerm !== "") {
this.$input.select();
await this.performFind();
}
}
}

Expand Down

0 comments on commit 521d950

Please sign in to comment.