Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export class SubmitInlineChatInputAction extends AbstractInlineChatAction {
override runInlineChatCommand(_accessor: ServicesAccessor, ctrl: InlineChatController, _editor: ICodeEditor, ..._args: unknown[]): void {
const value = ctrl.inputWidget.value;
if (value) {
ctrl.inputWidget.addToHistory(value);
ctrl.inputWidget.hide();
ctrl.run({ message: value, autoSend: true });
}
Expand Down Expand Up @@ -591,6 +592,9 @@ export class QueueInChatAction extends AbstractInlineChatAction {
}

const value = ctrl.inputWidget.value;
if (value) {
ctrl.inputWidget.addToHistory(value);
}
ctrl.inputWidget.hide();
if (!value) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ActionBar, ActionsOrientation } from '../../../../base/browser/ui/actio
import { BaseActionViewItem } from '../../../../base/browser/ui/actionbar/actionViewItems.js';
import { DomScrollableElement } from '../../../../base/browser/ui/scrollbar/scrollableElement.js';
import { Codicon } from '../../../../base/common/codicons.js';
import { HistoryNavigator2 } from '../../../../base/common/history.js';
import { MarkdownString } from '../../../../base/common/htmlContent.js';
import { KeyCode } from '../../../../base/common/keyCodes.js';
import { Disposable, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js';
Expand Down Expand Up @@ -62,6 +63,7 @@ export class InlineChatInputWidget extends Disposable {
private _anchorLeft: number = 0;
private _anchorAbove: boolean = false;

private readonly _historyNavigator = new HistoryNavigator2<string>([''], 50);

constructor(
private readonly _editorObs: ObservableCodeEditor,
Expand Down Expand Up @@ -214,15 +216,28 @@ export class InlineChatInputWidget extends Disposable {
this._store.add(this._input.onDidBlurEditorText(() => inputWidgetFocused.set(false)));
this._store.add(toDisposable(() => inputWidgetFocused.reset()));

// Handle key events: ArrowDown to move to actions
// Handle key events: ArrowUp/ArrowDown for history navigation and action bar focus
this._store.add(this._input.onKeyDown(e => {
if (e.keyCode === KeyCode.DownArrow && !actionBar.isEmpty()) {
const model = this._input.getModel();
if (e.keyCode === KeyCode.UpArrow) {
const position = this._input.getPosition();
if (position && position.lineNumber === model.getLineCount()) {
if (position && position.lineNumber === 1) {
this._showPreviousHistoryValue();
e.preventDefault();
e.stopPropagation();
actionBar.focus(0);
}
} else if (e.keyCode === KeyCode.DownArrow) {
const model = this._input.getModel();
const position = this._input.getPosition();
if (position && position.lineNumber === model.getLineCount()) {
if (!this._historyNavigator.isAtEnd()) {
this._showNextHistoryValue();
e.preventDefault();
e.stopPropagation();
} else if (!actionBar.isEmpty()) {
e.preventDefault();
e.stopPropagation();
actionBar.focus(0);
}
}
Comment thread
jrieken marked this conversation as resolved.
}
}));
Expand Down Expand Up @@ -254,6 +269,27 @@ export class InlineChatInputWidget extends Disposable {
return this._input.getModel().getValue().trim();
}

addToHistory(value: string): void {
this._historyNavigator.replaceLast(value);
this._historyNavigator.add('');
}

private _showPreviousHistoryValue(): void {
if (this._historyNavigator.isAtEnd()) {
this._historyNavigator.replaceLast(this._input.getModel().getValue());
}
const value = this._historyNavigator.previous();
this._input.getModel().setValue(value);
}

private _showNextHistoryValue(): void {
if (this._historyNavigator.isAtEnd()) {
return;
}
const value = this._historyNavigator.next();
this._input.getModel().setValue(value);
}

/**
* Show the widget at the specified line.
* @param lineNumber The line number to anchor the widget to
Expand All @@ -263,6 +299,9 @@ export class InlineChatInputWidget extends Disposable {
show(lineNumber: number, left: number, anchorAbove: boolean, placeholder: string, value?: string): void {
this._showStore.clear();

// Reset history cursor to the end (current uncommitted text)
this._historyNavigator.resetCursor();

// Clear input state
this._input.updateOptions({ wordWrap: 'off', placeholder });
this._input.getModel().setValue(value ?? '');
Comment thread
jrieken marked this conversation as resolved.
Expand Down
Loading