Skip to content

Commit 424afd4

Browse files
committed
Plugins: Add function to reset all tasks
This commit adds `mde_reset_task_list_items` command to clear all task check marks.
1 parent ce37cfb commit 424afd4

File tree

7 files changed

+93
-2
lines changed

7 files changed

+93
-2
lines changed

Default (Linux).sublime-keymap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,12 @@
10841084
{ "key": "overlay_visible", "operator": "equal", "operand": false }
10851085
]
10861086
},
1087+
// Reset GFM tasks
1088+
{ "keys": ["alt+shift+x"], "command": "mde_reset_task_list_items", "context":
1089+
[
1090+
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
1091+
]
1092+
},
10871093
// Toggle GFM tasks
10881094
{ "keys": ["alt+x"], "command": "mde_toggle_task_list_item", "context":
10891095
[

Default (OSX).sublime-keymap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,12 @@
10841084
{ "key": "overlay_visible", "operator": "equal", "operand": false }
10851085
]
10861086
},
1087+
// Reset GFM tasks
1088+
{ "keys": ["alt+shift+x"], "command": "mde_reset_task_list_items", "context":
1089+
[
1090+
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
1091+
]
1092+
},
10871093
// Toggle GFM tasks
10881094
{ "keys": ["alt+x"], "command": "mde_toggle_task_list_item", "context":
10891095
[

Default (Windows).sublime-keymap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,12 @@
10841084
{ "key": "overlay_visible", "operator": "equal", "operand": false }
10851085
]
10861086
},
1087+
// Reset GFM tasks
1088+
{ "keys": ["alt+shift+x"], "command": "mde_reset_task_list_items", "context":
1089+
[
1090+
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
1091+
]
1092+
},
10871093
// Toggle GFM tasks
10881094
{ "keys": ["alt+x"], "command": "mde_toggle_task_list_item", "context":
10891095
[

Default.sublime-commands

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@
205205
"command": "mde_switch_list_bullet_type"
206206
},
207207

208+
//
209+
// Tasks
210+
//
211+
212+
{
213+
"caption": "MarkdownEditing: Insert Task",
214+
"command": "mde_insert_task_list_item"
215+
},
216+
{
217+
"caption": "MarkdownEditing: Toggle Task",
218+
"command": "mde_toggle_task_list_item"
219+
},
220+
{
221+
"caption": "MarkdownEditing: Reset Tasks",
222+
"command": "mde_reset_task_list_items"
223+
},
224+
208225
//
209226
// References
210227
//

docs/usage.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Further available key bindings:
250250
| <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>,</kbd> | <kbd>⌘</kbd> + <kbd>⇧</kbd> + <kbd>,</kbd> | Decrease block quote level (remove a `> `)
251251
| <kbd>Ctrl</kbd> + <kbd>Enter</kbd> | <kbd>⌘</kbd> + <kbd>Enterkbd> | Terminate block quote by adding two newline's.<br/>If the current line is empty, block quote signs are removed.
252252

253-
# Lists and Tasks
253+
# Lists
254254

255255
List bullets are automatically changed when indenting or unindenting list items by default. This behaviour can be disabled via `"mde.list_indent_auto_switch_bullet": false`.
256256

@@ -261,12 +261,24 @@ Following commands are provided via Command Palette:
261261
* **Switch List Bullet Type**
262262
Switches the highlighted list between numbered and bulleted style.
263263

264+
# Tasks
265+
266+
Following commands are provided via Command Palette to manage tasks:
267+
268+
* **Insert Task**
269+
Creates new GFM task (`* [ ] task`)
270+
* **Toggle Task**
271+
Toggles GFM task check marks (`* [x] task`)
272+
* **Reset Tasks**
273+
Clear all task check boxes. If non-empty selection exists, only selected tasks are reset.
274+
264275
Following key bindings may be used to create or toggle tasks.
265276

266277
| Linux/Windows | MacOS | Description
267278
|---------------|-------|-------------
268279
| <kbd>Alt</kbd> + <kbd>t</kbd> | <kbd>⌘</kbd> + <kbd>⌥</kbd> + <kbd>t</kbd> | Creates new GFM task (`* [ ] task`)
269-
| <kbd>Alt</kbd> + <kbd>x</kbd> | <kbd>⌘</kbd> + <kbd>⌥</kbd> + <kbd>x</kbd> | Toggles GFM task check marks (`* [x] task`)
280+
| <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>x</kbd> | <kbd>⌥</kbd> + <kbd>⇧</kbd> + <kbd>x</kbd> | Clear GFM all (selected) task check marks (`* [0] task`)
281+
| <kbd>Alt</kbd> + <kbd>x</kbd> | <kbd>⌥</kbd> + <kbd>x</kbd> | Toggles GFM task check marks (`* [x] task`)
270282

271283
# References
272284

plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
MdeNumberListCommand,
6868
MdeSwitchListBulletTypeCommand,
6969
MdeInsertTaskListItemCommand,
70+
MdeResetTaskListItemsCommand,
7071
MdeToggleTaskListItemCommand,
7172
MdeJoinLines,
7273
)

plugins/lists.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,49 @@ def run(self, edit):
196196
self.view.insert(edit, sel.begin(), to_insert)
197197

198198

199+
class MdeResetTaskListItemsCommand(MdeTextCommand):
200+
"""
201+
The `mde_reset_task_list_items` command resets check mark of all task list items.
202+
203+
It must be called in the line of the check mark.
204+
205+
**Examples:**
206+
207+
```markdown
208+
# Ordered Task List
209+
210+
1. [ ] task 1
211+
2. [x] task 2
212+
213+
# Unordered Task List
214+
215+
* [ ] task 1
216+
- [x] task 2
217+
+ [ ] task 3
218+
219+
# Quoted Task List
220+
221+
> * [ ] task 1
222+
> * [x] task 2
223+
```
224+
"""
225+
226+
def run(self, edit):
227+
sels = self.view.sel()
228+
if not sels:
229+
return
230+
231+
# list of non-empty selections
232+
sels = [sel for sel in sels if not sel.empty()]
233+
234+
# replace all check marks by space
235+
for mark in self.view.find_by_selector(
236+
"text.html.markdown markup.list markup.checkbox.mark"
237+
):
238+
if not sels or any(mark in sel for sel in sels):
239+
self.view.replace(edit, mark, " ")
240+
241+
199242
class MdeToggleTaskListItemCommand(MdeTextCommand):
200243
"""
201244
The `mde_toggle_task_list_item` command toggles the check mark of task list items.

0 commit comments

Comments
 (0)