Skip to content

Commit

Permalink
Merge pull request #3 from sambacha/checklist-support
Browse files Browse the repository at this point in the history
  • Loading branch information
sam bacha authored May 30, 2020
2 parents a8ea02b + 51576e5 commit a9efa2f
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 23 deletions.
246 changes: 242 additions & 4 deletions Keymaps/Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,5 +1,182 @@
// This file is generated, do not edit it by hand!
[
{
"keys": [
"-"
],
"command": "insert_snippet",
"args": {
"contents": "-$0-"
},
"context": [
{
"key": "selection_empty",
"operator": "equal",
"operand": true,
"match_all": true
},
{
"key": "following_text",
"operator": "regex_contains",
"operand": "^(?:$|\\s|\\)|\\]|\\}|\\*|_|\\`)",
"match_all": true
},
{
"key": "preceding_text",
"operator": "regex_contains",
"operand": "(?:^|\\s|\\(|\\[|\\]|\\*|_|\\`)$",
"match_all": true
},
{
"key": "eol_selector",
"operator": "not_equal",
"operand": "string.quoted.single",
"match_all": true
},
{
"key": "setting.auto_match_enabled",
"operator": "equal",
"operand": true,
"match_all": true
},
{
"key": "selector",
"operator": "equal",
"operand": "text.asciidoc",
"match_all": true
},
{
"key": "selector",
"operator": "not_equal",
"operand": "markup.raw",
"match_all": true
}
]
},
{
"keys": [
"-"
],
"command": "insert_snippet",
"args": {
"contents": "-${0:$SELECTION}-"
},
"context": [
{
"key": "selection_empty",
"operator": "equal",
"operand": false,
"match_all": true
},
{
"key": "setting.auto_match_enabled",
"operator": "equal",
"operand": true,
"match_all": true
},
{
"key": "selector",
"operator": "equal",
"operand": "text.asciidoc",
"match_all": true
},
{
"key": "selector",
"operator": "not_equal",
"operand": "markup.raw",
"match_all": true
}
]
},
{
"keys": [
"-"
],
"command": "move",
"args": {
"by": "characters",
"forward": true
},
"context": [
{
"key": "selection_empty",
"operator": "equal",
"operand": true,
"match_all": true
},
{
"key": "following_text",
"operator": "regex_contains",
"operand": "^\\-",
"match_all": true
},
{
"key": "setting.auto_match_enabled",
"operator": "equal",
"operand": true,
"match_all": true
},
{
"key": "selector",
"operator": "equal",
"operand": "text.asciidoc",
"match_all": true
},
{
"key": "selector",
"operator": "not_equal",
"operand": "markup.raw",
"match_all": true
}
]
},
{
"keys": [
"backspace"
],
"command": "run_macro_file",
"args": {
"file": "res://Packages/Default/Delete Left Right.sublime-macro"
},
"context": [
{
"key": "selection_empty",
"operator": "equal",
"operand": true,
"match_all": true
},
{
"key": "preceding_text",
"operator": "regex_contains",
"operand": "\\-$",
"match_all": true
},
{
"key": "following_text",
"operator": "regex_contains",
"operand": "^\\-",
"match_all": true
},
{
"key": "setting.auto_match_enabled",
"operator": "equal",
"operand": true,
"match_all": true
},
{
"key": "selector",
"operator": "equal",
"operand": "text.asciidoc",
"match_all": true
},
{
"key": "selector",
"operator": "not_equal",
"operand": "markup.raw",
"match_all": true
}
]
},
{
"keys": [
"*"
Expand Down Expand Up @@ -1573,7 +1750,7 @@
{
"key": "preceding_text",
"operator": "regex_match",
"operand": "^\\s*[*.-]+\\s+$",
"operand": "^\\s*[*.-]+(\\s*(\\[)[xX* ](\\]))?\\s+$",
"match_all": true
},
{
Expand Down Expand Up @@ -1649,7 +1826,7 @@
{
"key": "preceding_text",
"operator": "regex_match",
"operand": "^\\s*[*.-]+\\s+$",
"operand": "^\\s*[*.-]+(\\s*(\\[)[xX* ](\\]))?\\s+$",
"match_all": true
},
{
Expand Down Expand Up @@ -1713,7 +1890,7 @@
],
"command": "insert_snippet",
"args": {
"contents": "${TM_CURRENT_LINE/^(\\s*([*.\\-]+)(\\s+)).*/\n$2$3/}"
"contents": "${TM_CURRENT_LINE/^(\\s*([*.\\-]+)(\\s+))(\\[[xX* ]\\]\\s*)?.*/\n$2$3$4/}"
},
"context": [
{
Expand Down Expand Up @@ -1742,6 +1919,67 @@
}
]
},
{
"keys": [
"["
],
"command": "insert_snippet",
"args": {
"contents": "[ ] $0"
},
"context": [
{
"key": "auto_complete_visible",
"operator": "equal",
"operand": false,
"match_all": true
},
{
"key": "preceding_text",
"operator": "regex_contains",
"operand": "^\\s*([*.-]+)(?!.*[\\[\\w])",
"match_all": true
},
{
"key": "selector",
"operator": "equal",
"operand": "text.asciidoc",
"match_all": true
},
{
"key": "selector",
"operator": "not_equal",
"operand": "markup.raw",
"match_all": true
}
]
},
{
"keys": [
"alt+enter"
],
"command": "asciidoc_toggle_checkbox",
"context": [
{
"key": "auto_complete_visible",
"operator": "equal",
"operand": false,
"match_all": true
},
{
"key": "selector",
"operator": "equal",
"operand": "text.asciidoc",
"match_all": true
},
{
"key": "selector",
"operator": "not_equal",
"operand": "markup.raw",
"match_all": true
}
]
},
{
"keys": [
"enter"
Expand Down Expand Up @@ -1818,7 +2056,7 @@
{
"key": "preceding_text",
"operator": "regex_match",
"operand": "^\\s*(?:[*.-]+|<\\d+>)\\s+$",
"operand": "^\\s*(?:[*.-]+|<\\d+>)(\\s*(\\[)[xX* ](\\]))?\\s+$",
"match_all": true
},
{
Expand Down
21 changes: 18 additions & 3 deletions Keymaps/Default.sublime-keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def indent_list_items(key, reverse=False):
bind(key)
.to('asciidoc_indent_list_item', reverse=reverse)
.when('selection_empty').true()
.also('preceding_text').regex_match('^\\s*[*.-]+\\s+$')
.also('preceding_text').regex_match('^\\s*[*.-]+(\\s*(\\[)[xX* ](\\]))?\\s+$')
.also('following_text').regex_match('^$'),

# When you select one or more list items and press the *key*, then the
Expand All @@ -113,6 +113,7 @@ def indent_list_items(key, reverse=False):


Keymap(
paired_chars('-', '-'),
paired_chars('*', '*'),
paired_chars('_', '_'),
paired_chars('`', '`'),
Expand Down Expand Up @@ -160,10 +161,24 @@ def indent_list_items(key, reverse=False):
# When the cursor is at EOL with an (un)ordered list item and you hit
# Enter, then the next item is added (with the same nesting level).
bind('enter')
.to('insert_snippet', contents='${TM_CURRENT_LINE/^(\\s*([*.\\-]+)(\\s+)).*/\n$2$3/}')
.to('insert_snippet',
contents='${TM_CURRENT_LINE/^(\\s*([*.\\-]+)(\\s+))(\\[[xX* ]\\]\\s*)?.*/\n$2$3$4/}')
.when('auto_complete_visible').false()
.also('preceding_text').regex_contains('^\\s*([*.-]+)\\s+\\S'),

# When the cursor is at beginning of a list item a "[" will create a
# checkbox and places the cursor at EOL.
bind('[')
.to('insert_snippet', contents='[ ] $0')
.when('auto_complete_visible').false()
.also('preceding_text').regex_contains('^\\s*([*.-]+)(?!.*[\\[\\w])'),

# When the cursor is at line with an checkbox item and you hit
# Alt+Enter, then the checkbox is toggled
bind('alt+enter')
.to('asciidoc_toggle_checkbox')
.when('auto_complete_visible').false(),

# When the cursor is at EOL with a callout list item and you hit Enter,
# then the next item is added (with incremented number).
bind('enter')
Expand All @@ -180,7 +195,7 @@ def indent_list_items(key, reverse=False):
['insert', {'characters': '\n'}],
['move', {'by': 'characters', 'forward': False}]])
.when('auto_complete_visible').false()
.also('preceding_text').regex_match('^\\s*(?:[*.-]+|<\\d+>)\\s+$')
.also('preceding_text').regex_match('^\\s*(?:[*.-]+|<\\d+>)(\\s*(\\[)[xX* ](\\]))?\\s+$')
.also('following_text').regex_match('^\\s*$'),

common_context=[
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ TODO
- You can disable indentation of list items in your settings file.
* At the end of a callouts list item, pressing <kbd>Enter</kbd> will automatically insert the new list item with incremented number.
- Pressing <kbd>Enter</kbd> on the blank list item will remove it.
* At the end of a checklist item, pressing <kbd>Enter</kbd> will automatically insert the new checklist item.
- Pressing <kbd>Alt+Enter</kbd> toggles the checkbox(es) on the selected line(s).

### Snippets

Expand Down Expand Up @@ -90,4 +92,4 @@ Most of the commands, keymaps and some text in this readme are based on (or insp
## License

This project is licensed under [MIT License](http://opensource.org/licenses/MIT/).
For the full text of the license, see the [LICENSE](LICENSE) file.
For the full text of the license, see the [LICENSE](LICENSE) file.
Loading

0 comments on commit a9efa2f

Please sign in to comment.