commit b54af7e
Hubert Hirtz
·
2020-08-05 12:10:14 +0000 UTC
parent 6dbbd0b
editor: handle HOME and END keys
3 files changed,
+26,
-0
M
app.go
+4,
-0
1@@ -219,6 +219,10 @@ func (app *App) handleUIEvent(ev tcell.Event) {
2 } else {
3 app.win.InputLeft()
4 }
5+ case tcell.KeyHome:
6+ app.win.InputHome()
7+ case tcell.KeyEnd:
8+ app.win.InputEnd()
9 case tcell.KeyBackspace2:
10 ok := app.win.InputBackspace()
11 if ok && app.win.InputLen() == 0 {
+12,
-0
1@@ -122,6 +122,18 @@ func (e *editor) Left() {
2 }
3 }
4
5+func (e *editor) Home() {
6+ e.cursorIdx = 0
7+ e.offsetIdx = 0
8+}
9+
10+func (e *editor) End() {
11+ e.cursorIdx = len(e.text)
12+ for e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
13+ e.offsetIdx++
14+ }
15+}
16+
17 func (e *editor) Draw(screen tcell.Screen, y int) {
18 st := tcell.StyleDefault
19
M
ui/ui.go
+10,
-0
1@@ -156,6 +156,16 @@ func (ui *UI) InputLeft() {
2 ui.draw()
3 }
4
5+func (ui *UI) InputHome() {
6+ ui.e.Home()
7+ ui.draw()
8+}
9+
10+func (ui *UI) InputEnd() {
11+ ui.e.End()
12+ ui.draw()
13+}
14+
15 func (ui *UI) InputBackspace() (ok bool) {
16 ok = ui.e.RemRune()
17 if ok {