mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-19 18:49:19 +01:00
Treat _ as a word character in word boundary search
This commit is contained in:
parent
51c4494628
commit
479d13cc0c
@ -8,7 +8,7 @@ import ocelot.desktop.ui.UiHandler
|
||||
import ocelot.desktop.ui.event.handlers.MouseHandler
|
||||
import ocelot.desktop.ui.event.sources.KeyEvents
|
||||
import ocelot.desktop.ui.event.{DragEvent, KeyEvent, MouseEvent}
|
||||
import ocelot.desktop.ui.widget.TextInput.{isPunctuation, Cursor, Selection, Text}
|
||||
import ocelot.desktop.ui.widget.TextInput.{Cursor, Selection, Text, isPunctuation, isWordCharacter}
|
||||
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry}
|
||||
import ocelot.desktop.ui.widget.traits.HoverAnimation
|
||||
import ocelot.desktop.util.NumberUtils.ExtendedInt
|
||||
@ -357,8 +357,6 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
||||
wordStart: Boolean,
|
||||
punctuationBoundaries: Boolean,
|
||||
): Int = {
|
||||
import Character.isLetterOrDigit
|
||||
|
||||
val start = initialPosition.clamped(0, _text.chars.length)
|
||||
|
||||
val indices = if (forward) {
|
||||
@ -370,13 +368,13 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
||||
val isBoundaryCodepoints: (Int, Int) => Boolean = if (wordStart) {
|
||||
(prev, current) =>
|
||||
(
|
||||
isLetterOrDigit(current) && !isLetterOrDigit(prev)
|
||||
isWordCharacter(current) && !isWordCharacter(prev)
|
||||
|| punctuationBoundaries && isPunctuation(current) && !isPunctuation(prev)
|
||||
)
|
||||
} else {
|
||||
(prev, current) =>
|
||||
(
|
||||
!isLetterOrDigit(current) && isLetterOrDigit(prev)
|
||||
!isWordCharacter(current) && isWordCharacter(prev)
|
||||
|| punctuationBoundaries && !isPunctuation(current) && isPunctuation(prev)
|
||||
)
|
||||
}
|
||||
@ -536,7 +534,11 @@ object TextInput {
|
||||
)
|
||||
|
||||
private def isPunctuation(codepoint: Int): Boolean = {
|
||||
PunctuationCategories.contains(Character.getType(codepoint))
|
||||
!isWordCharacter(codepoint) && PunctuationCategories.contains(Character.getType(codepoint))
|
||||
}
|
||||
|
||||
private def isWordCharacter(codepoint: Int): Boolean = {
|
||||
codepoint == '_' || Character.isLetterOrDigit(codepoint)
|
||||
}
|
||||
|
||||
class Text(initialValue: Array[Int]) extends BaseWatcher(initialValue) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user