Example #1
0
    this.onMousedown = function(e) {
        var target = e.domEvent.target;
        if (target == this.closeButton)
            return this.removeData();

        if (target == this.resizer) {
            var rect = this.editor.blameGutter.element.getBoundingClientRect();
            var mouseHandler = this.editor.$mouseHandler;
            mouseHandler.resizeBlameGutter = function() {
                var gutterWidth = this.x + 40 - rect.left;
                this.editor.renderer.$gutter.style.width = gutterWidth + "px";
                this.editor.blameGutter.element.style.width = gutterWidth - 40 + "px";
                this.editor.renderer.$gutterLayer._emit("changeGutterWidth", gutterWidth);
            };
            mouseHandler.captureMouse(e, "resizeBlameGutter");
            return;
        }

        if (dom.hasCssClass(target, "ace_blame-cell")) {
            var gutter = this.editor.renderer.$gutterLayer;
            var index = parseInt(target.getAttribute("index"));

            var blameCell = gutter.blameData[index];
            if (!blameCell)
                return;
            gutter.selectedText = blameCell.text;
            var ch = target.parentNode.children;
            for (var i = ch.length; i--; ) {
                var isSelected = ch[i].innerHTML.indexOf(gutter.selectedText) == 0;
                ch[i].className = "ace_blame-cell" + (isSelected ? " selected" : "");
            }
        }
    };
    mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) {
        var target = e.domEvent.target || e.domEvent.srcElement;
        if (dom.hasCssClass(target, "ace_fold-widget"))
            return hideTooltip();

        if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse)
            moveTooltip(e);

        mouseEvent = e;
        if (tooltipTimeout)
            return;
        tooltipTimeout = setTimeout(function() {
            tooltipTimeout = null;
            if (mouseEvent && !mouseHandler.isMousePressed)
                showTooltip();
            else
                hideTooltip();
        }, 50);
    });
Example #3
0
    this.onMousemove = function(e) {
        var target = e.target;
        var container = e.currentTarget;
        var tooltip = this.editor.tooltip;
        if (this.$highlightedCell != target) {
            if (dom.hasCssClass(target, "ace_blame-cell")) {
                tooltip.style.display = "block";
                this.$highlightedCell = target;
                tooltip.textContent = target.textContent;
            }
        }

        if (this.$highlightedCell) {
            tooltip.style.top = e.clientY + 10 + "px";
            tooltip.style.left = e.clientX + 10 + "px";
        } else {
            this.onMouseout();
            return
        }
    };
Example #4
0
    mouseHandler.drag = function() {
        var ev = this.mouseEvent;
        if (!dragInfo || !ev) return;
        var node = ev.getNode();
        dx = ev.x - x;
        dy = ev.y - y;
        x = ev.x;
        y = ev.y;
        var isInTree = isInRect(x, y, scrollerRect);
        if (!isInTree) {
            node = null;
        }
        
        if (dragInfo.isInTree != isInTree && dragInfo.selectedNodes) {
            dragInfo.isInTree = isInTree;
            ev.dragInfo = dragInfo;
            tree._signal(isInTree ? "dragIn" : "dragOut" , ev);
        }
        if (!isInTree) {
            ev.dragInfo = dragInfo;
            tree._signal("dragMoveOutside", ev);
        }
        
        if (dragInfo.el) {
            dragInfo.el.style.top = ev.y - dragInfo.offsetY + "px";
            dragInfo.el.style.left = ev.x - dragInfo.offsetX + "px";
        }
        
        var hoverNode = node;
        if (hoverNode) {
            var xOffset = x - scrollerRect.left;
            
            var depth = Math.max(0, Math.floor(xOffset / tree.provider.$indentSize));
            var depthDiff = hoverNode.$depth - depth;
            while (depthDiff > 0 && hoverNode.parent) {
                depthDiff--;
                hoverNode = hoverNode.parent;
            }
            
            if (!hoverNode.isFolder) {
                hoverNode = hoverNode.parent;
            }
        }
        
        if (dragInfo.hoverNode !== hoverNode) {
            if (dragInfo.hoverNode) {
                tree.provider.setClass(dragInfo.hoverNode, "dropTarget", false);
                tree._signal("folderDragLeave", dragInfo.hoverNode);
            }
            if (hoverNode && dragInfo.selectedNodes && dragInfo.selectedNodes.indexOf(hoverNode) != -1) {
                hoverNode = null;
            }
            dragInfo.hoverNode = hoverNode;
            if (dragInfo.hoverNode) {
                tree.provider.setClass(dragInfo.hoverNode, "dropTarget", true);
                tree._signal("folderDragEnter", dragInfo.hoverNode);
            }
            highlightFolder(tree, hoverNode);                        
        }
        
        var now = Date.now();

        var target = ev.domEvent.target;
        var isFoldWidget = target && dom.hasCssClass(target, "toggler") 
            && !dom.hasCssClass(target, "empty");
        
        var distance = Math.abs(dx) + Math.abs(dy);
        
        var pos = ev.y - scrollerRect.top;
        var rowHeight = tree.provider.rowHeight;
        var renderer = tree.renderer;
        var autoScrollMargin = 1.5 * rowHeight;
        var scroll = pos - autoScrollMargin;
        if (scroll > 0) {
            scroll += -renderer.$size.scrollerHeight + 2 * autoScrollMargin;
            if (scroll < 0)
                scroll = 0;
        }
        if (!scroll || !isInTree)
            dragInfo.autoScroll = false;
        
        if (distance <= 2) {
            if (!dragInfo.stopTime)
                dragInfo.stopTime = now;
        } else {
            if (!isFoldWidget)
                dragInfo.stopTime = undefined;
        }
        var dt = now - dragInfo.stopTime;
        
        if (scroll && isInTree) {
            if (dt > AUTOSCROLL_DELAY || dragInfo.autoScroll) {
                tree.renderer.scrollBy(0, scroll / 2);
                dragInfo.autoScroll = true;
            }
        }
        else if (node && node.parent !== tree.provider.root) {
            if (isFoldWidget && dt > WIDGET_UNFOLD_TIMEOUT && dt < 2 * WIDGET_UNFOLD_TIMEOUT) {
                tree.provider.toggleNode(node);
                dragInfo.stopTime = Infinity;
            }
            else if (!isFoldWidget && dt > UNFOLD_TIMEOUT && dt < 2 * UNFOLD_TIMEOUT) {
                tree.provider.open(node);
                dragInfo.stopTime = Infinity;
            }
        }
    };
Example #5
0
/**
 *
 *
 * Creates a new `Search` object. The following search options are avaliable:
 *
 * - `needle`: The string or regular expression you're looking for
 * - `backwards`: Whether to search backwards from where cursor currently is. Defaults to `false`.
 * - `wrap`: Whether to wrap the search back to the beginning when it hits the end. Defaults to `false`.
 * - `caseSensitive`: Whether the search ought to be case-sensitive. Defaults to `false`.
 * - `wholeWord`: Whether the search matches only on whole words. Defaults to `false`.
 * - `range`: The [[Range]] to search within. Set this to `null` for the whole document
 * - `regExp`: Whether the search is a regular expression or not. Defaults to `false`.
 * - `start`: The starting [[Range]] or cursor position to begin the search
 * - `skipCurrent`: Whether or not to include the current line in the search. Default to `false`.
 *
 * @constructor
 **/
function Finder(data) {
    var dom = require("ace/lib/dom");
    var event = require("ace/lib/event");

    this.searchInput = null;
    this.replaceInput = null;
    this.replaceText = null;
    this.fineNextBtn = null;

    var options = {};
    options['needle'] = data['findText'];
    if (data['regex']) {
        options['regExp'] = true;
    }
    options['wholeWord'] = data['wholeWordOnly'];
    options['caseSensitive'] = data['caseSensitive'];
    options['wrap'] = true;

    var searchBar = dom.createElement("div");
    searchBar.id = "searchbar";
    if (dom.hasCssClass(editor.container, "ace_dark")) {
        searchBar.className = "ace_dark";
    }

    this.show = function () {
        var old = document.getElementById(searchBar.id);
        if (old) {
            old.parentNode.removeChild(old);
        }
        this.createSearchBox();
        if (data['replaceText'] || data['replaceText'] === "") {
            this.createReplaceBox();
        }

        var closeBox = dom.createElement("div");
        closeBox.id = "close_box";
        var closeBtn = dom.createElement("i");
        closeBtn.className = "css-icon icon-up-open-big";
        closeBtn.innerHTML = "&#xe805;";
        closeBox.appendChild(closeBtn);
        event.addListener(closeBox, 'click', function (e) {
            editor.container.style.top = "0px";
            searchBar.parentNode.removeChild(searchBar);
            editor.clearSelection();
        });
        searchBar.appendChild(closeBox);

        document.body.appendChild(searchBar);

        editor.container.style.top = searchBar.clientHeight + "px";
        this.fineNextBtn.click();
    };

    this.updateData = function () {
        if (this.searchInput) {
            options['needle'] = this.searchInput.value;
        }
        if (this.replaceInput) {
            this.replaceText = this.replaceInput.value;
        }
    };

    this.createSearchBox = function () {
        var self = this;
        var searchBox = dom.createElement("div");
        searchBox.id = "search_box";

        var searchInput = dom.createElement("input");
        searchInput.setAttribute("type", "text");
        searchInput.value = data['findText'];
        searchBox.appendChild(searchInput);
        this.searchInput = searchInput;

        var finePrevBtn = dom.createElement("i");
        finePrevBtn.className = "css-icon icon-up-1";
        finePrevBtn.innerHTML = "&#xe802;";
        event.addListener(finePrevBtn, 'click', function (e) {
            self.updateData();
            editor.findPrevious(options, true);
        });
        searchBox.appendChild(finePrevBtn);

        var fineNextBtn = dom.createElement("i");
        fineNextBtn.className = "css-icon icon-down";
        fineNextBtn.innerHTML = "&#xe801;";
        event.addListener(fineNextBtn, 'click', function (e) {
            self.updateData();
            editor.findNext(options, true);
        });
        searchBox.appendChild(fineNextBtn);
        this.fineNextBtn = fineNextBtn;

        searchBar.appendChild(searchBox);
    };

    this.createReplaceBox = function () {
        var self = this;
        var replaceBox = dom.createElement("div");
        replaceBox.id = "replace_box";

        var replaceInput = dom.createElement("input");
        replaceInput.setAttribute("type", "text");
        replaceBox.appendChild(replaceInput);
        this.replaceInput = replaceInput;

        var replaceOnceBtn = dom.createElement("i");
        replaceOnceBtn.className = "css-icon icon-ccw";
        replaceOnceBtn.innerHTML = "&#xe803;";
        event.addListener(replaceOnceBtn, 'click', function (e) {
            self.updateData();
            editor.replace(self.replaceText, options);
            editor.clearSelection();
        });
        replaceBox.appendChild(replaceOnceBtn);

        var replaceAllBtn = dom.createElement("i");
        replaceAllBtn.className = "css-icon icon-arrows-ccw";
        replaceAllBtn.innerHTML = "&#xe804;";
        event.addListener(replaceAllBtn, 'click', function (e) {
            self.updateData();
            editor.replaceAll(self.replaceText, options);
            editor.clearSelection();
        });
        replaceBox.appendChild(replaceAllBtn);

        searchBar.appendChild(replaceBox);
    };
}