diff --git a/list-editor/index.js b/list-editor/index.js index dc2e6ca..f3b5fbc 100644 --- a/list-editor/index.js +++ b/list-editor/index.js @@ -42,8 +42,7 @@ function editor(root, inputData, options) { keymap.mapKey('Escape', 'leaveEditor') keymap.mapKey('C-S-ArrowUp', 'blockMoveBackward') keymap.mapKey('C-S-ArrowDown', 'blockMoveForward') - keymap.mapKey('C-.', 'expandBlock') - keymap.mapKey('C-S->', 'collapseBlock') + keymap.mapKey('C-.', 'toggleBlock') function createStore(inputData) { let data = [ @@ -157,7 +156,8 @@ function editor(root, inputData, options) { blockMoveForward, expandBlock, - collapseBlock + collapseBlock, + toggleBlock }; root.classList.add('root') @@ -613,9 +613,11 @@ function editor(root, inputData, options) { return false } - function expandBlock(event) { - let open = true + function toggleBlock(event, open) { store.update(cursor.getId(store), function (item) { + if (open === undefined) { + open = item.fold === 'closed' + } item.fold = open ? 'open' : 'closed' return item }) @@ -623,14 +625,12 @@ function editor(root, inputData, options) { return false } + function expandBlock(event) { + return toggleBlock(event, true) + } + function collapseBlock(event) { - let open = false - store.update(cursor.getId(store), function (item) { - item.fold = open ? 'open' : 'closed' - return item - }) - trigger('change') - return false + return toggleBlock(event, false) } $(root).on('keydown', function (event) {