Skip to content

Commit 09172c7

Browse files
authored
Syntax module: highlighting should not focus editor if it's not focused (T1248083) (#132)
1 parent 39dc944 commit 09172c7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

modules/syntax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class Syntax extends Module {
238238
container.highlight(this.highlightBlot, force);
239239
});
240240
this.quill.update(Quill.sources.SILENT);
241-
if (range != null) {
241+
if (range != null && this.quill.hasFocus()) {
242242
this.quill.setSelection(range, Quill.sources.SILENT);
243243
}
244244
}

test/unit/modules/syntax.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ describe('Syntax', function () {
287287
);
288288
});
289289

290+
it('should not call selection change if editor is not focused to not refocus (T1233316)', function () {
291+
this.quill.setSelection(1, 1);
292+
this.quill.root.blur();
293+
294+
const setSelectionSpy = spyOn(this.quill, 'setSelection');
295+
this.quill.getModule('syntax').highlight();
296+
297+
expect(setSelectionSpy).not.toHaveBeenCalled();
298+
setSelectionSpy.calls.reset();
299+
});
300+
290301
describe('allowedChildren', function () {
291302
beforeAll(function () {
292303
SyntaxCodeBlock.allowedChildren.push(BoldBlot);

0 commit comments

Comments
 (0)