Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/thirty-frogs-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/extension-find-and-replace": patch
---

Ensure only the active find-and-replace result keeps the current-result highlight while navigating matches.
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,31 @@ describe('FindAndReplace', () => {
editor = createEditor('<p>one two one two one</p>')
editor.commands.setSearchTerm('one')

const currentResultPositions = () => {
return Array.from(editor.view.dom.querySelectorAll('.find-and-replace-result-current')).map(
element => editor.view.posAtDOM(element, 0),
)
}

expect(editor.storage.findAndReplace.currentIndex).toBe(0)
expect(currentResultPositions()).toEqual([1])

editor.commands.goToNextResult()
expect(editor.storage.findAndReplace.currentIndex).toBe(1)
expect(editor.state.selection.from).toBe(9)
expect(editor.state.selection.to).toBe(12)
expect(currentResultPositions()).toEqual([9])

editor.commands.goToNextResult()
expect(currentResultPositions()).toEqual([17])

editor.commands.goToNextResult()
expect(editor.storage.findAndReplace.currentIndex).toBe(0)
expect(currentResultPositions()).toEqual([1])

editor.commands.goToPreviousResult()
expect(editor.storage.findAndReplace.currentIndex).toBe(2)
expect(currentResultPositions()).toEqual([17])
})

it('replaces the current result and jumps to the next one', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function findDecorations(

results.forEach(result => {
decorations
.find(result.from, result.to, decoration => {
.find(result.from, result.to)
.filter(decoration => {
return decoration.from === result.from && decoration.to === result.to
})
.forEach(decoration => found.add(decoration))
Expand Down
Loading