Textbox does not trigger a DotChange event when using Select
The convention within Tomo is that On*Change events only fire when the user interacts with something
This commit is contained in:
parent
6f9eca99e7
commit
b92308fc80
@ -98,9 +98,15 @@ func (this *textBox) SetSelectable (selectable bool) {
|
||||
}
|
||||
|
||||
func (this *textBox) Select (dot text.Dot) {
|
||||
this.selec(dot)
|
||||
}
|
||||
|
||||
func (this *textBox) selec (dot text.Dot) bool {
|
||||
if this.selectWithoutResettingDesiredX(dot) {
|
||||
this.desiredX = fixed.I(0)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *textBox) selectWithoutResettingDesiredX (dot text.Dot) bool {
|
||||
@ -109,11 +115,26 @@ func (this *textBox) selectWithoutResettingDesiredX (dot text.Dot) bool {
|
||||
this.SetFocused(true)
|
||||
this.dot = dot
|
||||
this.scrollToDot()
|
||||
this.on.dotChange.Broadcast()
|
||||
this.invalidateDraw()
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *textBox) userSelect (dot text.Dot) bool {
|
||||
if this.selec(dot) {
|
||||
return true
|
||||
this.on.dotChange.Broadcast()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *textBox) userSelectWithoutResettingDesiredX (dot text.Dot) bool {
|
||||
if this.selectWithoutResettingDesiredX(dot) {
|
||||
return true
|
||||
this.on.dotChange.Broadcast()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *textBox) Dot () text.Dot {
|
||||
return this.dot
|
||||
}
|
||||
@ -335,7 +356,7 @@ func (this *textBox) handleMouseDown (button input.Button) bool {
|
||||
index := this.runeUnderMouse()
|
||||
this.selectStart = index
|
||||
this.selecting = true
|
||||
this.Select(text.Dot { Start: this.selectStart, End: index })
|
||||
this.userSelect(text.Dot { Start: this.selectStart, End: index })
|
||||
}
|
||||
return this.box.handleMouseDown(button)
|
||||
}
|
||||
@ -344,7 +365,7 @@ func (this *textBox) handleMouseUp (button input.Button) bool {
|
||||
if this.mouseButtonCanDrag(button) && this.selecting {
|
||||
index := this.runeUnderMouse()
|
||||
this.selecting = false
|
||||
this.Select(text.Dot { Start: this.selectStart, End: index })
|
||||
this.userSelect(text.Dot { Start: this.selectStart, End: index })
|
||||
}
|
||||
return this.box.handleMouseUp(button)
|
||||
}
|
||||
@ -358,7 +379,7 @@ func (this *textBox) mouseButtonCanDrag (button input.Button) bool {
|
||||
func (this *textBox) handleMouseMove () bool {
|
||||
if this.selecting {
|
||||
index := this.runeUnderMouse()
|
||||
this.Select(text.Dot { Start: this.selectStart, End: index })
|
||||
this.userSelect(text.Dot { Start: this.selectStart, End: index })
|
||||
}
|
||||
return this.box.handleMouseMove()
|
||||
}
|
||||
@ -409,9 +430,9 @@ func (this *textBox) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||
|
||||
if sel {
|
||||
dot.End = nextDot
|
||||
this.selectWithoutResettingDesiredX(dot)
|
||||
this.userSelectWithoutResettingDesiredX(dot)
|
||||
} else {
|
||||
this.selectWithoutResettingDesiredX(text.EmptyDot(nextDot))
|
||||
this.userSelectWithoutResettingDesiredX(text.EmptyDot(nextDot))
|
||||
}
|
||||
}
|
||||
|
||||
@ -423,7 +444,7 @@ func (this *textBox) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||
dot.End = lineHomeSoft(this.runes, dot.End)
|
||||
}
|
||||
if !sel { dot.Start = dot.End }
|
||||
this.Select(dot)
|
||||
this.userSelect(dot)
|
||||
return true
|
||||
case key == input.KeyEnd || (modifiers.Alt && key == input.KeyRight):
|
||||
if word {
|
||||
@ -432,20 +453,20 @@ func (this *textBox) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||
dot.End = lineEnd(this.runes, dot.End)
|
||||
}
|
||||
if !sel { dot.Start = dot.End }
|
||||
this.Select(dot)
|
||||
this.userSelect(dot)
|
||||
return true
|
||||
case key == input.KeyLeft:
|
||||
if sel {
|
||||
this.Select(text.SelectLeft(this.runes, dot, word))
|
||||
this.userSelect(text.SelectLeft(this.runes, dot, word))
|
||||
} else {
|
||||
this.Select(text.MoveLeft(this.runes, dot, word))
|
||||
this.userSelect(text.MoveLeft(this.runes, dot, word))
|
||||
}
|
||||
return true
|
||||
case key == input.KeyRight:
|
||||
if sel {
|
||||
this.Select(text.SelectRight(this.runes, dot, word))
|
||||
this.userSelect(text.SelectRight(this.runes, dot, word))
|
||||
} else {
|
||||
this.Select(text.MoveRight(this.runes, dot, word))
|
||||
this.userSelect(text.MoveRight(this.runes, dot, word))
|
||||
}
|
||||
return true
|
||||
case key == input.KeyUp:
|
||||
@ -457,7 +478,7 @@ func (this *textBox) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||
case key == input.Key('a') && modifiers.Control:
|
||||
dot.Start = 0
|
||||
dot.End = len(this.text) // FIXME
|
||||
this.Select(dot)
|
||||
this.userSelect(dot)
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
Loading…
Reference in New Issue
Block a user