Add vim key commands
This commit is contained in:
parent
27ce39dcde
commit
c3aea176ae
|
@ -103,6 +103,9 @@ body {
|
||||||
.list-item:hover .fold {
|
.list-item:hover .fold {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
}
|
}
|
||||||
|
.list-item.selected .fold {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
.list-item.editor .fold {
|
.list-item.editor .fold {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
|
|
|
@ -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 () {
|
||||||
|
|
|
@ -16,16 +16,16 @@ function handleKeyDown(editor, event) {
|
||||||
|
|
||||||
const key = canonicalKey(event)
|
const key = canonicalKey(event)
|
||||||
|
|
||||||
console.log('Key down ' + key)
|
|
||||||
|
|
||||||
if (this.keys.hasOwnProperty(key)) {
|
if (this.keys.hasOwnProperty(key)) {
|
||||||
const action = this.keys[key]
|
const action = this.keys[key]
|
||||||
if (editor.hasOwnProperty(action)) {
|
if (editor.hasOwnProperty(action)) {
|
||||||
console.log('Calling action ' + action)
|
console.log('Key down ' + key + ', calling action ' + action)
|
||||||
return editor[action](event)
|
return editor[action](event)
|
||||||
} else {
|
} else {
|
||||||
console.warn('Unknown action on editor: ' + action)
|
console.warn('Unknown action on editor: ' + action)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('Key down ' + key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue
Block a user