<commit_before>// Copyright (c) 2011-2012 UX Productivity Pty Ltd. All rights reserved.


(function() {

    var insertionNode = null;
    var insertionTextBefore = null;
    var insertionTextAfter = null;

    // public
    function ensureCursorVisible()
    {
        var rect = Selection.getCursorRect();
        if (rect != null) {
            var cursorY = rect.top + window.scrollY + rect.height/2;
            if ((cursorY < window.scrollY) ||
                (cursorY > window.scrollY + window.innerHeight)) {
                var newScrollY = cursorY - window.innerHeight/2;
                if (newScrollY < 0)
                    newScrollY = 0;
                window.scrollTo(window.scrollX,newScrollY);
            }
        }
    }

    // public
    function isValidCursorPosition(pos)
    {
        var result = false;

        var node = pos.node;
        var offset = pos.offset;

        if (isOpaqueNode(node))
            return false;

        if (node.nodeType == Node.TEXT_NODE) {
            var value = node.nodeValue;
            var prev = node.previousSibling;
            var next = node.nextSibling;

            // Immediately after a non-whitespace character -> YES
            if ((offset > 0) && !isWhitespaceString(value.charAt(offset-1)))
                result = true;

            // At the end of a text node (with no next sibling), and the preceding character
            // is a whitespace character, but there is a non-whitespace character before it -> YES
            if (isWhitespaceString(value.slice(offset)) &&
                (offset >= 2) &&
                isWhitespaceString(value.charAt(offset-1)) &&
                !isWhitespaceString(value.charAt(offset-2)) &&
                (node.nextSibling == null)) {
                result = true;
            }

            // Immediately before a non-whitespace character -> YES
            if ((offset < value.length) && !isWhitespaceString(value.charAt(offset)))
                result = true;

            // Right at the end of a whitespace node which is the first child in a paragraph,
            // and has no next sibling, or is followed by a BR -> YES
            if ((offset == value.length) &&
                !isInlineNode(node.parentNode) &&
                isWhitespaceTextNode(node) &&
                (prev == null) &&
                ((next == null) || (DOM.upperName(next) == "BR")))
                result = true;
        }
        else if (node.nodeType == Node.ELEMENT_NODE) {
            var prev = (offset == 0) ? null : node.childNodes[offset-1];
            var next = (offset >= node.childNodes.length) ? null : node.childNodes[offset];

            // Directly after an IMG, TABLE, UL, or OL -> YES
            if ((prev != null) &&
                ((DOM.upperName(prev) == "IMG") ||
                 (DOM.upperName(prev) == "TABLE") ||
                 (DOM.upperName(prev) == "UL") ||
                 (DOM.upperName(prev) == "OL")))
                result = true;

            // Directly before an IMG, TABLE, UL, or OL -> YES
            if ((next != null) &&
                ((DOM.upperName(next) == "IMG") ||
                 (DOM.upperName(next) == "TABLE") ||
                 (DOM.upperName(next) == "UL") ||
                 (DOM.upperName(next) == "OL")))
                result = true;

            // In an empty paragraph or one that only contains a BR
            if ((prev == null) && (next != null) && (DOM.upperName(next) == "BR"))
                result = true;

            if ((prev == null) && (next == null) &&
                (isParagraphNode(node) ||
                 INLINE_ELEMENTS_THAT_CAN_HAVE_CHILDREN[DOM.upperName(node)]))
                result = true;

            // Special case for an IMG that directly follows some text that ends in a
            // non-whitespace character. The cursor will be allowed at the end of the text
            // node, so we don't want to allow it before the image (which corresponds to the
            // same location on screen)
            if ((next != null) && (prev != null) &&
                (DOM.upperName(next) == "IMG") &&
                (prev.nodeType == Node.TEXT_NODE) &&
                (prev.nodeValue.length > 0) &&
                !isWhitespaceString(prev.nodeValue.charAt(prev.nodeValue.length-1))) {
                result = false;<commit_msg>Don't consider the position directly before or after a UL or OL element to be valid<commit_after>// Copyright (c) 2011-2012 UX Productivity Pty Ltd. All rights reserved.


(function() {

    var insertionNode = null;
    var insertionTextBefore = null;
    var insertionTextAfter = null;

    // public
    function ensureCursorVisible()
    {
        var rect = Selection.getCursorRect();
        if (rect != null) {
            var cursorY = rect.top + window.scrollY + rect.height/2;
            if ((cursorY < window.scrollY) ||
                (cursorY > window.scrollY + window.innerHeight)) {
                var newScrollY = cursorY - window.innerHeight/2;
                if (newScrollY < 0)
                    newScrollY = 0;
                window.scrollTo(window.scrollX,newScrollY);
            }
        }
    }

    // public
    function isValidCursorPosition(pos)
    {
        var result = false;

        var node = pos.node;
        var offset = pos.offset;

        if (isOpaqueNode(node))
            return false;

        if (node.nodeType == Node.TEXT_NODE) {
            var value = node.nodeValue;
            var prev = node.previousSibling;
            var next = node.nextSibling;

            // Immediately after a non-whitespace character -> YES
            if ((offset > 0) && !isWhitespaceString(value.charAt(offset-1)))
                result = true;

            // At the end of a text node (with no next sibling), and the preceding character
            // is a whitespace character, but there is a non-whitespace character before it -> YES
            if (isWhitespaceString(value.slice(offset)) &&
                (offset >= 2) &&
                isWhitespaceString(value.charAt(offset-1)) &&
                !isWhitespaceString(value.charAt(offset-2)) &&
                (node.nextSibling == null)) {
                result = true;
            }

            // Immediately before a non-whitespace character -> YES
            if ((offset < value.length) && !isWhitespaceString(value.charAt(offset)))
                result = true;

            // Right at the end of a whitespace node which is the first child in a paragraph,
            // and has no next sibling, or is followed by a BR -> YES
            if ((offset == value.length) &&
                !isInlineNode(node.parentNode) &&
                isWhitespaceTextNode(node) &&
                (prev == null) &&
                ((next == null) || (DOM.upperName(next) == "BR")))
                result = true;
        }
        else if (node.nodeType == Node.ELEMENT_NODE) {
            var prev = (offset == 0) ? null : node.childNodes[offset-1];
            var next = (offset >= node.childNodes.length) ? null : node.childNodes[offset];

            // Directly after an IMG, TABLE, UL, or OL -> YES
            if ((prev != null) &&
                ((DOM.upperName(prev) == "IMG") ||
                 (DOM.upperName(prev) == "TABLE")))
                result = true;

            // Directly before an IMG, TABLE, UL, or OL -> YES
            if ((next != null) &&
                ((DOM.upperName(next) == "IMG") ||
                 (DOM.upperName(next) == "TABLE")))
                result = true;

            // In an empty paragraph or one that only contains a BR
            if ((prev == null) && (next != null) && (DOM.upperName(next) == "BR"))
                result = true;

            if ((prev == null) && (next == null) &&
                (isParagraphNode(node) || (DOM.upperName(node) == "LI") ||
                 INLINE_ELEMENTS_THAT_CAN_HAVE_CHILDREN[DOM.upperName(node)]))
                result = true;

            // Special case for an IMG that directly follows some text that ends in a
            // non-whitespace character. The cursor will be allowed at the end of the text
            // node, so we don't want to allow it before the image (which corresponds to the
            // same location on screen)
            if ((next != null) && (prev != null) &&
                (DOM.upperName(next) == "IMG") &&
                (prev.nodeType == Node.TEXT_NODE) &&
                (prev.nodeValue.length > 0) &&
                !isWhitespaceString(prev.nodeValue.charAt(prev.nodeValue.length-1))) {
                result = false;
{'fraction_non_alphanumeric': 0.12007896876088724, 'fraction_numerical': 0.004877482290094066, 'mean_word_length': 1.6200182537268026, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7268388', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2292, 'n_words': 670}