diff --git a/Editor.js b/Editor.js index e49feb9..a8fda1d 100644 --- a/Editor.js +++ b/Editor.js @@ -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': diff --git a/EditorLabel.js b/EditorLabel.js index 7438e21..025361b 100644 --- a/EditorLabel.js +++ b/EditorLabel.js @@ -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; diff --git a/EditorNode.js b/EditorNode.js index 00cf360..2c3c50c 100644 --- a/EditorNode.js +++ b/EditorNode.js @@ -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;