commit 2b6e0a2

delthas  ·  2024-07-03 00:07:04 +0000 UTC
parent f5a1c3d
Make Enter pick an autocompletion when the menu is open

Fixes: https://todo.sr.ht/~delthas/senpai/156
3 files changed,  +13, -1
M app.go
M app.go
+1, -1
1@@ -763,7 +763,7 @@ func (app *App) handleKeyEvent(ev vaxis.Key) {
2 	} else if keyMatches(ev, '\n', 0) || keyMatches(ev, '\r', 0) || keyMatches(ev, 'j', vaxis.ModCtrl) || keyMatches(ev, vaxis.KeyKeyPadEnter, 0) {
3 		if ev.EventType == vaxis.EventPaste {
4 			app.win.InputRune('\n')
5-		} else {
6+		} else if !app.win.InputEnter() {
7 			netID, buffer := app.win.CurrentBuffer()
8 			input := string(app.win.InputContent())
9 			var err error
+7, -0
 1@@ -302,6 +302,13 @@ func (e *Editor) Set(text string) {
 2 	e.backsearchEnd()
 3 }
 4 
 5+func (e *Editor) Enter() bool {
 6+	if e.autoCache != nil {
 7+		return e.AutoComplete()
 8+	}
 9+	return false
10+}
11+
12 func (e *Editor) Right() {
13 	e.right()
14 	e.autoCache = nil
+5, -0
 1@@ -464,6 +464,11 @@ func (ui *UI) InputRune(r rune) {
 2 	ui.e.PutRune(r)
 3 }
 4 
 5+// InputEnter returns true if the event was eaten
 6+func (ui *UI) InputEnter() bool {
 7+	return ui.e.Enter()
 8+}
 9+
10 func (ui *UI) InputRight() {
11 	ui.e.Right()
12 }