Skip to content

Fix: Up arrow on wrapped lines navigates history instead of moving cursor#273833

Merged
alexdima merged 2 commits intomainfrom
copilot/fix-cursor-navigation-issue
Oct 29, 2025
Merged

Fix: Up arrow on wrapped lines navigates history instead of moving cursor#273833
alexdima merged 2 commits intomainfrom
copilot/fix-cursor-navigation-issue

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

Pressing up arrow on the second visual line of wrapped text in chat input incorrectly triggered history navigation instead of moving the cursor to the first line.

Changes

  • Cursor position detection: Changed atTop check from position.lineNumber === 1 && position.column - 1 <= viewLineLength to position.lineNumber === 1 && position.column === 1

    • History navigation now only triggers when cursor is at the absolute start (1,1)
    • Prevents false positives on wrapped portions of first model line
  • History navigation cursor positioning: Simplified navigateHistory() to always position cursor at (1,1) when navigating backwards

    • Removed complex wrapped/non-wrapped line handling
    • Ensures consistent behavior and continued history navigation on subsequent up presses
// Before: Could trigger anywhere on first visual line
const atTop = position.lineNumber === 1 && 
  position.column - 1 <= (this._inputEditor._getViewModel()?.getLineLength(1) ?? 0);

// After: Only at absolute start
const atTop = position.lineNumber === 1 && position.column === 1;

Fixes behavior where users accidentally triggered history when revising multi-line prompts.

Original prompt

This section details on the original issue you should resolve

<issue_title>Pressing up on the second line of a wrapped line will navigate chat history instead of move the cursor to the first line</issue_title>
<issue_description>Example where pressing up will navigate history instead of moving the cursor to the desired spot:

Image

Additionally I'd prefer up to not navigate history unless the cursor is at (0,0), otherwise it's too easy to accidentally trigger history when revising a prompt.</issue_description>

Comments on the Issue (you are @copilot in this section)

@roblourens We had https://github.com/microsoft/vscode-copilot/issues/13415 for this, I'll move it to this issue.

From the other issue

const atTop = position.lineNumber === 1 && position.column - 1 <= (this._inputEditor._getViewModel()?.getLineLength(1) ?? 0);

It seems like when the line is wrapped, the cursor can either appear at the end of the first line after the space, or the start of the second line, but it's actually at the same column position in those two states. Is that right? If so, how do I handle this so that 'up' will always navigate only when it appears on the first view line?

Could "arrow up" only cycle up when the cursor is at position 1, line 1?

It worked that way at one point, currently when you navigate I always put the cursor at the end of the first line. Because if you navigate to an old input and want to edit it, you most likely want to type more at the end, and that was a good compromise.

And now I'm not sure what to do, I would prefer to understand and fix the issue I mentioned. cc @hediet </comment_new>
<comment_new>@alexdima
@roblourens The logic should be if line number == 1 && column == 1 then move to the previous history entry. We should always allow the arrow up on the first line to first reach the first position before cycling to the previous suggestion.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Change cursor position check to only enable history navigation when cursor is at line 1, column 1. This prevents accidental history navigation when pressing up arrow on wrapped lines.

Co-authored-by: alexdima <5047891+alexdima@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cursor navigation on wrapped lines in chat Fix: Up arrow on wrapped lines navigates history instead of moving cursor Oct 28, 2025
Copilot AI requested a review from alexdima October 28, 2025 22:19
@alexdima alexdima marked this pull request as ready for review October 29, 2025 11:37
Copilot AI review requested due to automatic review settings October 29, 2025 11:37
@alexdima alexdima enabled auto-merge (squash) October 29, 2025 11:37
@alexdima
Copy link
Member

FYI @roblourens @justschen

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR simplifies the cursor positioning logic when navigating to previous entries in chat input history. The change ensures that navigating backwards through history always positions the cursor at the start of the input (line 1, column 1), which allows continued upward navigation without interference from cursor position checks.

Key Changes

  • Replaces complex wrapped-line cursor positioning logic with a simple cursor-to-start approach for previous history navigation
  • Updates the "at top" cursor position check to only evaluate when the cursor is at line 1, column 1
Comments suppressed due to low confidence (1)

src/vs/workbench/contrib/chat/browser/chatInputPart.ts:1038

  • The comment 'always leave cursor at the end' on line 1034 is now misleading. The setValue() method is called from navigateHistory() with transient: true, which then immediately overrides the cursor position (setting it to line 1, column 1 for previous navigation). The comment should clarify that the cursor position may be overridden by the caller, or should be removed since the behavior is no longer universal.
	setValue(value: string, transient: boolean): void {
		this.inputEditor.setValue(value);
		// always leave cursor at the end
		const model = this.inputEditor.getModel();
		if (model) {
			this.inputEditor.setPosition(getLastPosition(model));
		}

@Tyriar
Copy link
Member

Tyriar commented Oct 29, 2025

CI flake?

@alexdima alexdima merged commit 512471a into main Oct 29, 2025
43 of 60 checks passed
@alexdima alexdima deleted the copilot/fix-cursor-navigation-issue branch October 29, 2025 13:34
dmitrivMS pushed a commit that referenced this pull request Oct 29, 2025
…rsor (#273833)

* Initial plan

* Fix cursor navigation in wrapped lines

Change cursor position check to only enable history navigation when cursor is at line 1, column 1. This prevents accidental history navigation when pressing up arrow on wrapped lines.

Co-authored-by: alexdima <5047891+alexdima@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: alexdima <5047891+alexdima@users.noreply.github.com>
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Dec 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pressing up on the second line of a wrapped line will navigate chat history instead of move the cursor to the first line

4 participants