<commit_before><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Rangy CSS Find Demo</title>
    <link href="demo.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        *.searchResult {
            font-weight: bold;
            background-color: yellow;
        }
    </style>
    <script type="text/javascript" src="../lib/log4javascript.js"></script>
    <script type="text/javascript" src="../src/js/core/core.js"></script>
    <script type="text/javascript" src="../src/js/core/dom.js"></script>
    <script type="text/javascript" src="../src/js/core/domrange.js"></script>
    <script type="text/javascript" src="../src/js/core/wrappedrange.js"></script>
    <script type="text/javascript" src="../src/js/core/wrappedselection.js"></script>
    <script type="text/javascript" src="../src/js/modules/rangy-textrange.js"></script>
    <script type="text/javascript" src="../src/js/modules/rangy-cssclassapplier.js"></script>
    <script type="text/javascript">
        function gEBI(id) {
            return document.getElementById(id);
        }

        var searchResultApplier;

        function toggleItalicYellowBg() {
            searchResultApplier.toggleSelection();
        }

        window.onload = function() {
            rangy.init();

            // Enable buttons
            var cssClassApplierModule = rangy.modules.CssClassApplier;
            if (rangy.supported && cssClassApplierModule && cssClassApplierModule.supported) {
                searchResultApplier = rangy.createCssClassApplier("searchResult", true);

                var searchBox = gEBI("search"),
                    regexCheckBox = gEBI("regex"),
                    caseSensitiveCheckBox = gEBI("caseSensitive"),
                    timer;

                function doSearch() {
                    // Remove existing highlights
                    var range = rangy.createRange();
                    var caseSensitive = caseSensitiveCheckBox.checked;

                    range.selectNodeContents(document.body);
                    searchResultApplier.undoToRange(range);

                    // Create search term
                    var searchTerm = searchBox.value;

                    if (searchTerm !== "") {
                        if (regexCheckBox.checked) {
                            searchTerm = new RegExp(searchTerm, caseSensitive ? "g" : "gi");
                        }

                        // Get matching ranges
                        var start = new Date();
                        var matchRanges = range.match(searchTerm, caseSensitive);
                        //alert(new Date() - start);

                        // Apply search result class to each range, in reverse order so that ranges are not affected
                        // by changes to ranges earlier in the document
                        var i = matchRanges.length;
                        while (i--) {
                            searchResultApplier.applyToRange(matchRanges[i]);
                        }
                    }

                    timer = null;
                }

                function scheduleSearch() {
                    if (timer) {
                        window.clearTimeout(timer);
                    }
                    timer = window.setTimeout(doSearch, 500);
                }

                searchBox.onpropertychange = function() {
                    if (window.event.propertyName == "value") {
                        scheduleSearch();
                    }
                };<commit_msg>Fixed find demo properly by implementing findText() much like IE<commit_after><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Rangy Find Demo</title>
    <link href="demo.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        *.searchResult {
            font-weight: bold;
            background-color: yellow;
        }
    </style>
    <script type="text/javascript" src="../lib/log4javascript.js"></script>
    <script type="text/javascript" src="../src/js/core/core.js"></script>
    <script type="text/javascript" src="../src/js/core/dom.js"></script>
    <script type="text/javascript" src="../src/js/core/domrange.js"></script>
    <script type="text/javascript" src="../src/js/core/wrappedrange.js"></script>
    <script type="text/javascript" src="../src/js/core/wrappedselection.js"></script>
    <script type="text/javascript" src="../src/js/modules/rangy-textrange.js"></script>
    <script type="text/javascript" src="../src/js/modules/rangy-cssclassapplier.js"></script>
    <script type="text/javascript">
        function gEBI(id) {
            return document.getElementById(id);
        }

        var searchResultApplier;

        function toggleItalicYellowBg() {
            searchResultApplier.toggleSelection();
        }

        window.onload = function() {
            rangy.init();

            // Enable buttons
            var cssClassApplierModule = rangy.modules.CssClassApplier;
            if (rangy.supported && cssClassApplierModule && cssClassApplierModule.supported) {
                searchResultApplier = rangy.createCssClassApplier("searchResult", true);

                var searchBox = gEBI("search"),
                    regexCheckBox = gEBI("regex"),
                    caseSensitiveCheckBox = gEBI("caseSensitive"),
                    timer;

                function doSearch() {
                    // Remove existing highlights
                    var range = rangy.createRange();
                    var caseSensitive = caseSensitiveCheckBox.checked;

                    range.selectNodeContents(document.body);
                    searchResultApplier.undoToRange(range);

                    // Create search term
                    var searchTerm = searchBox.value;

                    if (searchTerm !== "") {
                        if (regexCheckBox.checked) {
                            searchTerm = new RegExp(searchTerm, caseSensitive ? "g" : "gi");
                        }

                        // Iterate over matches
                        while (range.findText(searchTerm, caseSensitive)) {
                            // range now encompasses the first text match
                            searchResultApplier.applyToRange(range);

                            // Move the range to start after the match and end at the end of the document
                            range.collapse(false);
                            range.setEndAfter(document.body);
                        }
                    }

                    timer = null;
                }

                function scheduleSearch() {
                    if (timer) {
                        window.clearTimeout(timer);
                    }
                    timer = window.setTimeout(doSearch, 500);
                }

                searchBox.onpropertychange = function() {
                    if (window.event.propertyName == "value") {
                        scheduleSearch();
                    }
                };
{'fraction_non_alphanumeric': 0.11770455180117285, 'fraction_numerical': 0.0027925160569673277, 'mean_word_length': 1.5150983146067416, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1625379', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1720, 'n_words': 340}