struct TextSearch
Swift
struct TextSearch
Find-in-buffer: match locations plus which one is current.
Deliberately holds no reference to the buffer. Matches are recomputed when asked rather than kept in sync with edits, because a stale match range is worse than no match at all — it would highlight, and navigate to, text that has moved.
Sources/LavaText/TextSearch.swift:9
Constructors
init()
Creates an inactive search.
Sources/LavaText/TextSearch.swift:20
Properties
var caseSensitive: Bool { get }
Whether the last search matched case exactly.
Sources/LavaText/TextSearch.swift:13
var count: Int { get }
How many matches there are.
Sources/LavaText/TextSearch.swift:25
var current: Range<Int>? { get }
The current match's range, or nil when there are none.
Sources/LavaText/TextSearch.swift:28
var currentIndex: Int? { get }
Index into matches of the current match, or nil when there are none.
Sources/LavaText/TextSearch.swift:17
var isActive: Bool { get }
Whether a search is in effect.
Sources/LavaText/TextSearch.swift:23
var matches: [Range<Int>] { get }
Character offsets over the whole buffer.
Sources/LavaText/TextSearch.swift:15
var query: String { get }
What was last searched for; empty when there is no search.
Sources/LavaText/TextSearch.swift:11
Methods
mutating func clear()
Ends the search, dropping every match.
Sources/LavaText/TextSearch.swift:49
mutating func find(_ query: String, in text: String, caseSensitive: Bool = false, near caret: Int = 0)
Recomputes matches. near biases the initial selection to the match at
or after the caret, so opening find jumps forward rather than back to
the top of the buffer.
Sources/LavaText/TextSearch.swift:36
mutating func next()
Wraps at the end, which is what every editor's find does.
Sources/LavaText/TextSearch.swift:56
mutating func previous()
Moves to the previous match, wrapping round to the last from the first.
Sources/LavaText/TextSearch.swift:62