small refactor + fix brackets
authorJan Szejko <janek37@gmail.com>
Tue, 28 Feb 2017 15:46:42 +0000 (16:46 +0100)
committerJan Szejko <janek37@gmail.com>
Tue, 27 Mar 2018 15:02:51 +0000 (17:02 +0200)
(cherry picked from commit 6b06b64)

src/editor/plugins/core/core.js

index 4c58129..eda3c72 100644 (file)
@@ -192,7 +192,7 @@ plugin.documentExtension.documentNode.transformations = {
                         node: ret,
                         offset: ret.getText().length - len
                     };
                         node: ret,
                         offset: ret.getText().length - len
                     };
-                } else if(!toret) {
+                } else {
                     toret = {
                         node: ret.getFirstTextNode(),
                         offset: 0
                     toret = {
                         node: ret.getFirstTextNode(),
                         offset: 0
@@ -234,10 +234,12 @@ plugin.documentExtension.documentNode.transformations = {
                     return toMerge.is({tagName: 'div', 'klass': 'p'}) || (toMerge.is({tagName: 'div'}) && toMerge.getClass() === '');
                 },
                 run: function() {
                     return toMerge.is({tagName: 'div', 'klass': 'p'}) || (toMerge.is({tagName: 'div'}) && toMerge.getClass() === '');
                 },
                 run: function() {
-                    if(prev && (prev.is('p') || prev.is({tagName: 'header'}))) {
+                    if (!prev)
+                        return;
+                    if(prev.is('p') || prev.is({tagName: 'header'})) {
                         return merge(toMerge, prev);
                     }
                         return merge(toMerge, prev);
                     }
-                    if(prev && prev.is('list')) {
+                    if(prev.is('list')) {
                         var items = prev.contents().filter(function(n) { return n.is('item');});
                         return merge(toMerge, items[items.length-1]);
                     }
                         var items = prev.contents().filter(function(n) { return n.is('item');});
                         return merge(toMerge, items[items.length-1]);
                     }
@@ -294,7 +296,7 @@ plugin.documentExtension.documentNode.transformations = {
                     return toMerge.is({tagName: 'header'});
                 },
                 run: function() {
                     return toMerge.is({tagName: 'header'});
                 },
                 run: function() {
-                    if(prev && prev.is('p') || prev.is({tagName: 'header'})) {
+                    if(prev && (prev.is('p') || prev.is({tagName: 'header'}))) {
                         return merge(toMerge, prev);
                     }
                 }
                         return merge(toMerge, prev);
                     }
                 }