Skip to content
Merged
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 @@ -7,6 +7,7 @@ import {
IDisposable,
InlineChatFeatureRegistryToken,
ReplyResponse,
RunOnceScheduler,
} from '@opensumi/ide-core-common';
import { IEditor } from '@opensumi/ide-editor/lib/browser';
import * as monaco from '@opensumi/ide-monaco';
Expand Down Expand Up @@ -86,25 +87,28 @@ export class InlineInputHandler extends Disposable {

controller.listen();

let latestContent: string | undefined;
const schedulerEdit: RunOnceScheduler = this.registerDispose(
new RunOnceScheduler(() => {
const range = decoration.getRange(0);

if (range && latestContent) {
model.pushEditOperations(null, [EditOperation.replace(range, latestContent)], () => null);
}
}, 16 * 12.5),
);

inputDisposable.addDispose([
controller.onData(async (data) => {
if (!ReplyResponse.is(data)) {
return;
}

const { message } = data;

model.pushEditOperations(
null,
[
// 直接用 EditOperation.insert 会有问题
{
range: monaco.Range.fromPositions(decoration.getRange(0)!.getEndPosition()),
text: message,
},
],
() => null,
);
latestContent = data.message;

if (!schedulerEdit.isScheduled()) {
schedulerEdit.schedule();
}
}),
controller.onError((error) => {
widget.launchChatStatus(EInlineChatStatus.ERROR);
Expand Down