From 5d9b4129730c83c98f9762d821e64d8a220faa77 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sat, 7 Aug 2021 20:18:38 +0200 Subject: [PATCH] Add C-; toggleTodo key and actions Toggles between [ ] -> [x] -> none --- list-editor/index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/list-editor/index.js b/list-editor/index.js index 7e07282..5b6d4bc 100644 --- a/list-editor/index.js +++ b/list-editor/index.js @@ -59,6 +59,7 @@ function editor(root, inputData, options) { normalKeymap.mapKey('Tab', 'indentBlock') normalKeymap.mapKey('S-Tab', 'indentBlock') normalKeymap.mapKey('C-.', 'toggleBlock') + normalKeymap.mapKey('C-;', 'toggleTodo') function createStore(inputData) { let data = [ @@ -195,7 +196,9 @@ function editor(root, inputData, options) { expandBlock, collapseBlock, - toggleBlock + toggleBlock, + + toggleTodo }; root.classList.add('root') @@ -659,6 +662,24 @@ function editor(root, inputData, options) { return toggleBlock(event, false) } + function toggleTodo(event) { + store.update(cursor.getId(store), function (item) { + const res = item.text.match(/^#\[\[(TODO|DONE)\]\]/) + if (res) { + if (res[1] === 'TODO') { + item.text = item.text.replace(/#\[\[TODO\]\]\s*/, '#[[DONE]] ') + } else { + item.text = item.text.replace(/#\[\[DONE\]\]\s*/, '') + } + } else { + item.text = '#[[TODO]] ' + item.text + } + return item + }) + trigger('change') + return false + } + function countBraces(sset, as) { let set = _(sset).chain().split('').value() let defaults = {}