|
7 | 7 | IDisposable, |
8 | 8 | InlineChatFeatureRegistryToken, |
9 | 9 | ReplyResponse, |
| 10 | + RunOnceScheduler, |
10 | 11 | } from '@opensumi/ide-core-common'; |
11 | 12 | import { IEditor } from '@opensumi/ide-editor/lib/browser'; |
12 | 13 | import * as monaco from '@opensumi/ide-monaco'; |
@@ -86,25 +87,28 @@ export class InlineInputHandler extends Disposable { |
86 | 87 |
|
87 | 88 | controller.listen(); |
88 | 89 |
|
| 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 | + |
89 | 101 | inputDisposable.addDispose([ |
90 | 102 | controller.onData(async (data) => { |
91 | 103 | if (!ReplyResponse.is(data)) { |
92 | 104 | return; |
93 | 105 | } |
94 | 106 |
|
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 | + } |
108 | 112 | }), |
109 | 113 | controller.onError((error) => { |
110 | 114 | widget.launchChatStatus(EInlineChatStatus.ERROR); |
|
0 commit comments