Skip to content

Commit

Permalink
Merge pull request #99 from Thom1729/jsx-close-tag-selector
Browse files Browse the repository at this point in the history
Support TypeScript scopes for comments and tag closing
  • Loading branch information
Thom1729 authored Jul 16, 2020
2 parents 57cc6de + fbb4247 commit 7748c99
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
16 changes: 11 additions & 5 deletions src/listeners/jsx_close_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
33 changes: 33 additions & 0 deletions sublime/JS Custom - Comments.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Comments</string>
<key>scope</key>
<string>source.js, source.ts, source.tsx</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string>// </string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_START_2</string>
<key>value</key>
<string>/*</string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_END_2</string>
<key>value</key>
<string>*/</string>
</dict>
</array>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion sublime/JS Custom - JSX Comments.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>name</key>
<string>JS Custom - JSX Comments</string>
<key>scope</key>
<string>source.js meta.jsx - source.js.embedded.jsx</string>
<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>
<key>settings</key>
<dict>
<key>shellVariables</key>
Expand Down
2 changes: 1 addition & 1 deletion sublime/JS Custom.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

0 comments on commit 7748c99

Please sign in to comment.