From d14d099a1263e78d39dcf2e4969d171d03432a12 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 12 Nov 2017 21:14:16 +0100 Subject: [PATCH] Added (shift+)tab-key navigation inside tables --- .../redactor2/plugins/WoltLabKeydown.js | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js index 4c32db8a5e..fc1b59bf21 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js @@ -401,8 +401,67 @@ $.Redactor.prototype.WoltLabKeydown = function() { var mpOnTab = this.keydown.onTab; this.keydown.onTab = (function(e, key) { - if (!this.keydown.pre && $(this.selection.current()).closest('ul, ol', this.core.editor()[0]).length === 0) { - return true; + if (!this.keydown.pre) { + var closestRelevantBlock = $(this.selection.current()).closest('ul, ol, td', this.core.editor()[0]); + if (closestRelevantBlock.length === 0) { + // ignore tab, the browser's default action will be executed + return true; + } + + closestRelevantBlock = closestRelevantBlock[0]; + if (closestRelevantBlock.nodeName === 'TD') { + var target = null; + + if (e.originalEvent.shiftKey) { + target = closestRelevantBlock.previousElementSibling; + + // first `` of current `` + if (target === null) { + target = closestRelevantBlock.parentNode.previousElementSibling; + + if (target !== null) { + // set focus to last `` + target = target.lastElementChild; + } + } + } + else { + target = closestRelevantBlock.nextElementSibling; + + // last `` of current `` + if (target === null) { + target = closestRelevantBlock.parentNode.nextElementSibling; + + // last `` + if (target === null) { + this.table.addRowBelow(); + + target = closestRelevantBlock.parentNode.nextElementSibling; + } + + // set focus to first `` + target = target.firstElementChild; + } + } + + if (target !== null) { + if (this.utils.isEmpty(target.innerHTML)) { + // `` is empty + this.caret.end(target); + } + else { + // select the entire content + var range = document.createRange(); + range.selectNodeContents(target); + + selection.removeAllRanges(); + selection.addRange(range); + } + } + + e.originalEvent.preventDefault(); + return false; + } } return mpOnTab.call(this, e, key); -- 2.20.1