diff --git a/macOS/SynapseNotes/EditorView.swift b/macOS/SynapseNotes/EditorView.swift index 7617eec..c379f3a 100644 --- a/macOS/SynapseNotes/EditorView.swift +++ b/macOS/SynapseNotes/EditorView.swift @@ -2740,29 +2740,32 @@ class LinkAwareTextView: NSTextView { private func replaceAllMatches(query: String, replacement: String) { guard !query.isEmpty, let storage = textStorage else { return } let content = storage.string - var matches: [NSRange] = [] - var searchStart = content.startIndex - while searchStart < content.endIndex, - let r = content.range(of: query, options: .caseInsensitive, range: searchStart.. 0 else { + applySearchHighlights(query: query, focusIndex: 0) + return } + let fullRange = NSRange(location: 0, length: storage.length) - guard shouldChangeText(in: fullRange, replacementString: mutable as String) else { return } + guard shouldChangeText(in: fullRange, replacementString: resultString) else { return } // Highlight ranges are about to be invalidated by the full-document replace. // Drop them now so the debounced restyle (which re-applies highlights via // reapplySearchHighlights) can't read out-of-bounds NSRanges and crash. lastSearchHighlightRanges = [] lastSearchFocusIndex = -1 - storage.replaceCharacters(in: fullRange, with: mutable as String) + storage.replaceCharacters(in: fullRange, with: resultString) didChangeText() applySearchHighlights(query: query, focusIndex: 0)