mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Reformat TextInput
This commit is contained in:
parent
cbd3927cc5
commit
51c4494628
@ -8,7 +8,7 @@ import ocelot.desktop.ui.UiHandler
|
|||||||
import ocelot.desktop.ui.event.handlers.MouseHandler
|
import ocelot.desktop.ui.event.handlers.MouseHandler
|
||||||
import ocelot.desktop.ui.event.sources.KeyEvents
|
import ocelot.desktop.ui.event.sources.KeyEvents
|
||||||
import ocelot.desktop.ui.event.{DragEvent, KeyEvent, MouseEvent}
|
import ocelot.desktop.ui.event.{DragEvent, KeyEvent, MouseEvent}
|
||||||
import ocelot.desktop.ui.widget.TextInput.{Cursor, Selection, Text, isPunctuation}
|
import ocelot.desktop.ui.widget.TextInput.{isPunctuation, Cursor, Selection, Text}
|
||||||
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry}
|
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry}
|
||||||
import ocelot.desktop.ui.widget.traits.HoverAnimation
|
import ocelot.desktop.ui.widget.traits.HoverAnimation
|
||||||
import ocelot.desktop.util.NumberUtils.ExtendedInt
|
import ocelot.desktop.util.NumberUtils.ExtendedInt
|
||||||
@ -209,7 +209,8 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
|||||||
case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_LEFT, _) if isFocused =>
|
case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_LEFT, _) if isFocused =>
|
||||||
handleKeyMovement(selection match {
|
handleKeyMovement(selection match {
|
||||||
case Some(Selection.Ordered(start, _)) if !KeyEvents.isShiftDown => start
|
case Some(Selection.Ordered(start, _)) if !KeyEvents.isShiftDown => start
|
||||||
case _ if KeyEvents.isControlDown => findWordBoundary(cursor.position - 1, forward = false, wordStart = true, punctuationBoundaries = false)
|
case _ if KeyEvents.isControlDown =>
|
||||||
|
findWordBoundary(cursor.position - 1, forward = false, wordStart = true, punctuationBoundaries = false)
|
||||||
case _ => cursor.position - 1
|
case _ => cursor.position - 1
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -218,7 +219,8 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
|||||||
case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_RIGHT, _) if isFocused =>
|
case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_RIGHT, _) if isFocused =>
|
||||||
handleKeyMovement(selection match {
|
handleKeyMovement(selection match {
|
||||||
case Some(Selection.Ordered(_, end)) if !KeyEvents.isShiftDown => end
|
case Some(Selection.Ordered(_, end)) if !KeyEvents.isShiftDown => end
|
||||||
case _ if KeyEvents.isControlDown => findWordBoundary(cursor.position + 1, forward = true, wordStart = false, punctuationBoundaries = false)
|
case _ if KeyEvents.isControlDown =>
|
||||||
|
findWordBoundary(cursor.position + 1, forward = true, wordStart = false, punctuationBoundaries = false)
|
||||||
case _ => cursor.position + 1
|
case _ => cursor.position + 1
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -349,7 +351,12 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
|||||||
*
|
*
|
||||||
* May return the `initialPosition` if it's already at the boundary.
|
* May return the `initialPosition` if it's already at the boundary.
|
||||||
*/
|
*/
|
||||||
private def findWordBoundary(initialPosition: Int, forward: Boolean, wordStart: Boolean, punctuationBoundaries: Boolean): Int = {
|
private def findWordBoundary(
|
||||||
|
initialPosition: Int,
|
||||||
|
forward: Boolean,
|
||||||
|
wordStart: Boolean,
|
||||||
|
punctuationBoundaries: Boolean,
|
||||||
|
): Int = {
|
||||||
import Character.isLetterOrDigit
|
import Character.isLetterOrDigit
|
||||||
|
|
||||||
val start = initialPosition.clamped(0, _text.chars.length)
|
val start = initialPosition.clamped(0, _text.chars.length)
|
||||||
@ -361,12 +368,14 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
|||||||
}
|
}
|
||||||
|
|
||||||
val isBoundaryCodepoints: (Int, Int) => Boolean = if (wordStart) {
|
val isBoundaryCodepoints: (Int, Int) => Boolean = if (wordStart) {
|
||||||
(prev, current) => (
|
(prev, current) =>
|
||||||
|
(
|
||||||
isLetterOrDigit(current) && !isLetterOrDigit(prev)
|
isLetterOrDigit(current) && !isLetterOrDigit(prev)
|
||||||
|| punctuationBoundaries && isPunctuation(current) && !isPunctuation(prev)
|
|| punctuationBoundaries && isPunctuation(current) && !isPunctuation(prev)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(prev, current) => (
|
(prev, current) =>
|
||||||
|
(
|
||||||
!isLetterOrDigit(current) && isLetterOrDigit(prev)
|
!isLetterOrDigit(current) && isLetterOrDigit(prev)
|
||||||
|| punctuationBoundaries && !isPunctuation(current) && isPunctuation(prev)
|
|| punctuationBoundaries && !isPunctuation(current) && isPunctuation(prev)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user