fix(wrapper): up/down arrow hide menu

This commit is contained in:
verse91
2026-04-19 09:59:53 +07:00
parent 7c11a3a620
commit c798673069
+12 -9
View File
@@ -199,8 +199,9 @@ func runWrapper() {
if b == '\033' { if b == '\033' {
// handle escape sequences like arrow keys and functional shortcuts // handle escape sequences like arrow keys and functional shortcuts
if i+2 < n && inputSlice[i+1] == '[' && inputSlice[i+2] == 'Z' { if i+2 < n && (inputSlice[i+1] == '[' || inputSlice[i+1] == 'O') {
// shift tab: hide/unhide menu dropdown // shift tab: hide/unhide menu dropdown
if inputSlice[i+1] == '[' && inputSlice[i+2] == 'Z' {
intercepted = true intercepted = true
suggestionsEnabled = !suggestionsEnabled suggestionsEnabled = !suggestionsEnabled
if !suggestionsEnabled { if !suggestionsEnabled {
@@ -212,25 +213,27 @@ func runWrapper() {
continue continue
} }
ptmx.Write([]byte{b}) if overlay.Visible && (inputSlice[i+2] == 'A' || inputSlice[i+2] == 'B') {
if i+2 < n && inputSlice[i+1] == '[' { intercepted = true
if overlay.Visible { if inputSlice[i+2] == 'A' { // up arrow
switch inputSlice[i+2] {
case 'A': // up arrow
overlay.Cursor-- overlay.Cursor--
if overlay.Cursor < 0 { if overlay.Cursor < 0 {
overlay.Cursor = 0 overlay.Cursor = 0
} }
os.Stdout.Write([]byte(overlay.Render())) } else { // down arrow
case 'B': // down arrow
overlay.Cursor++ overlay.Cursor++
if overlay.Cursor >= len(overlay.Items) { if overlay.Cursor >= len(overlay.Items) {
overlay.Cursor = len(overlay.Items) - 1 overlay.Cursor = len(overlay.Items) - 1
} }
}
os.Stdout.Write([]byte(overlay.Render())) os.Stdout.Write([]byte(overlay.Render()))
i += 2
continue
} }
} }
}
// forward escape sequence to pty if not intercepted
ptmx.Write([]byte{b})
// skip remaining bytes of the escape sequence to avoid misinterpretation // skip remaining bytes of the escape sequence to avoid misinterpretation
for j := i + 1; j < n; j++ { for j := i + 1; j < n; j++ {
char := inputSlice[j] char := inputSlice[j]