Skip to content

Commit 7748c99

Browse files
authored
Merge pull request #99 from Thom1729/jsx-close-tag-selector
Support TypeScript scopes for comments and tag closing
2 parents 57cc6de + fbb4247 commit 7748c99

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ An object specifying a configuration to use when another syntax embeds the `sour
6262

6363
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.
6464

65-
### `jsx_close_tag`: boolean
65+
### `jsx_close_tag`: string or boolean
6666

67-
If true, when you run the `close_tag` command in a JavaScript file, this package's `jsx_close_tag` command will be invoked instead.
67+
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
68+
69+
If false, `jsx_close_tag` will never be run.
6870

6971
### `reassign_when_deleting`: string or `false`
7072

src/listeners/jsx_close_tag.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88

99
class JsxCloseTagListener(sublime_plugin.ViewEventListener):
1010
def on_text_command(self, command_name, args):
11-
if (
12-
command_name == 'close_tag'
13-
and get_settings()['jsx_close_tag']
14-
and self.view.match_selector(0, 'source.js')
15-
):
11+
if command_name != 'close_tag':
12+
return
13+
14+
selector = get_settings()['jsx_close_tag']
15+
16+
if not selector:
17+
return
18+
elif selector is True:
19+
selector = 'source.js, source.ts, source.tsx'
20+
21+
if self.view.match_selector(0, selector):
1622
return ('jsx_close_tag', args)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plist version="1.0">
3+
<dict>
4+
<key>name</key>
5+
<string>Comments</string>
6+
<key>scope</key>
7+
<string>source.js, source.ts, source.tsx</string>
8+
<key>settings</key>
9+
<dict>
10+
<key>shellVariables</key>
11+
<array>
12+
<dict>
13+
<key>name</key>
14+
<string>TM_COMMENT_START</string>
15+
<key>value</key>
16+
<string>// </string>
17+
</dict>
18+
<dict>
19+
<key>name</key>
20+
<string>TM_COMMENT_START_2</string>
21+
<key>value</key>
22+
<string>/*</string>
23+
</dict>
24+
<dict>
25+
<key>name</key>
26+
<string>TM_COMMENT_END_2</string>
27+
<key>value</key>
28+
<string>*/</string>
29+
</dict>
30+
</array>
31+
</dict>
32+
</dict>
33+
</plist>

sublime/JS Custom - JSX Comments.tmPreferences

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<key>name</key>
66
<string>JS Custom - JSX Comments</string>
77
<key>scope</key>
8-
<string>source.js meta.jsx - source.js.embedded.jsx</string>
8+
<string>source.js meta.jsx - source.js.embedded.jsx, source.ts meta.jsx - source.ts.embedded.jsx, source.tsx meta.jsx - source.tsx.embedded.jsx</string>
99
<key>settings</key>
1010
<dict>
1111
<key>shellVariables</key>

sublime/JS Custom.sublime-settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
},
3838

3939
"auto_build": true,
40-
"jsx_close_tag": true,
40+
"jsx_close_tag": "source.js, source.ts, source.tsx",
4141
"reassign_when_deleting": "scope:source.js",
4242
}

0 commit comments

Comments
 (0)