Offload selection manipulation of TextInput to backend

This commit is contained in:
Sasha Koshka 2024-07-26 18:49:54 -04:00
parent b87f32eac9
commit 6ea1679112

View File

@ -66,57 +66,57 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
dot := this.Dot()
modifiers := this.Window().Modifiers()
word := modifiers.Control
sel := modifiers.Shift
changed := false
// TODO all dot control (movement, selection, etc) should be done in the
// backend. (editing should be done here, though)
defer func () {
this.Select(dot)
if changed {
this.SetText(string(this.text))
this.on.valueChange.Broadcast()
}
} ()
switch {
case key == input.KeyEnter:
this.on.confirm.Broadcast()
case key == input.KeyHome || (modifiers.Alt && key == input.KeyLeft):
dot.End = 0
if !sel { dot.Start = dot.End }
case key == input.KeyEnd || (modifiers.Alt && key == input.KeyRight):
dot.End = len(this.text)
if !sel { dot.Start = dot.End }
case key == input.KeyLeft:
if sel {
dot = text.SelectLeft(this.text, dot, word)
} else {
dot = text.MoveLeft(this.text, dot, word)
}
case key == input.KeyRight:
if sel {
dot = text.SelectRight(this.text, dot, word)
} else {
dot = text.MoveRight(this.text, dot, word)
}
return true
case key == input.KeyBackspace:
this.text, dot = text.Backspace(this.text, dot, word)
changed = true
return true
case key == input.KeyDelete:
this.text, dot = text.Delete(this.text, dot, word)
changed = true
return true
case key == input.Key('a') && modifiers.Control:
dot.Start = 0
dot.End = len(this.text)
return true
case key.Printable():
this.text, dot = text.Type(this.text, dot, rune(key))
changed = true
return true
default:
return false
}
this.Select(dot)
if changed {
this.SetText(string(this.text))
this.on.valueChange.Broadcast()
}
return true
}
func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
return true
modifiers := this.Window().Modifiers()
switch {
case key == input.KeyEnter:
return true
case key == input.KeyBackspace:
return true
case key == input.KeyDelete:
return true
case key == input.Key('a') && modifiers.Control:
return true
case key.Printable():
return true
default:
return false
}
}
func (this *TextInput) handleScroll (x, y float64) bool {