All selectable TextBoxes have keyboard controls
This commit is contained in:
parent
ddde2a79a8
commit
fad46eafd3
@ -24,6 +24,7 @@ type textBox struct {
|
||||
attrOverflow attrHierarchy[tomo.AttrOverflow]
|
||||
|
||||
text string
|
||||
runes []rune
|
||||
selectable bool
|
||||
selecting bool
|
||||
selectStart int
|
||||
@ -70,8 +71,9 @@ func (this *textBox) OnContentBoundsChange (callback func()) event.Cookie {
|
||||
|
||||
func (this *textBox) SetText (text string) {
|
||||
if this.text == text { return }
|
||||
this.text = text
|
||||
this.drawer.SetText([]rune(text))
|
||||
this.text = text
|
||||
this.runes = []rune(text)
|
||||
this.drawer.SetText(this.runes)
|
||||
this.invalidateMinimum()
|
||||
this.invalidateLayout()
|
||||
}
|
||||
@ -286,6 +288,71 @@ func (this *textBox) runeUnderMouse () int {
|
||||
return this.drawer.AtPosition(fixPt(position))
|
||||
}
|
||||
|
||||
func (this *textBox) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||
if this.box.handleKeyDown(key, numberPad) { return true }
|
||||
if this.selectable { return false }
|
||||
|
||||
// because fuck you thats why!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
modifiers := this.Window().Modifiers()
|
||||
dot := this.Dot()
|
||||
sel := modifiers.Shift
|
||||
word := modifiers.Control
|
||||
switch {
|
||||
case key == input.KeyHome || (modifiers.Alt && key == input.KeyLeft):
|
||||
dot.End = 0
|
||||
if !sel { dot.Start = dot.End }
|
||||
this.Select(dot)
|
||||
return true
|
||||
case key == input.KeyEnd || (modifiers.Alt && key == input.KeyRight):
|
||||
dot.End = len(this.text)
|
||||
if !sel { dot.Start = dot.End }
|
||||
this.Select(dot)
|
||||
return true
|
||||
case key == input.KeyLeft:
|
||||
if sel {
|
||||
this.Select(text.SelectLeft(this.runes, dot, word))
|
||||
} else {
|
||||
this.Select(text.MoveLeft(this.runes, dot, word))
|
||||
}
|
||||
return true
|
||||
case key == input.KeyRight:
|
||||
if sel {
|
||||
this.Select(text.SelectRight(this.runes, dot, word))
|
||||
} else {
|
||||
this.Select(text.MoveRight(this.runes, dot, word))
|
||||
}
|
||||
return true
|
||||
case key == input.Key('a') && modifiers.Control:
|
||||
dot.Start = 0
|
||||
dot.End = len(this.text)
|
||||
this.Select(dot)
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (this *textBox) handleKeyUp (key input.Key, numberPad bool) bool {
|
||||
if this.box.handleKeyUp(key, numberPad) { return true }
|
||||
if this.selectable { return false }
|
||||
|
||||
modifiers := this.Window().Modifiers()
|
||||
switch {
|
||||
case key == input.KeyHome || (modifiers.Alt && key == input.KeyLeft):
|
||||
return true
|
||||
case key == input.KeyEnd || (modifiers.Alt && key == input.KeyRight):
|
||||
return true
|
||||
case key == input.KeyLeft:
|
||||
return true
|
||||
case key == input.KeyRight:
|
||||
return true
|
||||
case key == input.Key('a') && modifiers.Control:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (this *textBox) normalizedLayoutBoundsSpace () image.Rectangle {
|
||||
bounds := this.drawer.LayoutBoundsSpace()
|
||||
return bounds.Sub(bounds.Min)
|
||||
|
Loading…
Reference in New Issue
Block a user