From c5cf622caf6a4da5a36dc8e05bc64609371ab1bb Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 13 Jul 2020 15:00:46 -0400 Subject: [PATCH 1/3] Use settings selector to control jsx_close_tag --- README.md | 6 ++++-- src/listeners/jsx_close_tag.py | 16 +++++++++++----- sublime/JS Custom.sublime-settings | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9072d7f..be621ca 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,11 @@ An object specifying a configuration to use when another syntax embeds the `sour If true, JS Custom will automatically rebuild your syntaxes when you modify your user settings. Only syntaxes whose configurations have changed will be rebuilt. If `auto_build` is disabled, you will have to run the rebuild command manually. -### `jsx_close_tag`: boolean +### `jsx_close_tag`: string or boolean -If true, when you run the `close_tag` command in a JavaScript file, this package's `jsx_close_tag` command will be invoked instead. +When you run the `close_tag` command, if the scope of the file matches this selector, then this package's `jsx_close_tag` command will be invoked instead. You may have to modify this setting if you use the `scope` configuration option + +If false, `jsx_close_tag` will never be run. ### `reassign_when_deleting`: string or `false` diff --git a/src/listeners/jsx_close_tag.py b/src/listeners/jsx_close_tag.py index d7e0145..23fd529 100644 --- a/src/listeners/jsx_close_tag.py +++ b/src/listeners/jsx_close_tag.py @@ -8,9 +8,15 @@ class JsxCloseTagListener(sublime_plugin.ViewEventListener): def on_text_command(self, command_name, args): - if ( - command_name == 'close_tag' - and get_settings()['jsx_close_tag'] - and self.view.match_selector(0, 'source.js') - ): + if command_name != 'close_tag': + return + + selector = get_settings()['jsx_close_tag'] + + if not selector: + return + elif selector is True: + selector = 'source.js, source.ts, source.tsx' + + if self.view.match_selector(0, selector): return ('jsx_close_tag', args) diff --git a/sublime/JS Custom.sublime-settings b/sublime/JS Custom.sublime-settings index dd08a40..b0df249 100644 --- a/sublime/JS Custom.sublime-settings +++ b/sublime/JS Custom.sublime-settings @@ -37,6 +37,6 @@ }, "auto_build": true, - "jsx_close_tag": true, + "jsx_close_tag": "source.js, source.ts, source.tsx", "reassign_when_deleting": "scope:source.js", } From 9fd934aa8f413a7804adb93dbd6050eee71575ea Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 13 Jul 2020 15:45:15 -0400 Subject: [PATCH 2/3] Use broader scopes for tmPreferences. --- sublime/JS Custom - Comments.tmPreferences | 33 +++++++++++++++++++ .../JS Custom - JSX Comments.tmPreferences | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 sublime/JS Custom - Comments.tmPreferences diff --git a/sublime/JS Custom - Comments.tmPreferences b/sublime/JS Custom - Comments.tmPreferences new file mode 100644 index 0000000..64128c4 --- /dev/null +++ b/sublime/JS Custom - Comments.tmPreferences @@ -0,0 +1,33 @@ + + + + name + Comments + scope + source.js, source.ts, source.tsx + settings + + shellVariables + + + name + TM_COMMENT_START + value + // + + + name + TM_COMMENT_START_2 + value + /* + + + name + TM_COMMENT_END_2 + value + */ + + + + + diff --git a/sublime/JS Custom - JSX Comments.tmPreferences b/sublime/JS Custom - JSX Comments.tmPreferences index 1e5b06e..67af591 100644 --- a/sublime/JS Custom - JSX Comments.tmPreferences +++ b/sublime/JS Custom - JSX Comments.tmPreferences @@ -5,7 +5,7 @@ name JS Custom - JSX Comments scope - source.js meta.jsx - source.js.embedded.jsx + source.js meta.jsx - source.js.embedded.jsx, source.tsx meta.jsx - source.tsx.embedded.jsx settings shellVariables From fbb4247abe31f2903d580dcae4af7fe86921b021 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 13 Jul 2020 16:00:35 -0400 Subject: [PATCH 3/3] Use consistent list of scopes for JSX comments. --- sublime/JS Custom - JSX Comments.tmPreferences | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sublime/JS Custom - JSX Comments.tmPreferences b/sublime/JS Custom - JSX Comments.tmPreferences index 67af591..143e214 100644 --- a/sublime/JS Custom - JSX Comments.tmPreferences +++ b/sublime/JS Custom - JSX Comments.tmPreferences @@ -5,7 +5,7 @@ name JS Custom - JSX Comments scope - source.js meta.jsx - source.js.embedded.jsx, source.tsx meta.jsx - source.tsx.embedded.jsx + source.js meta.jsx - source.js.embedded.jsx, source.ts meta.jsx - source.ts.embedded.jsx, source.tsx meta.jsx - source.tsx.embedded.jsx settings shellVariables