Implement toggleBlock

This commit is contained in:
Peter Stuifzand 2020-11-02 22:43:05 +01:00
parent 56802dc106
commit 8384c115c6

View File

@ -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) {