Fixed caret management in Safari when inserting tables
authorAlexander Ebert <ebert@woltlab.com>
Tue, 12 Sep 2017 12:18:17 +0000 (14:18 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 12 Sep 2017 12:18:17 +0000 (14:18 +0200)
Fixes #2419

wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabTable.js

index bdb51a3283ab024af5e777456b279a320ff7b290..87bb77f9b9009f6b2941f526c36a7b2a8357f4f2 100644 (file)
@@ -6,6 +6,15 @@ $.Redactor.prototype.WoltLabTable = function() {
                        this.WoltLabEvent.register('insertedTable', (function() {
                                window.setTimeout((function () {
                                        var table = this.selection.block() || this.selection.current();
+                                       
+                                       // Safari sends the caret on a journey
+                                       if (table === this.$editor[0]) {
+                                               var selection = window.getSelection();
+                                               if (selection.isCollapsed && selection.anchorNode === this.$editor[0] && selection.anchorOffset > 0) {
+                                                       table = selection.anchorNode.childNodes[selection.anchorOffset - 1];
+                                               }
+                                       }
+                                       
                                        if (table.nodeName === 'TBODY') table = table.parentNode;
                                        if (table.nodeName === 'TABLE') {
                                                // remove whitespaces directly inside the table element