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()
|
selectWord()
|
||||||
|
|
||||||
case DragEvent(DragEvent.State.Start | DragEvent.State.Drag, MouseEvent.Button.Left, mouse) if isFocused =>
|
case DragEvent(DragEvent.State.Start | DragEvent.State.Drag, MouseEvent.Button.Left, mouse) if isFocused =>
|
||||||
val pos = pixelToCursorPosition(mouse.x - bounds.x)
|
val pos = if (mouse.y < bounds.y) {
|
||||||
selection = Selection(selection.fold(prevCursorPosition.value)(_.start), pos)
|
0
|
||||||
|
} else if (mouse.y > bounds.max.y) {
|
||||||
|
_text.chars.length
|
||||||
|
} else {
|
||||||
|
pixelToCursorPosition(mouse.x - bounds.x)
|
||||||
|
}
|
||||||
|
|
||||||
|
extendSelection(pos, prevCursorPosition.value)
|
||||||
cursor.position = pos
|
cursor.position = pos
|
||||||
|
|
||||||
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 =>
|
||||||
@ -291,11 +298,15 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w
|
|||||||
pos
|
pos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def extendSelection(position: Int, cursorPosition: Int = cursor.position): Unit = {
|
||||||
|
selection = Selection(selection.fold(cursorPosition)(_.start), position)
|
||||||
|
}
|
||||||
|
|
||||||
private def handleKeyMovement(position: Int): Unit = {
|
private def handleKeyMovement(position: Int): Unit = {
|
||||||
selection = if (KeyEvents.isShiftDown) {
|
if (KeyEvents.isShiftDown) {
|
||||||
Selection(selection.fold(cursor.position)(_.start), position)
|
extendSelection(position)
|
||||||
} else {
|
} else {
|
||||||
None
|
selection = None
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.position = position
|
cursor.position = position
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user