TextBox can be selected with left, middle, and right buttons

This commit is contained in:
Sasha Koshka 2024-07-26 21:17:30 -04:00
parent fd6297b4fb
commit 832d7e02ef
2 changed files with 13 additions and 4 deletions

View File

@ -3,7 +3,6 @@ package system
import "image"
import "git.tebibyte.media/tomo/tomo/input"
// TODO: redo all of this because there are new event propogation rules
// TODO: once go v1.23 comes out, replace the explicit iterator calls here with
// range loops

View File

@ -248,14 +248,18 @@ func (this *textBox) textOffset () image.Point {
Sub(this.drawer.LayoutBoundsSpace().Min)
}
func (this *textBox) handleFocusEnter () {
this.invalidateDraw()
this.box.handleFocusEnter()
}
func (this *textBox) handleFocusLeave () {
this.on.dotChange.Broadcast()
this.invalidateDraw()
this.box.handleFocusLeave()
}
func (this *textBox) handleMouseDown (button input.Button) bool {
if button == input.ButtonLeft {
if this.mouseButtonCanDrag(button) {
index := this.runeUnderMouse()
this.selectStart = index
this.selecting = true
@ -265,7 +269,7 @@ func (this *textBox) handleMouseDown (button input.Button) bool {
}
func (this *textBox) handleMouseUp (button input.Button) bool {
if button == input.ButtonLeft && this.selecting {
if this.mouseButtonCanDrag(button) && this.selecting {
index := this.runeUnderMouse()
this.selecting = false
this.Select(text.Dot { Start: this.selectStart, End: index })
@ -273,6 +277,12 @@ func (this *textBox) handleMouseUp (button input.Button) bool {
return this.box.handleMouseUp(button)
}
func (this *textBox) mouseButtonCanDrag (button input.Button) bool {
return button == input.ButtonLeft ||
button == input.ButtonMiddle ||
button == input.ButtonRight
}
func (this *textBox) handleMouseMove () bool {
if this.selecting {
index := this.runeUnderMouse()