diff --git a/packages/ai-native/src/browser/ai-core.contribution.ts b/packages/ai-native/src/browser/ai-core.contribution.ts index 260f74d00e..bf359220b8 100644 --- a/packages/ai-native/src/browser/ai-core.contribution.ts +++ b/packages/ai-native/src/browser/ai-core.contribution.ts @@ -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( @@ -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}`, + }); } } diff --git a/packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts b/packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts index e058ca588c..7f811d7c6b 100644 --- a/packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts +++ b/packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts @@ -19,6 +19,10 @@ import { InlineDiffWidget } from './inline-diff-widget'; export interface IDiffPreviewerOptions { disposeWhenEditorClosed: boolean; + /** + * 是否隐藏接受部分编辑的 widget,用于只展示 diff 的场景 + */ + hideAcceptPartialEditWidget?: boolean; } export interface IInlineDiffPreviewerNode extends IDisposable { diff --git a/packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx b/packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx index 6079b34f67..eef6b5f1cd 100644 --- a/packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx +++ b/packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx @@ -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, + }, + }); } initialize(selection: Selection): void { diff --git a/packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.component.tsx b/packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.component.tsx index a9da956097..7df8c8b1e4 100644 --- a/packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.component.tsx +++ b/packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.component.tsx @@ -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'; @@ -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'; @@ -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; diff --git a/packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx b/packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx index e067b0f6c2..4197fae4f2 100644 --- a/packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx +++ b/packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx @@ -29,6 +29,7 @@ import { AddedRangeDecoration, EPartialEdit, IPartialEditEvent, + IPartialEditWidgetOptions, IRemovedWidgetState, IRemovedZoneWidgetOptions, ITextLinesTokens, @@ -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) @@ -76,6 +81,10 @@ export class LivePreviewDiffDecorationModel extends Disposable { public readonly onPartialEditWidgetListChange: Event = this._onPartialEditWidgetListChange.event; + protected options: IModelOptions = { + partialEditWidgetOptions: {}, + }; + protected model: ITextModel; // Parts that require snapshots @@ -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(() => { @@ -702,4 +714,8 @@ export class LivePreviewDiffDecorationModel extends Disposable { } } } + + setPreviewerOptions(options: IModelOptions) { + this.options = options; + } }