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

feat(inline-diff): support hide accpet widget #4066

Merged
merged 2 commits into from
Oct 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions packages/ai-native/src/browser/ai-core.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,20 +491,6 @@ export class AINativeBrowserContribution
args: false,
when: `editorFocus && ${InlineChatIsVisible.raw}`,
});
keybindings.registerKeybinding({
command: AI_INLINE_DIFF_PARTIAL_EDIT.id,
keybinding: 'ctrl+y',
args: true,
priority: 100,
when: `editorTextFocus && ${InlineDiffPartialEditsIsVisible.raw}`,
});
keybindings.registerKeybinding({
command: AI_INLINE_DIFF_PARTIAL_EDIT.id,
keybinding: 'ctrl+n',
args: false,
priority: 100,
when: `editorTextFocus && ${InlineDiffPartialEditsIsVisible.raw}`,
});

if (this.inlineChatFeatureRegistry.getInteractiveInputHandler()) {
keybindings.registerKeybinding(
Expand Down Expand Up @@ -538,5 +524,20 @@ export class AINativeBrowserContribution
);
}
}

keybindings.registerKeybinding({
command: AI_INLINE_DIFF_PARTIAL_EDIT.id,
keybinding: 'ctrl+y',
args: true,
priority: 100,
when: `editorTextFocus && ${InlineDiffPartialEditsIsVisible.raw}`,
});
keybindings.registerKeybinding({
command: AI_INLINE_DIFF_PARTIAL_EDIT.id,
keybinding: 'ctrl+n',
args: false,
priority: 100,
when: `editorTextFocus && ${InlineDiffPartialEditsIsVisible.raw}`,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import { InlineDiffWidget } from './inline-diff-widget';

export interface IDiffPreviewerOptions {
disposeWhenEditorClosed: boolean;
/**
* 是否隐藏接受部分编辑的 widget,用于只展示 diff 的场景
*/
hideAcceptPartialEditWidget?: boolean;
}

export interface IInlineDiffPreviewerNode extends IDisposable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr

setPreviewerOptions(options: IDiffPreviewerOptions): void {
this.previewerOptions = options;

this.livePreviewDiffDecorationModel.setPreviewerOptions({
partialEditWidgetOptions: {
hideAcceptPartialEditWidget: options.hideAcceptPartialEditWidget,
},
});
bytemain marked this conversation as resolved.
Show resolved Hide resolved
}

initialize(selection: Selection): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ const PartialEditComponent = (props: {
);
};

export interface IPartialEditWidgetOptions {
/**
* In some case, we don't want to show the accept and reject button
*/
hideAcceptPartialEditWidget?: boolean;
}

@Injectable({ multiple: true })
export class AcceptPartialEditWidget extends ReactInlineContentWidget {
static ID = 'AcceptPartialEditWidgetID';
Expand All @@ -142,6 +149,10 @@ export class AcceptPartialEditWidget extends ReactInlineContentWidget {

positionPreference = [ContentWidgetPositionPreference.EXACT];

constructor(protected readonly editor: ICodeEditor, protected editWidgetOptions?: IPartialEditWidgetOptions) {
super(editor);
}

public addedLinesCount: number = 0;
public deletedLinesCount: number = 0;
public status: IWidgetStatus = 'pending';
Expand All @@ -166,6 +177,10 @@ export class AcceptPartialEditWidget extends ReactInlineContentWidget {
}

public renderView(): React.ReactNode {
if (this.editWidgetOptions?.hideAcceptPartialEditWidget) {
return;
}

const keyStrings = this.getSequenceKeyStrings();
if (!keyStrings) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
AddedRangeDecoration,
EPartialEdit,
IPartialEditEvent,
IPartialEditWidgetOptions,
IRemovedWidgetState,
IRemovedZoneWidgetOptions,
ITextLinesTokens,
Expand All @@ -53,6 +54,10 @@ export interface ITotalCodeInfo {
unresolvedChangedLinesCount: number;
}

export interface IModelOptions {
partialEditWidgetOptions?: IPartialEditWidgetOptions;
}

@Injectable({ multiple: true })
export class LivePreviewDiffDecorationModel extends Disposable {
@Autowired(INJECTOR_TOKEN)
Expand All @@ -76,6 +81,10 @@ export class LivePreviewDiffDecorationModel extends Disposable {
public readonly onPartialEditWidgetListChange: Event<AcceptPartialEditWidget[]> =
this._onPartialEditWidgetListChange.event;

protected options: IModelOptions = {
partialEditWidgetOptions: {},
};

protected model: ITextModel;

// Parts that require snapshots
Expand Down Expand Up @@ -575,7 +584,10 @@ export class LivePreviewDiffDecorationModel extends Disposable {
}

private createPartialEditWidget(lineNumber: number): AcceptPartialEditWidget {
const acceptPartialEditWidget = this.injector.get(AcceptPartialEditWidget, [this.monacoEditor]);
const acceptPartialEditWidget = this.injector.get(AcceptPartialEditWidget, [
this.monacoEditor,
this.options.partialEditWidgetOptions,
]);
acceptPartialEditWidget.show({ position: { lineNumber, column: 1 } });

const disposable = acceptPartialEditWidget.onDispose(() => {
Expand Down Expand Up @@ -702,4 +714,8 @@ export class LivePreviewDiffDecorationModel extends Disposable {
}
}
}

setPreviewerOptions(options: IModelOptions) {
this.options = options;
}
}
Loading