diff --git a/EditorHelp.js b/EditorHelp.js index fc28829..f3e3ea5 100644 --- a/EditorHelp.js +++ b/EditorHelp.js @@ -49,6 +49,10 @@ class EditorHelp extends EditorEntryBase { this.addLine(); this.addKey('␣'); this.addText('Highlight '); + + this.addLine(); + this.addKey('f'); + this.addText('Flip link '); } addLine() { diff --git a/EditorLink.js b/EditorLink.js index a508ab4..ee11d22 100644 --- a/EditorLink.js +++ b/EditorLink.js @@ -63,6 +63,22 @@ class EditorLink extends EditorEntryBase { this.elem_.classList.toggle('highlight', highlight); } + flip() { + let entries = this.nodes_.getEntries(EditorNode); + let fromElem = entries[0].getElement(); + let toElem = entries[1].getElement(); + let fromHasFocus = document.activeElement == fromElem; + let toHasFocus = document.activeElement == toElem; + + toElem.parentElement.insertBefore(toElem, fromElem); + + if (fromHasFocus) { + fromElem.focus(); + } else if (toHasFocus) { + toElem.focus(); + } + } + onKeyDown(e) { super.onKeyDown(e); @@ -81,6 +97,12 @@ class EditorLink extends EditorEntryBase { e.stopPropagation(); e.preventDefault(); break; + + case 'f': + this.flip(); + e.stopPropagation(); + e.preventDefault(); + break; } }