Skip to content

Preserve draft text when navigating command history with arrow keys#581

Open
Redth wants to merge 1 commit intomainfrom
fix/history-draft-preservation
Open

Preserve draft text when navigating command history with arrow keys#581
Redth wants to merge 1 commit intomainfrom
fix/history-draft-preservation

Conversation

@Redth
Copy link
Copy Markdown
Collaborator

@Redth Redth commented Apr 10, 2026

Problem

Pressing Up Arrow in the chat input replaces the current draft with a previous sent message. Pressing Down Arrow back to the live position returns an empty string — the original draft is permanently lost.

This is a standard shell-history UX expectation: bash, zsh, and fish all stash the in-progress line when entering history mode and restore it on return.

Fix

Added a draft slot to CommandHistory:

  • On first Up navigation: stashes the current input text in _draft
  • On navigating Down past the newest entry: restores _draft instead of returning ""
  • On Add() (message sent): clears _draft

Changes

File What
CommandHistory.cs Added _draft field; Navigate() accepts optional currentText param
Dashboard.razor (JS) Passes ta.value to JsNavigateHistory
Dashboard.razor (C#) Forwards currentText to hist.Navigate()
CommandHistoryTests.cs 4 new tests (14 total, all passing)

Testing

  • dotnet test --filter CommandHistoryTests14/14 passed
  • Draft preserved through full up→down cycle
  • Empty draft preserved correctly
  • Draft cleared when message is sent
  • Existing history navigation behavior unchanged

When pressing Up arrow in the chat input, the current draft text was
permanently lost — pressing Down arrow back to the live position returned
an empty string instead of the original draft.

Added a draft slot to CommandHistory that stashes the current input text
on the first Up navigation and restores it when the user navigates back
down past the newest history entry. The draft is cleared when a message
is sent (Add).

Changes:
- CommandHistory: added _draft field, Navigate accepts optional currentText
- Dashboard.razor JS: passes ta.value to JsNavigateHistory
- Dashboard.razor C#: forwards currentText to hist.Navigate
- CommandHistoryTests: 4 new tests (14 total, all passing)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant