Skip to content

Commit 6d7e133

Browse files
authored
fix: inline input edit operations (#3876)
1 parent 9ad02d5 commit 6d7e133

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

packages/ai-native/src/browser/widget/inline-input/inline-input.handler.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
IDisposable,
88
InlineChatFeatureRegistryToken,
99
ReplyResponse,
10+
RunOnceScheduler,
1011
} from '@opensumi/ide-core-common';
1112
import { IEditor } from '@opensumi/ide-editor/lib/browser';
1213
import * as monaco from '@opensumi/ide-monaco';
@@ -86,25 +87,28 @@ export class InlineInputHandler extends Disposable {
8687

8788
controller.listen();
8889

90+
let latestContent: string | undefined;
91+
const schedulerEdit: RunOnceScheduler = this.registerDispose(
92+
new RunOnceScheduler(() => {
93+
const range = decoration.getRange(0);
94+
95+
if (range && latestContent) {
96+
model.pushEditOperations(null, [EditOperation.replace(range, latestContent)], () => null);
97+
}
98+
}, 16 * 12.5),
99+
);
100+
89101
inputDisposable.addDispose([
90102
controller.onData(async (data) => {
91103
if (!ReplyResponse.is(data)) {
92104
return;
93105
}
94106

95-
const { message } = data;
96-
97-
model.pushEditOperations(
98-
null,
99-
[
100-
// 直接用 EditOperation.insert 会有问题
101-
{
102-
range: monaco.Range.fromPositions(decoration.getRange(0)!.getEndPosition()),
103-
text: message,
104-
},
105-
],
106-
() => null,
107-
);
107+
latestContent = data.message;
108+
109+
if (!schedulerEdit.isScheduled()) {
110+
schedulerEdit.schedule();
111+
}
108112
}),
109113
controller.onError((error) => {
110114
widget.launchChatStatus(EInlineChatStatus.ERROR);

0 commit comments

Comments
 (0)