From 7138597d7ecb196231cd1012af25e4f993234077 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sun, 1 Nov 2020 22:10:00 +0100 Subject: [PATCH] Implement expand/collapseBlock keys --- editor/src/editor.js | 4 ++-- list-editor/index.js | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/editor/src/editor.js b/editor/src/editor.js index a8ae69f..11efa59 100644 --- a/editor/src/editor.js +++ b/editor/src/editor.js @@ -528,8 +528,8 @@ function Editor(holder, input) { }) editor.replaceChildren(id, results) }).then(function () { - editor.render() - }) + editor.render() + }) } } }); diff --git a/list-editor/index.js b/list-editor/index.js index 2b234ee..c130e71 100644 --- a/list-editor/index.js +++ b/list-editor/index.js @@ -42,6 +42,8 @@ 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') function createStore(inputData) { let data = [ @@ -152,7 +154,10 @@ function editor(root, inputData, options) { leaveEditor, blockMoveBackward, - blockMoveForward + blockMoveForward, + + expandBlock, + collapseBlock }; root.classList.add('root') @@ -609,6 +614,26 @@ function editor(root, inputData, options) { return false } + function expandBlock(event) { + let open = true + store.update(cursor.getId(store), function (item) { + item.fold = open ? 'open' : 'closed' + return item + }) + trigger('change') + return false + } + + function collapseBlock(event) { + let open = false + store.update(cursor.getId(store), function (item) { + item.fold = open ? 'open' : 'closed' + return item + }) + trigger('change') + return false + } + $(root).on('keydown', function (event) { return keymap.handleKey(EDITOR, event) })