|
|
@ -29,23 +29,36 @@ function textareaCursorInfo(target, dir) {
|
|
|
|
function editor(root, inputData, options) {
|
|
|
|
function editor(root, inputData, options) {
|
|
|
|
let cursor = createCursor()
|
|
|
|
let cursor = createCursor()
|
|
|
|
let store = createStore(inputData);
|
|
|
|
let store = createStore(inputData);
|
|
|
|
let keymap = new Keymap()
|
|
|
|
|
|
|
|
let drake = null;
|
|
|
|
let drake = null;
|
|
|
|
|
|
|
|
|
|
|
|
keymap.mapKey('ArrowUp', 'backwardLine')
|
|
|
|
let editorKeymap = new Keymap()
|
|
|
|
keymap.mapKey('ArrowDown', 'forwardLine')
|
|
|
|
editorKeymap.mapKey('ArrowUp', 'backwardLine')
|
|
|
|
keymap.mapKey('S-Delete', 'deleteBlock')
|
|
|
|
editorKeymap.mapKey('ArrowDown', 'forwardLine')
|
|
|
|
keymap.mapKey('C-Enter', 'insertLineAbove')
|
|
|
|
editorKeymap.mapKey('S-Delete', 'deleteBlock')
|
|
|
|
keymap.mapKey('Enter', 'insertLineBelow')
|
|
|
|
editorKeymap.mapKey('C-Enter', 'insertLineAbove')
|
|
|
|
keymap.mapKey('Tab', 'indentBlock')
|
|
|
|
editorKeymap.mapKey('Enter', 'insertLineBelow')
|
|
|
|
keymap.mapKey('S-Tab', 'indentBlock')
|
|
|
|
editorKeymap.mapKey('Tab', 'indentBlock')
|
|
|
|
keymap.mapKey('Escape', 'leaveEditor')
|
|
|
|
editorKeymap.mapKey('S-Tab', 'indentBlock')
|
|
|
|
keymap.mapKey('C-S-ArrowUp', 'blockMoveBackward')
|
|
|
|
editorKeymap.mapKey('Escape', 'leaveEditor')
|
|
|
|
keymap.mapKey('C-S-ArrowDown', 'blockMoveForward')
|
|
|
|
editorKeymap.mapKey('C-S-ArrowUp', 'blockMoveBackward')
|
|
|
|
keymap.mapKey('C-.', 'toggleBlock')
|
|
|
|
editorKeymap.mapKey('C-S-ArrowDown', 'blockMoveForward')
|
|
|
|
|
|
|
|
editorKeymap.mapKey('C-.', 'toggleBlock')
|
|
|
|
// keymap.mapKey('C-]', 'zoomIn')
|
|
|
|
// keymap.mapKey('C-]', 'zoomIn')
|
|
|
|
// keymap.mapKey('C-[', 'zoomOut')
|
|
|
|
// keymap.mapKey('C-[', 'zoomOut')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let normalKeymap = new Keymap()
|
|
|
|
|
|
|
|
normalKeymap.mapKey('k', 'backwardLine')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('j', 'forwardLine')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('S-O', 'insertLineAbove')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('o', 'insertLineBelow')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('d', 'deleteBlock')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('i', 'enterEditor')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('S-I', 'enterEditor')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('S-A', 'enterEditorAppend')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('Tab', 'indentBlock')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('S-Tab', 'indentBlock')
|
|
|
|
|
|
|
|
normalKeymap.mapKey('C-.', 'toggleBlock')
|
|
|
|
|
|
|
|
|
|
|
|
function createStore(inputData) {
|
|
|
|
function createStore(inputData) {
|
|
|
|
let data = [
|
|
|
|
let data = [
|
|
|
|
{indented: 0, text: '', fold: 'open'},
|
|
|
|
{indented: 0, text: '', fold: 'open'},
|
|
|
@ -154,6 +167,8 @@ function editor(root, inputData, options) {
|
|
|
|
indentBlock,
|
|
|
|
indentBlock,
|
|
|
|
|
|
|
|
|
|
|
|
leaveEditor,
|
|
|
|
leaveEditor,
|
|
|
|
|
|
|
|
enterEditor,
|
|
|
|
|
|
|
|
enterEditorAppend,
|
|
|
|
|
|
|
|
|
|
|
|
blockMoveBackward,
|
|
|
|
blockMoveBackward,
|
|
|
|
blockMoveForward,
|
|
|
|
blockMoveForward,
|
|
|
@ -585,6 +600,18 @@ function editor(root, inputData, options) {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function enterEditor(event) {
|
|
|
|
|
|
|
|
let $input = startEditing(root, store, cursor)
|
|
|
|
|
|
|
|
$input[0].selectStart = $input[0].selectionEnd = 0
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function enterEditorAppend(event) {
|
|
|
|
|
|
|
|
let $input = startEditing(root, store, cursor)
|
|
|
|
|
|
|
|
$input[0].selectStart = $input[0].selectionEnd = $input[0].value.length
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function blockMoveBackward(event) {
|
|
|
|
function blockMoveBackward(event) {
|
|
|
|
stopEditing(root, store, currentEditor)
|
|
|
|
stopEditing(root, store, currentEditor)
|
|
|
|
|
|
|
|
|
|
|
@ -637,7 +664,12 @@ function editor(root, inputData, options) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$(root).on('keydown', function (event) {
|
|
|
|
$(root).on('keydown', function (event) {
|
|
|
|
return keymap.handleKey(EDITOR, event)
|
|
|
|
console.log('editing: ' + editing)
|
|
|
|
|
|
|
|
if (editing) {
|
|
|
|
|
|
|
|
return editorKeymap.handleKey(EDITOR, event)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return normalKeymap.handleKey(EDITOR, event)
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
$(root).on('click', '.marker', function () {
|
|
|
|
$(root).on('click', '.marker', function () {
|
|
|
|