# all files / src/js/base/editing/ Typing.js

83.64% Statements 46/55
78.57% Branches 22/28
85.71% Functions 6/7
83.33% Lines 45/54

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    1181×
    1×
    1×
    1×
    1×
    1×

    1×
    2×

    103×
    103×

    1×
    1×
    1×
    1×
    1×
    1×

    1×
    8×

    8×

    8×

    8×
    8×

    8×

    8×

    8×
    8×
    2×

    6×
    5×

    8×

    5×

    5×
    1×

    5×
    5×
    4×

    1×

    3×

    3×
    3×
    3×

    3×

    8×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/editing/Typing.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var jquery_1 = require("jquery");
    var dom_1 = require("../core/dom");
    var range_1 = require("../core/range");
    var Bullet_1 = require("../editing/Bullet");
    /**
     * @class editing.Typing
     *
     * Typing
     *
     */
    var Typing = /** @class */ (function () {
        function Typing(context) {
            // a Bullet instance to toggle lists off
            this.bullet = new Bullet_1["default"]();
            this.options = context.options;
        }
        /**
         * insert tab
         *
         * @param {WrappedRange} rng
         * @param {Number} tabsize
         */
        Typing.prototype.insertTab = function (rng, tabsize) {
            var tab = dom_1["default"].createText(new Array(tabsize + 1).join(dom_1["default"].NBSP_CHAR));
            rng = rng.deleteContents();
            rng.insertNode(tab, true);
            rng = range_1["default"].create(tab, tabsize);
            rng.select();
        };
        /**
         * insert paragraph
         *
         * @param {jQuery} $editable
         * @param {WrappedRange} rng Can be used in unit tests to "mock" the range
         *
         * blockquoteBreakingLevel
         *   0 - No break, the new paragraph remains inside the quote
         *   1 - Break the first blockquote in the ancestors list
         *   2 - Break all blockquotes, so that the new paragraph is not quoted (this is the default)
         */
        Typing.prototype.insertParagraph = function (editable, rng) {
            rng = rng || range_1["default"].create(editable);
            // deleteContents on range.
            rng = rng.deleteContents();
            // Wrap range if it needs to be wrapped by paragraph
            rng = rng.wrapBodyInlineWithPara();
            // finding paragraph
            var splitRoot = dom_1["default"].ancestor(rng.sc, dom_1["default"].isPara);
            var nextPara;
            // on paragraph: split paragraph
            Eif (splitRoot) {
                // if it is an empty line with li
                Iif (dom_1["default"].isEmpty(splitRoot) && dom_1["default"].isLi(splitRoot)) {
                    // toogle UL/OL and escape
                    this.bullet.toggleList(splitRoot.parentNode.nodeName);
                    return;
                }
                else {
                    var blockquote = null;
                    if (this.options.blockquoteBreakingLevel === 1) {
                        blockquote = dom_1["default"].ancestor(splitRoot, dom_1["default"].isBlockquote);
                    }
                    else if (this.options.blockquoteBreakingLevel === 2) {
                        blockquote = dom_1["default"].lastAncestor(splitRoot, dom_1["default"].isBlockquote);
                    }
                    if (blockquote) {
                        // We're inside a blockquote and options ask us to break it
                        nextPara = jquery_1["default"](dom_1["default"].emptyPara)[0];
                        // If the split is right before a <br>, remove it so that there's no "empty line"
                        // after the split in the new blockquote created
                        if (dom_1["default"].isRightEdgePoint(rng.getStartPoint()) && dom_1["default"].isBR(rng.sc.nextSibling)) {
                            jquery_1["default"](rng.sc.nextSibling).remove();
                        }
                        var split = dom_1["default"].splitTree(blockquote, rng.getStartPoint(), { isDiscardEmptySplits: true });
                        if (split) {
                            split.parentNode.insertBefore(nextPara, split);
                        }
                        else {
                            dom_1["default"].insertAfter(nextPara, blockquote); // There's no split if we were at the end of the blockquote
                        }
                    }
                    else {
                        nextPara = dom_1["default"].splitTree(splitRoot, rng.getStartPoint());
                        // not a blockquote, just insert the paragraph
                        var emptyAnchors = dom_1["default"].listDescendant(splitRoot, dom_1["default"].isEmptyAnchor);
                        emptyAnchors = emptyAnchors.concat(dom_1["default"].listDescendant(nextPara, dom_1["default"].isEmptyAnchor));
                        jquery_1["default"].each(emptyAnchors, function (idx, anchor) {
                            dom_1["default"].remove(anchor);
                        });
                        // replace empty heading, pre or custom-made styleTag with P tag
                        Iif ((dom_1["default"].isHeading(nextPara) || dom_1["default"].isPre(nextPara) || dom_1["default"].isCustomStyleTag(nextPara)) && dom_1["default"].isEmpty(nextPara)) {
                            nextPara = dom_1["default"].replace(nextPara, 'p');
                        }
                    }
                }
                // no paragraph: insert empty paragraph
            }
            else {
                var next = rng.sc.childNodes[rng.so];
                nextPara = jquery_1["default"](dom_1["default"].emptyPara)[0];
                if (next) {
                    rng.sc.insertBefore(nextPara, next);
                }
                else {
                    rng.sc.appendChild(nextPara);
                }
            }
            range_1["default"].create(nextPara, 0).normalize().select().scrollIntoView(editable);
        };
        return Typing;
    }());
    exports["default"] = Typing;

    },'src/js/base/editing/Typing.js',{"jquery":"/Users/lqez/Dev/summernote/node_modules/jquery/dist/jquery.js","../core/dom":"/Users/lqez/Dev/summernote/src/js/base/core/dom.js","../core/range":"/Users/lqez/Dev/summernote/src/js/base/core/range.js","../editing/Bullet":"/Users/lqez/Dev/summernote/src/js/base/editing/Bullet.js"}];})(this);
    //# sourceMappingURL=data:application/json;charset=utf-8;base64,