Skip to content
This repository was archived by the owner on Jun 13, 2022. It is now read-only.

Commit 5e480d7

Browse files
authored
Merge pull request #234 from UziTech/grammar-substring
fix: fix grammar condition when substring of editor grammar
2 parents a118f42 + 3618f34 commit 5e480d7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/flex-tool-bar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ export default {
774774
grammarCondition(condition) {
775775
this.conditionTypes.grammar = true;
776776
return this.reversableStringCondition(condition, (c) => {
777-
return this.activeItem && this.activeItem.grammar && this.activeItem.grammar.includes(c.toLowerCase());
777+
return this.activeItem && this.activeItem.grammar && this.activeItem.grammar === c.toLowerCase();
778778
});
779779
},
780780

spec/flex-tool-bar-spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,24 @@ describe('FlexToolBar', function () {
304304
expect(match).toBe(true);
305305
expect(notMatch).toBe(false);
306306
});
307+
308+
it('should not match substring', function () {
309+
flexToolBar.activeItem.grammar = 'cpp';
310+
311+
const match = flexToolBar.checkConditions({grammar: 'c'});
312+
const notMatch = flexToolBar.checkConditions({grammar: '!c'});
313+
expect(match).toBe(false);
314+
expect(notMatch).toBe(true);
315+
});
316+
317+
it('should not match grammar substring', function () {
318+
flexToolBar.activeItem.grammar = 'c';
319+
320+
const match = flexToolBar.checkConditions({grammar: 'cpp'});
321+
const notMatch = flexToolBar.checkConditions({grammar: '!cpp'});
322+
expect(match).toBe(false);
323+
expect(notMatch).toBe(true);
324+
});
307325
});
308326

309327
describe('pattern condition', function () {

0 commit comments

Comments
 (0)