commit 31f9033
delthas
·
2022-02-13 13:21:59 +0000 UTC
parent 5f199ec
Make CTRL+C alternatively clear the input and set '/quit' in it
3 files changed,
+19,
-0
M
app.go
+2,
-0
1@@ -448,6 +448,8 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
2 case tcell.KeyCtrlC:
3 if app.win.InputClear() {
4 app.typing()
5+ } else {
6+ app.win.InputSet("/quit")
7 }
8 case tcell.KeyCtrlL:
9 app.win.Resize()
+13,
-0
1@@ -214,6 +214,19 @@ func (e *Editor) Clear() bool {
2 return true
3 }
4
5+func (e *Editor) Set(text string) {
6+ r := []rune(text)
7+ e.text[e.lineIdx] = r
8+ e.cursorIdx = len(r)
9+ e.computeTextWidth()
10+ e.offsetIdx = 0
11+ for e.width < e.textWidth[e.cursorIdx]-e.textWidth[e.offsetIdx]+16 {
12+ e.offsetIdx++
13+ }
14+ e.autoCache = nil
15+ e.backsearchEnd()
16+}
17+
18 func (e *Editor) Right() {
19 e.right()
20 e.autoCache = nil
M
ui/ui.go
+4,
-0
1@@ -318,6 +318,10 @@ func (ui *UI) InputClear() bool {
2 return ui.e.Clear()
3 }
4
5+func (ui *UI) InputSet(text string) {
6+ ui.e.Set(text)
7+}
8+
9 func (ui *UI) InputBackSearch() {
10 ui.e.BackSearch()
11 }