mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Take mouse.y into account when computing the selection endpoint
This commit is contained in:
parent
ca8ef6eee1
commit
68350f8d62
@ -181,8 +181,15 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
||||
selectWord()
|
||||
|
||||
case DragEvent(DragEvent.State.Start | DragEvent.State.Drag, MouseEvent.Button.Left, mouse) if isFocused =>
|
||||
val pos = pixelToCursorPosition(mouse.x - bounds.x)
|
||||
selection = Selection(selection.fold(prevCursorPosition.value)(_.start), pos)
|
||||
val pos = if (mouse.y < bounds.y) {
|
||||
0
|
||||
} else if (mouse.y > bounds.max.y) {
|
||||
_text.chars.length
|
||||
} else {
|
||||
pixelToCursorPosition(mouse.x - bounds.x)
|
||||
}
|
||||
|
||||
extendSelection(pos, prevCursorPosition.value)
|
||||
cursor.position = pos
|
||||
|
||||
case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_LEFT, _) if isFocused =>
|
||||
@ -290,12 +297,16 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
||||
}
|
||||
pos
|
||||
}
|
||||
|
||||
private def extendSelection(position: Int, cursorPosition: Int = cursor.position): Unit = {
|
||||
selection = Selection(selection.fold(cursorPosition)(_.start), position)
|
||||
}
|
||||
|
||||
private def handleKeyMovement(position: Int): Unit = {
|
||||
selection = if (KeyEvents.isShiftDown) {
|
||||
Selection(selection.fold(cursor.position)(_.start), position)
|
||||
if (KeyEvents.isShiftDown) {
|
||||
extendSelection(position)
|
||||
} else {
|
||||
None
|
||||
selection = None
|
||||
}
|
||||
|
||||
cursor.position = position
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user