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

// FIXME: cursor does not display correctly if it is after a space at the end of the line

(function() {

    var selectionDivs = new Array();
    var selectionRange = null;

    // public
    function updateSelectionDisplay()
    {
        for (var i = 0; i < selectionDivs.length; i++)
            selectionDivs[i].parentNode.removeChild(selectionDivs[i]);
        selectionDivs = new Array();

        var rects = null;
        if (selectionRange != null)
            rects = selectionRange.getClientRects();

        if ((selectionRange != null) && selectionRange.isEmpty()) {
            // We just have a cursor
            if ((rects != null) && (rects.length > 0)) {
                left = rects[0].left + window.scrollX;
                top = rects[0].top + window.scrollY;
                width = rects[0].width;<commit_msg>Correctly place the cursor when it is after a space at the end of a paragraph.<commit_after>// Copyright (c) 2011-2012 UX Productivity. All rights reserved.

// FIXME: cursor does not display correctly if it is after a space at the end of the line

(function() {

    var selectionDivs = new Array();
    var selectionRange = null;

    // public
    function updateSelectionDisplay()
    {
        for (var i = 0; i < selectionDivs.length; i++)
            selectionDivs[i].parentNode.removeChild(selectionDivs[i]);
        selectionDivs = new Array();

        var rects = null;
        if (selectionRange != null)
            rects = selectionRange.getClientRects();

        if ((selectionRange != null) && selectionRange.isEmpty()) {

            // We just have a cursor

            if ((rects != null) && (rects.length == 0)) {

                // If the cursor is at the end of a paragraph and the last character is a space,
                // getClientRects() fails to return anything. So instead, we temporarily add a
                // single character to the end of the paragraph, get the client rect for that,
                // and then remove the character. This client rect will be in the same location
                // as the cursor placed at the end of the space.

                    var node = selectionRange.start.node;
                    var offset = selectionRange.start.offset;

                if ((node.nodeType == Node.TEXT_NODE) && (offset == node.nodeValue.length)) {
                    var tempNode = document.createTextNode("X");
                    node.parentNode.insertBefore(tempNode,node.nextSibling);
                    var tempRange = new Range(new Position(tempNode,0),
                                              new Position(tempNode,0));
                    rects = tempRange.getClientRects();
                    node.parentNode.removeChild(tempNode);
                }
            }

            var left;
            var top;
            var width;
            var height;

            if ((rects != null) && (rects.length > 0)) {
                left = rects[0].left + window.scrollX;
                top = rects[0].top + window.scrollY;
                width = rects[0].width;
{'fraction_non_alphanumeric': 0.09980928162746344, 'fraction_numerical': 0.009218054672600126, 'mean_word_length': 1.807314897413024, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5784576', 'n_tokens_mistral': 839, 'n_tokens_neox': 789, 'n_words': 276}