Skip to content

Centralize Key Binding Logic and Refactor#1969

Closed
Lee-WonJun wants to merge 5 commits intogoogle-gemini:mainfrom
Lee-WonJun:feature/issue-1950-stage-1-keymatcher
Closed

Centralize Key Binding Logic and Refactor#1969
Lee-WonJun wants to merge 5 commits intogoogle-gemini:mainfrom
Lee-WonJun:feature/issue-1950-stage-1-keymatcher

Conversation

@Lee-WonJun
Copy link
Copy Markdown
Contributor

TLDR

Centralized key binding logic into a single place to improve maintainability and consistency. Hardcoded key combinations like Ctrl+L and Ctrl+P have been moved to the keyMatchers object in keyBindings.ts. This lays the groundwork for future support for user-defined key bindings.

Dive Deeper

Previously, key bindings were scattered across different files like App.tsx and InputPrompt.tsx, making them hard to manage. This change introduces:

  • Centralized key binding definitions in keyBindings.ts under keyMatchers
  • Meaningful action names for each key binding (e.g., showErrorDetails, toggleToolDescriptions)
  • Reduced code duplication and increased consistency

A few exceptions remain:

  • Ctrl+X and Ctrl+E interactions with external editors involve complex logic, so the original code is left untouched
  • Low-level keys managed by text-buffer are also left unchanged, as improvements have already been made by the gemini-cli team (e.g., handling del vs backspace)

Reviewer Test Plan

Confirm that all previous key bindings still work as expected.

Testing Matrix

🍏 🪟 🐧
npm run O
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

#1950

This PR presents a sample / illustrative approach to centralizing key bindings.
It’s not meant to dictate the only possible solution—if the original structure (e.g., keeping bindings directly in terminal-style components) was intentionally chosen, please feel free to point that out.

@Lee-WonJun Lee-WonJun requested a review from a team as a code owner June 26, 2025 15:55
@umairidris
Copy link
Copy Markdown
Contributor

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes key binding definitions, improving maintainability. However, duplicated key binding handling logic in InputPrompt.tsx needs refactoring to ensure consistency.

Comment on lines 237 to 251
// Ctrl+L (Clear Screen)
if (key.ctrl && input === 'l') {
if (keyMatchers.clearScreen(key, input)) {
onClearScreen();
return;
}
// Ctrl+P (History Up)
if (key.ctrl && input === 'p' && !completion.showSuggestions) {
if (keyMatchers.historyUp(key, input) && !completion.showSuggestions) {
inputHistory.navigateUp();
return;
}
// Ctrl+N (History Down)
if (key.ctrl && input === 'n' && !completion.showSuggestions) {
if (keyMatchers.historyDown(key, input) && !completion.showSuggestions) {
inputHistory.navigateDown();
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The duplicated key binding handling logic for clearScreen, historyUp, and historyDown in the useInput hook introduces a potential inconsistency. If a key binding's behavior needs modification, changes in one location might be missed in the other, leading to unexpected behavior. Refactor useInput to consolidate these handlers into a single location to ensure consistent behavior. This is a high severity issue because inconsistent keybindings would be a confusing user experience.

@gemini-cli gemini-cli bot added kind/documentation priority/p2 Important but can be addressed in a future release. labels Jul 3, 2025
@mattKorwel
Copy link
Copy Markdown
Collaborator

Hi @Lee-WonJun I'm going back through some stale pR's. I love the refactoring here and think it lceans things up nicely. That said there are a good number of merge conflicts and some new functionaly that needs included. I'm going to close this out but please feel free to reoopen and address the conflicts and tag me if you'd like to move it forward. Either way thanks for the contribution.

@mattKorwel mattKorwel closed this Aug 1, 2025
@Lee-WonJun
Copy link
Copy Markdown
Contributor Author

Lee-WonJun commented Aug 1, 2025

I think it would be better to implement this in a separate PR. Also, from what I briefly saw, it looks like there's already an epic issue related to the config component: #5153. So I assume it's already being worked on elsewhere.

Thank you for saying you like my PR style — I appreciate it. Anyway, I'll try to create a separate PR myself sometime soon.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Thanks for the update, @Lee-WonJun. It's understandable that addressing merge conflicts and new functionality might be better suited for a new PR, especially with an existing epic issue. Your refactoring work here is indeed valuable and sets a great foundation. Please feel free to tag me if you create a new PR, and I'll be happy to review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants