Skip to content

Add terminal-native input navigation and editing#79

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/improve-input-navigation
Draft

Add terminal-native input navigation and editing#79
Copilot wants to merge 4 commits intomainfrom
copilot/improve-input-navigation

Conversation

Copy link

Copilot AI commented Jan 30, 2026

The custom input handler only supported append-only text entry with backspace deletion and history navigation. No cursor positioning, word-level navigation, or standard terminal editing shortcuts.

Implementation

Cursor tracking

  • Added cursor_position state variable
  • Implements character insertion at cursor (not just append)
  • All edit operations maintain correct cursor position

Navigation

  • Character: Left/Right arrows, Home/End, Ctrl+A/E
  • Word: Ctrl+Left/Right, Alt+B/F (Emacs-style)
  • Helper functions find_prev_word_start() and find_next_word_start() for word boundary detection

Editing

  • Delete key
  • Ctrl+W (delete word backward)
  • Ctrl+K (kill to end of line)
  • Ctrl+U (kill to start of line)
  • Ctrl+L (clear screen)

Cursor movement helper

  • move_cursor_to() handles both forward and backward movement
  • Correctly handles newlines in both directions (MoveUp/MoveDown + column positioning)
  • All operations use this helper for consistency

Technical notes

Multi-line input support required special handling when moving cursor backward across newlines - must calculate previous line length to set correct column position. All manual MoveLeft loops replaced with the helper to avoid cursor desync.

// Before: only append at end
buffer.push(c);
print!("{}", c);

// After: insert at cursor with proper redraw
let chars: Vec<char> = buffer.chars().collect();
let before: String = chars.iter().take(cursor_position).collect();
let after: String = chars.iter().skip(cursor_position).collect();
buffer = format!("{}{}{}", before, c, after);
print!("{}", c);
if !after.is_empty() {
    print!("{}", after.replace('\n', "\r\n"));
    self.move_cursor_to(&after, after.chars().count(), 0)?;
}
cursor_position += 1;
Original prompt

Inprove the input.rs, and make it feel like terminal native way to navigate while giving inputs


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 30, 2026 06:37
Co-Authored-By: Paws <noreply@pawscode.dev>

Co-authored-by: manthanabc <48511543+manthanabc@users.noreply.github.com>
Co-Authored-By: Paws <noreply@pawscode.dev>

Co-authored-by: manthanabc <48511543+manthanabc@users.noreply.github.com>
- Renamed find_next_word_end to find_next_word_start for accuracy
- Fixed all manual cursor movement to use move_cursor_to helper
- Enhanced move_cursor_to to handle backwards movement across newlines
- Removed redundant character loops that didn't handle newlines

Co-Authored-By: Paws <noreply@pawscode.dev>

Co-authored-by: manthanabc <48511543+manthanabc@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve terminal-like input handling in input.rs Add terminal-native input navigation and editing Jan 30, 2026
Copilot AI requested a review from manthanabc January 30, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants