From 0c48ef6426aa8cc1f4685124d03c92704a21be99 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 5 Jan 2017 13:43:18 +0100 Subject: [PATCH] Fixed caret behavior for inserted tables --- com.woltlab.wcf/templates/wysiwyg.tpl | 2 ++ .../install/files/acp/templates/wysiwyg.tpl | 2 ++ .../redactor2/plugins/WoltLabBlock.js | 4 ++-- .../redactor2/plugins/WoltLabTable.js | 20 +++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index 0e60cf9c78..e1b9aef229 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -40,6 +40,7 @@ '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSmiley.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSource.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSpoiler.js?v={@LAST_UPDATE_TIME}', + '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabTable.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabUtils.js?v={@LAST_UPDATE_TIME}' {else} '{@$__wcf->getPath()}js/3rdParty/redactor2/redactor.min.js?v={@LAST_UPDATE_TIME}', @@ -208,6 +209,7 @@ 'WoltLabSmiley', 'WoltLabSource', 'WoltLabSpoiler', + 'WoltLabTable', 'WoltLabUtils' ], toolbarFixed: false, diff --git a/wcfsetup/install/files/acp/templates/wysiwyg.tpl b/wcfsetup/install/files/acp/templates/wysiwyg.tpl index 0e60cf9c78..e1b9aef229 100644 --- a/wcfsetup/install/files/acp/templates/wysiwyg.tpl +++ b/wcfsetup/install/files/acp/templates/wysiwyg.tpl @@ -40,6 +40,7 @@ '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSmiley.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSource.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSpoiler.js?v={@LAST_UPDATE_TIME}', + '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabTable.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabUtils.js?v={@LAST_UPDATE_TIME}' {else} '{@$__wcf->getPath()}js/3rdParty/redactor2/redactor.min.js?v={@LAST_UPDATE_TIME}', @@ -208,6 +209,7 @@ 'WoltLabSmiley', 'WoltLabSource', 'WoltLabSpoiler', + 'WoltLabTable', 'WoltLabUtils' ], toolbarFixed: false, diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js index 9a4e1feac4..e8afa1779f 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabBlock.js @@ -32,8 +32,8 @@ $.Redactor.prototype.WoltLabBlock = function() { var mpFormatCollapsed = this.block.formatCollapsed; this.block.formatCollapsed = (function(tag, attr, value, type) { var block = this.selection.block(); - if (block && block.nodeName === 'LI') { - // lists cannot contain other block elements + if (block && (block.nodeName === 'LI' || block.nodeName === 'TD')) { + // tables/lists cannot contain other block elements return; } diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js new file mode 100644 index 0000000000..06fed1941e --- /dev/null +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js @@ -0,0 +1,20 @@ +$.Redactor.prototype.WoltLabTable = function() { + "use strict"; + + return { + init: function() { + this.WoltLabEvent.register('insertedTable', (function() { + window.setTimeout((function () { + var node = this.selection.block() || this.selection.current(); + if (node.nodeName === 'TBODY') { + // find first and set the caret inside it + var td = elBySel('td', node); + if (td) { + this.caret.end(td); + } + } + }).bind(this), 10); + }).bind(this)); + } + } +}; -- 2.20.1