Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search selections when content is changed #2846

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/note-content-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ class NoteContentEditor extends Component<Props> {
this.setDecorators();
}

// If content is changed so that the selected search index is greater then the number of matches
// then select the last match instead
if (
this.editor &&
this.state.editor === 'full' &&
(this.props.selectedSearchMatchIndex ?? 0) > this.matchesInNote.length - 1
) {
const newIndex = Math.max(this.matchesInNote.length - 1, 0);
this.setSearchSelection(newIndex);
this.props.storeSearchSelection(newIndex);
}

if (
this.editor &&
this.state.editor === 'full' &&
Expand Down