Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ type appModel struct {
// Focus state
focusedPanel FocusedPanel

// keyboardEnhancements stores the last keyboard enhancements message.
// When non-nil with Flags != 0, the terminal supports key disambiguation
// (shift+enter, ctrl+i vs tab, etc.).
// keyboardEnhancements stores the last keyboard enhancements message
keyboardEnhancements *tea.KeyboardEnhancementsMsg

// keyboardEnhancementsSupported tracks whether the terminal supports keyboard enhancements
keyboardEnhancementsSupported bool

// program holds a reference to the tea.Program so that we can
// perform a full terminal release/restore cycle on focus events.
program *tea.Program
Expand Down Expand Up @@ -246,20 +247,15 @@ func (m *appModel) SetProgram(p *tea.Program) {
m.supervisor.SetProgram(p)
}

// hasKeyboardEnhancements reports whether the terminal supports keyboard
// enhancements (Kitty keyboard protocol). When true, keybindings like
// shift+enter become available.
func (m *appModel) hasKeyboardEnhancements() bool {
return m.keyboardEnhancements != nil && m.keyboardEnhancements.Flags != 0
}

// reapplyKeyboardEnhancements forwards the cached keyboard enhancements message
// to the active editor so new/replaced instances pick up the terminal's key
// disambiguation support.
// to the active chat page and editor so new/replaced instances pick up the
// terminal's key disambiguation support.
func (m *appModel) reapplyKeyboardEnhancements() {
if m.keyboardEnhancements == nil {
return
}
updated, _ := m.chatPage.Update(*m.keyboardEnhancements)
m.chatPage = updated.(chat.Page)
editorModel, _ := m.editor.Update(*m.keyboardEnhancements)
m.editor = editorModel.(editor.Editor)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 CONFIRMED: Chat page lacks keyboard enhancement tracking

The reapplyKeyboardEnhancements() method forwards the keyboard enhancements message to both the chat page and editor. However, the chat page component (pkg/tui/page/chat/chat.go) does not have a keyboardEnhancementsSupported field like the editor does.

Impact: If the chat page needs to make decisions based on keyboard enhancement support (e.g., keybinding configuration for inline editing), it won't have that information available after reapply.

Recommendation: Consider adding a keyboardEnhancementsSupported field to the chat page component, similar to the editor component.

}
Expand Down Expand Up @@ -589,10 +585,14 @@ func (m *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case tea.KeyboardEnhancementsMsg:
m.keyboardEnhancements = &msg
// Forward to editor (only component that uses it for keybinding config)
editorModel, cmd := m.editor.Update(msg)
m.keyboardEnhancementsSupported = msg.Flags != 0
// Forward to content view
updated, cmd := m.chatPage.Update(msg)
m.chatPage = updated.(chat.Page)
// Forward to editor
editorModel, editorCmd := m.editor.Update(msg)
m.editor = editorModel.(editor.Editor)
return m, cmd
return m, tea.Batch(cmd, editorCmd)

// --- Keyboard input ---
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 LIKELY: Keyboard enhancements may not reach all nested components

The code forwards KeyboardEnhancementsMsg to both chatPage and editor, then batches the commands. While the forwarding to top-level components is correct, it's unclear whether all nested components that need keyboard enhancement configuration (especially inline edit textareas within the messages component) properly receive and configure their keybindings.

Impact: Some nested UI components may not properly configure keyboard shortcuts that depend on terminal capabilities.

Recommendation: Verify that the messages component and its inline edit textarea properly handle keyboard enhancement messages.


Expand Down Expand Up @@ -1494,7 +1494,7 @@ func (m *appModel) Bindings() []key.Binding {
))

// Show newline help based on keyboard enhancement support
if m.hasKeyboardEnhancements() {
if m.keyboardEnhancementsSupported {
bindings = append(bindings, key.NewBinding(
key.WithKeys("shift+enter"),
key.WithHelp("Shift+Enter", "newline"),
Expand Down Expand Up @@ -2229,8 +2229,6 @@ func toFullscreenView(content, windowTitle string, working bool) tea.View {
view.MouseMode = tea.MouseModeCellMotion
view.BackgroundColor = styles.Background
view.WindowTitle = windowTitle
view.ReportFocus = true
view.KeyboardEnhancements.ReportEventTypes = true
if working {
view.ProgressBar = tea.NewProgressBar(tea.ProgressBarIndeterminate, 0)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 CONFIRMED: Removed view config may prevent keyboard enhancement detection

This revert removes view.ReportFocus = true and view.KeyboardEnhancements.ReportEventTypes = true from the view configuration. However, the PR also adds a new keyboardEnhancementsSupported field (line 124) that is set based on received KeyboardEnhancementsMsg messages (line 590).

The problem: If the view no longer requests keyboard enhancement events via KeyboardEnhancements.ReportEventTypes, the terminal may not send KeyboardEnhancementsMsg at all, leaving the new tracking field uninitialized or stale.

Impact: The keyboardEnhancementsSupported field may never be updated, causing the application to incorrectly assume keyboard enhancements are unavailable even when the terminal supports them.

Recommendation: Either keep view.KeyboardEnhancements.ReportEventTypes = true or verify that keyboard enhancement messages are received through another mechanism.

Expand Down
Loading