Skip to content

Commit

Permalink
fix: compare incoming value with modal's value
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-sir committed Jun 17, 2024
1 parent 555abe1 commit 96187df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/services/workbench/__tests__/editorService.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ describe('Test EditorService', () => {
expect(groups?.length).toBe(1);

const setValFn = jest.fn();
const getValFn = jest.fn();
(MonacoEditor.getModel as jest.Mock).mockImplementation(() => ({
setValue: setValFn,
getValue: getValFn,
}));

act(() => {
editor.updateTab({
id: mockTab.id,
Expand Down
20 changes: 15 additions & 5 deletions src/services/workbench/editorService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'reflect-metadata';
import { singleton, container } from 'tsyringe';
import { cloneDeep } from 'lodash';
import { cloneDeep, isString } from 'lodash';
import { Component } from 'mo/react';
import {
EditorModel,
Expand Down Expand Up @@ -337,8 +337,13 @@ export class EditorService
const model = MonacoEditor.getModel(
Uri.parse(tab.id.toString())
);
if (model) {
model.setValue(editorValue || '');
const currentValue = model?.getValue();
if (
model &&
isString(editorValue) &&
currentValue !== editorValue

Check warning on line 344 in src/services/workbench/editorService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/workbench/editorService.ts#L343-L344

Added lines #L343 - L344 were not covered by tests
) {
model.setValue(editorValue);

Check warning on line 346 in src/services/workbench/editorService.ts

View check run for this annotation

Codecov / codecov/patch

src/services/workbench/editorService.ts#L346

Added line #L346 was not covered by tests
}
this.updateGroup(groupId, group);

Expand All @@ -362,8 +367,13 @@ export class EditorService
const model = MonacoEditor.getModel(
Uri.parse(tab.id.toString())
);
if (model) {
model.setValue(editorValue || '');
const currentValue = model?.getValue();
if (
model &&
isString(editorValue) &&
currentValue !== editorValue
) {
model.setValue(editorValue);
}
});

Expand Down

0 comments on commit 96187df

Please sign in to comment.