diff options
| author | adamdottv <[email protected]> | 2025-06-20 07:31:45 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-06-20 07:31:45 -0500 |
| commit | 261e76e0a3e3996a22817f5be9bebc949d673346 (patch) | |
| tree | bfe908b168128714e8f44f41bcefee52103c89b1 | |
| parent | a300bfaccb64779be2990496894630027eef42a6 (diff) | |
| download | opencode-261e76e0a3e3996a22817f5be9bebc949d673346.tar.gz opencode-261e76e0a3e3996a22817f5be9bebc949d673346.zip | |
fix(tui): input feels laggy
| -rw-r--r-- | packages/tui/internal/components/textarea/textarea.go | 3 | ||||
| -rw-r--r-- | packages/tui/internal/tui/tui.go | 71 |
2 files changed, 36 insertions, 38 deletions
diff --git a/packages/tui/internal/components/textarea/textarea.go b/packages/tui/internal/components/textarea/textarea.go index 0110ae824..6646d2a97 100644 --- a/packages/tui/internal/components/textarea/textarea.go +++ b/packages/tui/internal/components/textarea/textarea.go @@ -1161,8 +1161,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { } var cmd tea.Cmd - cmds = append(cmds, cmd) - newRow, newCol := m.cursorLineNumber(), m.col m.virtualCursor, cmd = m.virtualCursor.Update(msg) if (newRow != oldRow || newCol != oldCol) && m.virtualCursor.Mode() == cursor.CursorBlink { @@ -1171,7 +1169,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { } cmds = append(cmds, cmd) - m.SetHeight(m.ContentHeight()) return m, tea.Batch(cmds...) } diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go index e1f3aa1b1..176960429 100644 --- a/packages/tui/internal/tui/tui.go +++ b/packages/tui/internal/tui/tui.go @@ -70,9 +70,11 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: + keyString := msg.String() + // 1. Handle active modal if a.modal != nil { - switch msg.String() { + switch keyString { // Escape always closes current modal case "esc", "ctrl+c": a.modal = nil @@ -88,7 +90,6 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // 2. Check for commands that require leader if a.isLeaderSequence { matches := a.app.Commands.Matches(msg, a.isLeaderSequence) - // Reset leader state a.isLeaderSequence = false if len(matches) > 0 { return a, util.CmdHandler(commands.ExecuteCommandsMsg(matches)) @@ -96,44 +97,44 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } // 3. Handle completions trigger - switch msg.String() { - case "/": - if !a.showCompletionDialog { - a.showCompletionDialog = true - - initialValue := "/" - currentInput := a.editor.Value() - // if the input doesn't end with a space, - // then we want to include the last word - if !strings.HasSuffix(currentInput, " ") { - words := strings.Split(a.editor.Value(), " ") - if len(words) > 0 { - lastWord := words[len(words)-1] - lastWord = strings.TrimSpace(lastWord) - initialValue = lastWord + "/" - } + if keyString == "/" && !a.showCompletionDialog { + a.showCompletionDialog = true + + initialValue := "/" + currentInput := a.editor.Value() + + // if the input doesn't end with a space, + // then we want to include the last word + // (ie, `packages/`) + if !strings.HasSuffix(currentInput, " ") { + words := strings.Split(a.editor.Value(), " ") + if len(words) > 0 { + lastWord := words[len(words)-1] + lastWord = strings.TrimSpace(lastWord) + initialValue = lastWord + "/" } - updated, cmd := a.completions.Update( - app.CompletionDialogTriggerdMsg{ - InitialValue: initialValue, - }, - ) - a.completions = updated.(dialog.CompletionDialog) - cmds = append(cmds, cmd) - - updated, cmd = a.completions.Update(msg) - a.completions = updated.(dialog.CompletionDialog) - cmds = append(cmds, cmd) - - updated, cmd = a.editor.Update(msg) - a.editor = updated.(chat.EditorComponent) - cmds = append(cmds, cmd) - return a, tea.Sequence(cmds...) } + + updated, cmd := a.completions.Update( + app.CompletionDialogTriggerdMsg{ + InitialValue: initialValue, + }, + ) + a.completions = updated.(dialog.CompletionDialog) + cmds = append(cmds, cmd) + + updated, cmd = a.completions.Update(msg) + a.completions = updated.(dialog.CompletionDialog) + cmds = append(cmds, cmd) + + updated, cmd = a.editor.Update(msg) + a.editor = updated.(chat.EditorComponent) + cmds = append(cmds, cmd) + return a, tea.Sequence(cmds...) } if a.showCompletionDialog { - switch msg.String() { + switch keyString { case "tab", "enter", "esc", "ctrl+c": context, contextCmd := a.completions.Update(msg) a.completions = context.(dialog.CompletionDialog) |
