Skip to content

Commit

Permalink
feat: support inline input restore (#4345)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet authored Feb 7, 2025
1 parent 7fbe3bc commit 512420a
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ export class AIInlineContentWidget extends ReactInlineContentWidget {
super(editor);

this.aiNativeContextKey = this.injector.get(AINativeContextKey, [this.editor.contextKeyService]);
this.addDispose(
this.editor.onDidLayoutChange(() => {
if (this.isOutOfArea()) {
this.dispose();
}
}),
);
}

public launchChatStatus(status: EInlineChatStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ interface IInlineInputWidgetRenderProps {
onInteractiveInputSend?: (value: string) => void;
onChatStatus: Event<EInlineChatStatus>;
onResultClick: (k: EResultKind) => void;
onValueChange?: (value: string) => void;
}

const InlineInputWidgetRender = (props: IInlineInputWidgetRenderProps) => {
const { defaultValue, onClose, onInteractiveInputSend, onLayoutChange, onChatStatus, onResultClick } = props;
const { defaultValue, onClose, onInteractiveInputSend, onLayoutChange, onChatStatus, onResultClick, onValueChange } =
props;
const [status, setStatus] = useState<EInlineChatStatus>(EInlineChatStatus.READY);
const aiNativeConfigService = useInjectable<AINativeConfigService>(AINativeConfigService);

Expand Down Expand Up @@ -69,6 +71,7 @@ const InlineInputWidgetRender = (props: IInlineInputWidgetRenderProps) => {
<InteractiveInput
autoFocus
defaultValue={defaultValue}
onValueChange={onValueChange}
onHeightChange={(height) => onLayoutChange(height)}
size='small'
placeholder={localize('aiNative.inline.chat.input.placeholder.default')}
Expand All @@ -82,16 +85,19 @@ const InlineInputWidgetRender = (props: IInlineInputWidgetRenderProps) => {
};

@Injectable({ multiple: true })
export class InlineInputChatWidget extends AIInlineContentWidget {
export class InlineInputWidget extends AIInlineContentWidget {
allowEditorOverflow = true;
positionPreference = [ContentWidgetPositionPreference.ABOVE];

protected readonly _onInteractiveInputValue = new Emitter<string>();
public readonly onInteractiveInputValue = this._onInteractiveInputValue.event;
protected readonly _onSend = new Emitter<string>();
public readonly onSend = this._onSend.event;

protected readonly _onClose = new Emitter<void>();
public readonly onClose = this._onClose.event;

protected readonly _onValueChange = new Emitter<string>();
public readonly onValueChange = this._onValueChange.event;

constructor(protected readonly editor: IMonacoCodeEditor, protected readonly defaultValue?: string) {
super(editor);
}
Expand All @@ -115,9 +121,12 @@ export class InlineInputChatWidget extends AIInlineContentWidget {
onLayoutChange={() => {
this.editor.layoutContentWidget(this);
}}
onValueChange={(value) => {
this._onValueChange.fire(value);
}}
onInteractiveInputSend={(value) => {
this.launchChatStatus(EInlineChatStatus.THINKING);
this._onInteractiveInputValue.fire(value);
this._onSend.fire(value);
}}
onResultClick={(k: EResultKind) => {
this._onResultClick.fire(k);
Expand Down
Loading

1 comment on commit 512420a

@opensumi
Copy link
Contributor

@opensumi opensumi bot commented on 512420a Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Next publish successful!

3.7.1-next-1738922480.0

Please sign in to comment.