Compare commits
No commits in common. "0cdb116ec1e16d0214ef66763a3ef5826eaf1c04" and "b87f32eac9cb200b394f3fb4687f1b35c1da2df7" have entirely different histories.
0cdb116ec1
...
b87f32eac9
59
textinput.go
59
textinput.go
@ -66,61 +66,60 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
|
|||||||
dot := this.Dot()
|
dot := this.Dot()
|
||||||
modifiers := this.Window().Modifiers()
|
modifiers := this.Window().Modifiers()
|
||||||
word := modifiers.Control
|
word := modifiers.Control
|
||||||
|
sel := modifiers.Shift
|
||||||
changed := false
|
changed := false
|
||||||
|
|
||||||
defer func () {
|
// TODO all dot control (movement, selection, etc) should be done in the
|
||||||
this.Select(dot)
|
// backend. (editing should be done here, though)
|
||||||
if changed {
|
|
||||||
this.SetText(string(this.text))
|
|
||||||
this.on.valueChange.Broadcast()
|
|
||||||
}
|
|
||||||
} ()
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case key == input.KeyEnter:
|
case key == input.KeyEnter:
|
||||||
this.on.confirm.Broadcast()
|
this.on.confirm.Broadcast()
|
||||||
return true
|
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)
|
||||||
|
}
|
||||||
case key == input.KeyBackspace:
|
case key == input.KeyBackspace:
|
||||||
this.text, dot = text.Backspace(this.text, dot, word)
|
this.text, dot = text.Backspace(this.text, dot, word)
|
||||||
changed = true
|
changed = true
|
||||||
return true
|
|
||||||
case key == input.KeyDelete:
|
case key == input.KeyDelete:
|
||||||
this.text, dot = text.Delete(this.text, dot, word)
|
this.text, dot = text.Delete(this.text, dot, word)
|
||||||
changed = true
|
changed = true
|
||||||
return true
|
|
||||||
case key == input.Key('a') && modifiers.Control:
|
case key == input.Key('a') && modifiers.Control:
|
||||||
dot.Start = 0
|
dot.Start = 0
|
||||||
dot.End = len(this.text)
|
dot.End = len(this.text)
|
||||||
return true
|
|
||||||
case key.Printable():
|
case key.Printable():
|
||||||
this.text, dot = text.Type(this.text, dot, rune(key))
|
this.text, dot = text.Type(this.text, dot, rune(key))
|
||||||
changed = true
|
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 {
|
func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
|
||||||
modifiers := this.Window().Modifiers()
|
return true
|
||||||
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 {
|
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))))
|
this.ScrollTo(this.ContentBounds().Min.Sub(image.Pt(int(x), int(y))))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user