From 3618f342ce6df2e6b531a7582c67608a26084522 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 25 Mar 2021 01:03:46 -0500 Subject: [PATCH] fix: fix grammar condition when substring of editor grammar --- lib/flex-tool-bar.js | 2 +- spec/flex-tool-bar-spec.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/flex-tool-bar.js b/lib/flex-tool-bar.js index fd79f08..0afe970 100644 --- a/lib/flex-tool-bar.js +++ b/lib/flex-tool-bar.js @@ -774,7 +774,7 @@ export default { grammarCondition(condition) { this.conditionTypes.grammar = true; return this.reversableStringCondition(condition, (c) => { - return this.activeItem && this.activeItem.grammar && this.activeItem.grammar.includes(c.toLowerCase()); + return this.activeItem && this.activeItem.grammar && this.activeItem.grammar === c.toLowerCase(); }); }, diff --git a/spec/flex-tool-bar-spec.js b/spec/flex-tool-bar-spec.js index bf897ab..700ce20 100644 --- a/spec/flex-tool-bar-spec.js +++ b/spec/flex-tool-bar-spec.js @@ -304,6 +304,24 @@ describe('FlexToolBar', function () { expect(match).toBe(true); expect(notMatch).toBe(false); }); + + it('should not match substring', function () { + flexToolBar.activeItem.grammar = 'cpp'; + + const match = flexToolBar.checkConditions({grammar: 'c'}); + const notMatch = flexToolBar.checkConditions({grammar: '!c'}); + expect(match).toBe(false); + expect(notMatch).toBe(true); + }); + + it('should not match grammar substring', function () { + flexToolBar.activeItem.grammar = 'c'; + + const match = flexToolBar.checkConditions({grammar: 'cpp'}); + const notMatch = flexToolBar.checkConditions({grammar: '!cpp'}); + expect(match).toBe(false); + expect(notMatch).toBe(true); + }); }); describe('pattern condition', function () {