Skip to content

Commit 89155fe

Browse files
authored
[JavaScript] fix tagged template string key bindings regression (#4022)
* [JavaScript] Adjust tagged template string related key bindings This commit... 1. scopes tagged template strings `meta.string.template` to give all of them a common scope without regards of used syntax highlighting 2. uses that scope in key bindings' selectors to enable them in syntax highlighted tagged templates. 3. restrict ` to JavaScript strings by enforcing scope order in selectors in binding 1 and 2 4. merge "selector" keys in binding 3 and 4 * [JavaScript] Add binding to auto-indent content whithin backquotes This commit adds a `enter` key binding to achieve the following, when hitting enter within two backquotes. before: foo = `|` after: foo = ` | ` * [JavaScript] Adjust context key order This commit moves `selector` after `settings` and `selection_empty` as it seems to be the commonly used order in ST's default key bindings. * [JavaScript] Add missing `match_all` attribute to selector context checks This commit aligns selector checks with ST's default key bindings by adding `"match_all": true` to all selector context checks. * [JavaScrit] Simplify keybindings' context checks This commit removes default entries. - operator: equal - operand: true * [JavaScript] Fix typo * [JavaScript] Tweak enter key binding This commit changes `enter` key binding to "Add Line in Braces" macro, as it indents line between backticks using indentation rules instead of forcing it to be indented via `\t`. This works also, if indentation rules decide not to indent backticked contents.
1 parent 80f1a61 commit 89155fe

File tree

3 files changed

+104
-86
lines changed

3 files changed

+104
-86
lines changed

JavaScript/Default.sublime-keymap

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,71 @@
22
// Auto-pair backticks
33
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0`"}, "context":
44
[
5-
{ "key": "selector", "operator": "equal", "operand": "(source.js, source.ts) - string" },
6-
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
7-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
5+
{ "key": "setting.auto_match_enabled" },
6+
{ "key": "selection_empty", "match_all": true },
7+
{ "key": "selector", "operand": "source.js - source.js meta.string, source.jsx - source.jsx meta.string, source.ts - source.ts meta.string, source.tsx - source.tsx meta.string", "match_all": true },
88
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
99
]
1010
},
1111
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`${0:$SELECTION}`"}, "context":
1212
[
13-
{ "key": "selector", "operator": "equal", "operand": "(source.js, source.ts) - string" },
14-
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
15-
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
13+
{ "key": "setting.auto_match_enabled" },
14+
{ "key": "selection_empty", "operand": false, "match_all": true },
15+
{ "key": "selector", "operand": "source.js - source.js meta.string, source.jsx - source.jsx meta.string, source.ts - source.ts meta.string, source.tsx - source.tsx meta.string", "match_all": true }
1616
]
1717
},
1818
{ "keys": ["`"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
1919
[
20-
{ "key": "selector", "operator": "equal", "operand": "source.js, source.ts" },
21-
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
22-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
23-
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true },
24-
{ "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
20+
{ "key": "setting.auto_match_enabled" },
21+
{ "key": "selection_empty", "match_all": true },
22+
{ "key": "selector", "operand": "meta.string.template.js - meta.string.template.js punctuation.definition.string.begin", "match_all": true },
23+
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
2524
]
2625
},
2726
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}, "context":
2827
[
29-
{ "key": "selector", "operator": "equal", "operand": "string.quoted.other.js" },
30-
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
31-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
28+
{ "key": "setting.auto_match_enabled" },
29+
{ "key": "selection_empty", "match_all": true },
30+
{ "key": "selector", "operand": "meta.string.template.js - meta.string.template.js punctuation.definition.string.begin", "match_all": true },
3231
{ "key": "preceding_text", "operator": "regex_contains", "operand": "`$", "match_all": true },
33-
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true },
34-
{ "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
32+
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
33+
]
34+
},
35+
36+
// Add indented line in backticks
37+
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
38+
[
39+
{ "key": "setting.auto_indent" },
40+
{ "key": "selection_empty", "match_all": true },
41+
{ "key": "selector", "operand": "meta.string.template.js", "match_all": true },
42+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "`$", "match_all": true },
43+
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
44+
]
45+
},
46+
{ "keys": ["keypad_enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
47+
[
48+
{ "key": "setting.auto_indent" },
49+
{ "key": "selection_empty", "match_all": true },
50+
{ "key": "selector", "operand": "meta.string.template.js", "match_all": true },
51+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "`$", "match_all": true },
52+
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
3553
]
3654
},
3755

3856
// Auto-pair interpolation
3957
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0}"}, "context":
4058
[
41-
{ "key": "selector", "operator": "equal", "operand": "string.quoted.other.js", "match_all": true },
42-
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
43-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
59+
{ "key": "setting.auto_match_enabled" },
60+
{ "key": "selection_empty", "match_all": true },
61+
{ "key": "selector", "operand": "meta.string.template.js", "match_all": true },
4462
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\$$", "match_all": true }
4563
]
4664
},
4765
{ "keys": ["$"], "command": "insert_snippet", "args": {"contents": "\\${${0:$SELECTION}}"}, "context":
4866
[
49-
{ "key": "selector", "operator": "equal", "operand": "string.quoted.other.js", "match_all": true },
50-
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
51-
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
67+
{ "key": "setting.auto_match_enabled" },
68+
{ "key": "selection_empty", "operand": false, "match_all": true },
69+
{ "key": "selector", "operand": "meta.string.template.js", "match_all": true }
5270
]
5371
},
5472
]

JavaScript/JavaScript.sublime-syntax

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,62 +1245,62 @@ contexts:
12451245
- match: (css)\s*((\`){{trailing_wspace}}?)
12461246
captures:
12471247
1: variable.function.tagged-template.js
1248-
2: meta.string.js string.quoted.other.js
1248+
2: meta.string.template.js string.quoted.other.js
12491249
3: punctuation.definition.string.begin.js
12501250
embed: scope:source.css.js-template
1251-
embed_scope: meta.string.js source.css.embedded.js
1251+
embed_scope: meta.string.template.js source.css.embedded.js
12521252
escape: '{{leading_wspace}}?(\`)'
12531253
escape_captures:
1254-
0: meta.string.js string.quoted.other.js
1254+
0: meta.string.template.js string.quoted.other.js
12551255
1: punctuation.definition.string.end.js
12561256
pop: 1
12571257
- match: (html)\s*((\`){{trailing_wspace}}?)
12581258
captures:
12591259
1: variable.function.tagged-template.js
1260-
2: meta.string.js string.quoted.other.js
1260+
2: meta.string.template.js string.quoted.other.js
12611261
3: punctuation.definition.string.begin.js
12621262
embed: scope:text.html.js-template
1263-
embed_scope: meta.string.js text.html.embedded.js
1263+
embed_scope: meta.string.template.js text.html.embedded.js
12641264
escape: '{{leading_wspace}}?(\`)'
12651265
escape_captures:
1266-
0: meta.string.js string.quoted.other.js
1266+
0: meta.string.template.js string.quoted.other.js
12671267
1: punctuation.definition.string.end.js
12681268
pop: 1
12691269
- match: (js)\s*((\`){{trailing_wspace}}?)
12701270
captures:
12711271
1: variable.function.tagged-template.js
1272-
2: meta.string.js string.quoted.other.js
1272+
2: meta.string.template.js string.quoted.other.js
12731273
3: punctuation.definition.string.begin.js
12741274
embed: scope:source.js.js-template
1275-
embed_scope: meta.string.js source.js.embedded.js
1275+
embed_scope: meta.string.template.js source.js.embedded.js
12761276
escape: '{{leading_wspace}}?(\`)'
12771277
escape_captures:
1278-
0: meta.string.js string.quoted.other.js
1278+
0: meta.string.template.js string.quoted.other.js
12791279
1: punctuation.definition.string.end.js
12801280
pop: 1
12811281
- match: (json)\s*((\`){{trailing_wspace}}?)
12821282
captures:
12831283
1: variable.function.tagged-template.js
1284-
2: meta.string.js string.quoted.other.js
1284+
2: meta.string.template.js string.quoted.other.js
12851285
3: punctuation.definition.string.begin.js
12861286
embed: scope:source.json.js-template
1287-
embed_scope: meta.string.js source.json.embedded.js
1287+
embed_scope: meta.string.template.js source.json.embedded.js
12881288
escape: '{{leading_wspace}}?(\`)'
12891289
escape_captures:
1290-
0: meta.string.js string.quoted.other.js
1290+
0: meta.string.template.js string.quoted.other.js
12911291
1: punctuation.definition.string.end.js
12921292
pop: 1
12931293
- match: (?:({{identifier_name}})\s*)?(\`)
12941294
captures:
12951295
1: variable.function.tagged-template.js
1296-
2: meta.string.js string.quoted.other.js punctuation.definition.string.begin.js
1296+
2: meta.string.template.js string.quoted.other.js punctuation.definition.string.begin.js
12971297
set: literal-string-template-content
12981298

12991299
literal-string-template-content:
13001300
- meta_include_prototype: false
1301-
- meta_content_scope: meta.string.js string.quoted.other.js
1301+
- meta_content_scope: meta.string.template.js string.quoted.other.js
13021302
- match: \`
1303-
scope: meta.string.js string.quoted.other.js punctuation.definition.string.end.js
1303+
scope: meta.string.template.js string.quoted.other.js punctuation.definition.string.end.js
13041304
pop: 1
13051305
- include: string-interpolations
13061306
- include: string-content

0 commit comments

Comments
 (0)