More key shortcut cases

This commit is contained in:
Ian Gulliver
2019-07-11 19:58:22 +00:00
parent f4893cd20d
commit 0ecbd40642
3 changed files with 60 additions and 27 deletions

View File

@@ -63,115 +63,142 @@ class Editor extends List {
addNodeAfter(...rest) {
if (this.mayAdd(EditorNode)) {
EditorNode.addAfter(this.container_, this.getSelected(), ...rest);
return true;
}
return false;
}
addNodeBefore(...rest) {
if (this.mayAdd(EditorNode)) {
EditorNode.addBefore(this.container_, this.getSelected(), ...rest);
return true;
}
return false;
}
addLabelBefore() {
if (this.mayAdd(EditorLabel)) {
EditorLabel.addBefore(this.container_, this.getSelected());
return true;
}
return false;
}
addLabelAfter() {
if (this.mayAdd(EditorLabel)) {
EditorLabel.addAfter(this.container_, this.getSelected());
return true;
}
return false;
}
addLinkAfter() {
if (this.mayAdd(EditorLink)) {
EditorLink.addAfter(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode));
return true;
}
return false;
}
addLinkBefore() {
if (this.mayAdd(EditorLink)) {
EditorLink.addBefore(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode));
return true;
}
return false;
}
addGroupAfter() {
if (this.mayAdd(EditorGroup)) {
EditorGroup.addAfter(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode));
return true;
}
return false
}
addGroupBefore() {
if (this.mayAdd(EditorGroup)) {
EditorGroup.addBefore(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode));
return true;
}
return false;
}
addHelpAfter() {
if (this.mayAdd(EditorHelp)) {
EditorHelp.addAfter(this.container_, this.getSelected());
return true;
}
return false;
}
onKeyDown(e) {
switch (e.key) {
case 'a':
this.addLabelAfter();
e.stopPropagation();
e.preventDefault();
if (this.addLabelAfter()) {
e.stopPropagation();
e.preventDefault();
}
return;
case 'A':
this.addLabelBefore();
e.stopPropagation();
e.preventDefault();
if (this.addLabelBefore()) {
e.stopPropagation();
e.preventDefault();
}
return;
case 'g':
this.addGroupAfter();
e.stopPropagation();
e.preventDefault();
if (this.addGroupAfter()) {
e.stopPropagation();
e.preventDefault();
}
return;
case 'G':
this.addGroupBefore();
e.stopPropagation();
e.preventDefault();
if (this.addGroupBefore()) {
e.stopPropagation();
e.preventDefault();
}
return;
case 'i':
this.addLinkAfter();
e.stopPropagation();
e.preventDefault();
if (this.addLinkAfter()) {
e.stopPropagation();
e.preventDefault();
}
return;
case 'I':
this.addLinkBefore();
e.stopPropagation();
e.preventDefault();
if (this.addLinkBefore()) {
e.stopPropagation();
e.preventDefault();
}
return;
case 'n':
this.addNodeAfter();
e.stopPropagation();
e.preventDefault();
if (this.addNodeAfter()) {
e.stopPropagation();
e.preventDefault();
}
return;
case 'N':
this.addNodeBefore();
e.stopPropagation();
e.preventDefault();
if (this.addNodeBefore()) {
e.stopPropagation();
e.preventDefault();
}
return;
case '?':
this.addHelpAfter();
e.stopPropagation();
e.preventDefault();
if (this.addHelpAfter()) {
e.stopPropagation();
e.preventDefault();
}
return;
case 'Escape':

View File

@@ -44,6 +44,7 @@ class EditorLabel extends EditorEntryBase {
onInputKeyDown(e) {
switch (e.key) {
case 'Enter':
e.preventDefault();
e.stopPropagation();
if (this.elem_.nextElementSibling &&
this.elem_.nextElementSibling.xArchObj &&
@@ -55,6 +56,8 @@ class EditorLabel extends EditorEntryBase {
break;
case 'Escape':
case '`':
e.preventDefault();
e.stopPropagation();
this.stopEdit();
break;

View File

@@ -64,6 +64,7 @@ class EditorNode extends EditorEntryBase {
onInputKeyDown(e) {
switch (e.key) {
case 'Enter':
e.preventDefault();
e.stopPropagation();
if (this.elem_.nextElementSibling &&
this.elem_.nextElementSibling.xArchObj &&
@@ -75,6 +76,8 @@ class EditorNode extends EditorEntryBase {
break;
case 'Escape':
case '`':
e.preventDefault();
e.stopPropagation();
this.stopEdit();
break;