Skip to content

Commit

Permalink
Fix cursor in wrong place when navigating backwards (#229470)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens authored Sep 24, 2024
1 parent 2a88ead commit 325e2cd
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/vs/workbench/contrib/chat/browser/chatInputPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,24 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
this.inHistoryNavigation = false;

this._onDidLoadInputState.fire(historyEntry.state);

const model = this._inputEditor.getModel();
if (!model) {
return;
}

if (previous) {
// Set cursor to the end of the first view line, so if wrapped, it's the point where the line wraps
const endOfFirstLine = this._inputEditor._getViewModel()?.getLineLength(1) ?? 1;
this._inputEditor.setPosition({ lineNumber: 1, column: endOfFirstLine });
} else {
const model = this._inputEditor.getModel();
if (!model) {
return;
const endOfFirstViewLine = this._inputEditor._getViewModel()?.getLineLength(1) ?? 1;
const endOfFirstModelLine = model.getLineLength(1);
if (endOfFirstViewLine === endOfFirstModelLine) {
// Not wrapped - set cursor to the end of the first line
this._inputEditor.setPosition({ lineNumber: 1, column: endOfFirstViewLine + 1 });
} else {
// Wrapped - set cursor one char short of the end of the first view line.
// If it's after the next character, the cursor shows on the second line.
this._inputEditor.setPosition({ lineNumber: 1, column: endOfFirstViewLine });
}

} else {
this._inputEditor.setPosition(getLastPosition(model));
}
}
Expand Down

0 comments on commit 325e2cd

Please sign in to comment.