scoop:scoop.ui:0.1.0
src/text/services.scoop
Selected production source · src/text/services.scoop
1
package scoop.ui.text3
import scoop.window.*5
internal struct TextCheckingContext(val text: String, val start: Long)7
internal fun textCheckingContext(text: String, range: Utf8Range): TextCheckingContext {8
val bytes = text.toByteArray()9
var start = range.start10
var end = range.end11
while (start > 0L && bytes[start - 1L] != 10.toByte() && bytes[start - 1L] != 13.toByte())12
start -= 1L13
while (end < bytes.size && bytes[end] != 10.toByte() && bytes[end] != 13.toByte())14
end += 1L15
return TextCheckingContext(text.utf8Slice(Utf8Range(start, end)), start)16
}18
internal fun textCheckTouches(finding: Utf8Range, selection: Utf8Range): Boolean =19
if (selection.start == selection.end)20
finding.start <= selection.start && finding.end >= selection.end21
else22
finding.start < selection.end && finding.end > selection.start