Skip to content

Commit 9ade524

Browse files
authored
fix: compare incoming value with modal's value (#887)
1 parent 555abe1 commit 9ade524

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/services/workbench/__tests__/editorService.test.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,12 @@ describe('Test EditorService', () => {
208208
expect(groups?.length).toBe(1);
209209

210210
const setValFn = jest.fn();
211+
const getValFn = jest.fn();
211212
(MonacoEditor.getModel as jest.Mock).mockImplementation(() => ({
212213
setValue: setValFn,
214+
getValue: getValFn,
213215
}));
216+
214217
act(() => {
215218
editor.updateTab({
216219
id: mockTab.id,

src/services/workbench/editorService.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'reflect-metadata';
22
import { singleton, container } from 'tsyringe';
3-
import { cloneDeep } from 'lodash';
3+
import { cloneDeep, isString } from 'lodash';
44
import { Component } from 'mo/react';
55
import {
66
EditorModel,
@@ -337,8 +337,13 @@ export class EditorService
337337
const model = MonacoEditor.getModel(
338338
Uri.parse(tab.id.toString())
339339
);
340-
if (model) {
341-
model.setValue(editorValue || '');
340+
const currentValue = model?.getValue();
341+
if (
342+
model &&
343+
isString(editorValue) &&
344+
currentValue !== editorValue
345+
) {
346+
model.setValue(editorValue);
342347
}
343348
this.updateGroup(groupId, group);
344349

@@ -362,8 +367,13 @@ export class EditorService
362367
const model = MonacoEditor.getModel(
363368
Uri.parse(tab.id.toString())
364369
);
365-
if (model) {
366-
model.setValue(editorValue || '');
370+
const currentValue = model?.getValue();
371+
if (
372+
model &&
373+
isString(editorValue) &&
374+
currentValue !== editorValue
375+
) {
376+
model.setValue(editorValue);
367377
}
368378
});
369379

0 commit comments

Comments
 (0)