Compare commits
2 Commits
b87f32eac9
...
0cdb116ec1
Author | SHA1 | Date | |
---|---|---|---|
0cdb116ec1 | |||
6ea1679112 |
59
textinput.go
59
textinput.go
|
@ -66,60 +66,61 @@ 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 {
|
||||
if x == 0 { return false }
|
||||
this.ScrollTo(this.ContentBounds().Min.Sub(image.Pt(int(x), int(y))))
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user