Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add commands to navigate between hunks #205293

Merged
merged 1 commit into from
Feb 15, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ export abstract class ZoneWidget implements IHorizontalSashLayoutProvider {
this.editor.changeViewZones(accessor => {
accessor.layoutZone(this._viewZone!.id);
});
this._positionMarkerId.set([{
range: Range.isIRange(rangeOrPos) ? rangeOrPos : Range.fromPositions(rangeOrPos),
options: ModelDecorationOptions.EMPTY
}]);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ registerAction2(InlineChatActions.DiscardAction);
registerAction2(InlineChatActions.DiscardToClipboardAction);
registerAction2(InlineChatActions.DiscardUndoToNewFileAction);
registerAction2(InlineChatActions.CancelSessionAction);
registerAction2(InlineChatActions.MoveToNextHunk);
registerAction2(InlineChatActions.MoveToPreviousHunk);

registerAction2(InlineChatActions.ArrowOutUpAction);
registerAction2(InlineChatActions.ArrowOutDownAction);
Expand Down
40 changes: 40 additions & 0 deletions src/vs/workbench/contrib/inlineChat/browser/inlineChatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,46 @@ export class ConfigureInlineChatAction extends AbstractInlineChatAction {
}
}

export class MoveToNextHunk extends AbstractInlineChatAction {

constructor() {
super({
id: 'inlineChat.moveToNextHunk',
title: localize2('moveToNextHunk', 'Move to Next Change'),
precondition: CTX_INLINE_CHAT_VISIBLE,
f1: true,
keybinding: {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyCode.F7
}
});
}

override runInlineChatCommand(accessor: ServicesAccessor, ctrl: InlineChatController, editor: ICodeEditor, ...args: any[]): void {
ctrl.moveHunk(true);
}
}

export class MoveToPreviousHunk extends AbstractInlineChatAction {

constructor() {
super({
id: 'inlineChat.moveToPreviousHunk',
title: localize2('moveToPreviousHunk', 'Move to Previous Change'),
f1: true,
precondition: CTX_INLINE_CHAT_VISIBLE,
keybinding: {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.Shift | KeyCode.F7
}
});
}

override runInlineChatCommand(accessor: ServicesAccessor, ctrl: InlineChatController, editor: ICodeEditor, ...args: any[]): void {
ctrl.moveHunk(false);
}
}

export class CopyRecordings extends AbstractInlineChatAction {

constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,11 @@ export class InlineChatController implements IEditorContribution {
return this._zone.value.widget.hasFocus();
}

moveHunk(next: boolean) {
this.focus();
this._strategy?.move?.(next);
}

populateHistory(up: boolean) {
const len = InlineChatController._promptHistory.length;
if (len === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export abstract class EditModeStrategy {

abstract renderChanges(response: ReplyResponse): Promise<Position | undefined>;

move?(next: boolean): void;

abstract hasFocus(): boolean;

getWholeRangeDecoration(): IModelDeltaDecoration[] {
Expand Down Expand Up @@ -401,6 +403,7 @@ type HunkDisplayData = {
discardHunk: () => void;
toggleDiff?: () => any;
remove(): void;
move: (next: boolean) => void;
};


Expand Down Expand Up @@ -429,7 +432,6 @@ export class LiveStrategy extends EditModeStrategy {

private readonly _progressiveEditingDecorations: IEditorDecorationsCollection;


override acceptHunk: () => Promise<void> = () => super.acceptHunk();
override discardHunk: () => Promise<void> = () => super.discardHunk();

Expand Down Expand Up @@ -617,6 +619,33 @@ export class LiveStrategy extends EditModeStrategy {
});
};

const move = (next: boolean) => {
assertType(widgetData);

const candidates: Position[] = [];
for (const item of this._session.hunkData.getInfo()) {
if (item.getState() === HunkState.Pending) {
candidates.push(item.getRangesN()[0].getStartPosition().delta(-1));
}
}
if (candidates.length < 2) {
return;
}
for (let i = 0; i < candidates.length; i++) {
if (candidates[i].equals(widgetData.position)) {
let newPos: Position;
if (next) {
newPos = candidates[(i + 1) % candidates.length];
} else {
newPos = candidates[(i + candidates.length - 1) % candidates.length];
}
this._zone.updatePositionAndHeight(newPos);
renderHunks();
break;
}
}
};

const zoneLineNumber = this._zone.position!.lineNumber;
const myDistance = zoneLineNumber <= hunkRanges[0].startLineNumber
? hunkRanges[0].startLineNumber - zoneLineNumber
Expand All @@ -632,6 +661,7 @@ export class LiveStrategy extends EditModeStrategy {
discardHunk,
toggleDiff: !hunkData.isInsertion() ? toggleDiff : undefined,
remove,
move
};

this._hunkDisplayData.set(hunkData, data);
Expand Down Expand Up @@ -674,6 +704,7 @@ export class LiveStrategy extends EditModeStrategy {
this.toggleDiff = widgetData.toggleDiff;
this.acceptHunk = async () => widgetData!.acceptHunk();
this.discardHunk = async () => widgetData!.discardHunk();
this.move = next => widgetData!.move(next);

} else if (this._hunkDisplayData.size > 0) {
// everything accepted or rejected
Expand Down