commit c078fbb
delthas
·
2021-07-12 17:54:52 +0000 UTC
parent 01c2715
Clear the input on CTRL+C instead of quitting We have /QUIT for quitting. Most well-known IRC clients don't quit on CTRL+C but they do on QUIT. Clearing the editor input on CTRL+C is useful for shell-like behaviour "abort current line, let me start my line again".
3 files changed,
+18,
-1
M
app.go
+2,
-1
1@@ -320,7 +320,8 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
2 func (app *App) handleKeyEvent(ev *tcell.EventKey) {
3 switch ev.Key() {
4 case tcell.KeyCtrlC:
5- app.win.Exit()
6+ app.win.InputClear()
7+ app.typing()
8 case tcell.KeyCtrlL:
9 app.win.Resize()
10 case tcell.KeyCtrlU, tcell.KeyPgUp:
+12,
-0
1@@ -164,6 +164,18 @@ func (e *Editor) Flush() (content string) {
2 return
3 }
4
5+func (e *Editor) Clear() {
6+ if e.TextLen() == 0 {
7+ return
8+ }
9+ e.text[e.lineIdx] = []rune{}
10+ e.textWidth = e.textWidth[:1]
11+ e.cursorIdx = 0
12+ e.offsetIdx = 0
13+ e.autoCache = nil
14+ return
15+}
16+
17 func (e *Editor) Right() {
18 e.right()
19 e.autoCache = nil
M
ui/ui.go
+4,
-0
1@@ -228,6 +228,10 @@ func (ui *UI) InputEnter() (content string) {
2 return ui.e.Flush()
3 }
4
5+func (ui *UI) InputClear() {
6+ ui.e.Clear()
7+}
8+
9 func (ui *UI) Resize() {
10 w, h := ui.screen.Size()
11 ui.e.Resize(w - 9 - ui.config.ChanColWidth - ui.config.NickColWidth)