lib/gollum/public/gollum/livepreview/js/ace/lib/ace/mouse/default_gutter_handler.js in gollum-3.1.2 vs lib/gollum/public/gollum/livepreview/js/ace/lib/ace/mouse/default_gutter_handler.js in gollum-3.1.3

- old
+ new

@@ -29,22 +29,25 @@ * ***** END LICENSE BLOCK ***** */ define(function(require, exports, module) { "use strict"; var dom = require("../lib/dom"); +var oop = require("../lib/oop"); var event = require("../lib/event"); +var Tooltip = require("../tooltip").Tooltip; function GutterHandler(mouseHandler) { var editor = mouseHandler.editor; var gutter = editor.renderer.$gutterLayer; + var tooltip = new GutterTooltip(editor.container); mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) { - if (!editor.isFocused()) + if (!editor.isFocused() || e.getButton() != 0) return; var gutterRegion = gutter.getRegion(e); - if (gutterRegion) + if (gutterRegion == "foldWidgets") return; var row = e.getDocumentPosition().row; var selection = editor.session.selection; @@ -55,28 +58,19 @@ editor.selectAll(); return e.preventDefault(); } mouseHandler.$clickSelection = editor.selection.getLineRange(row); } - mouseHandler.captureMouse(e, "selectByLines"); + mouseHandler.setState("selectByLines"); + mouseHandler.captureMouse(e); return e.preventDefault(); }); - var tooltipTimeout, mouseEvent, tooltip, tooltipAnnotation; - function createTooltip() { - tooltip = dom.createElement("div"); - tooltip.className = "ace_gutter-tooltip"; - tooltip.style.maxWidth = "500px"; - tooltip.style.display = "none"; - editor.container.appendChild(tooltip); - } + var tooltipTimeout, mouseEvent, tooltipAnnotation; function showTooltip() { - if (!tooltip) { - createTooltip(); - } var row = mouseEvent.getDocumentPosition().row; var annotation = gutter.$annotations[row]; if (!annotation) return hideTooltip(); @@ -90,45 +84,45 @@ if (tooltipAnnotation == annotation) return; tooltipAnnotation = annotation.text.join("<br/>"); - tooltip.style.display = "block"; - tooltip.innerHTML = tooltipAnnotation; + tooltip.setHtml(tooltipAnnotation); + tooltip.show(); editor.on("mousewheel", hideTooltip); - moveTooltip(mouseEvent); + if (mouseHandler.$tooltipFollowsMouse) { + moveTooltip(mouseEvent); + } else { + var gutterElement = gutter.$cells[editor.session.documentToScreenRow(row, 0)].element; + var rect = gutterElement.getBoundingClientRect(); + var style = tooltip.getElement().style; + style.left = rect.right + "px"; + style.top = rect.bottom + "px"; + } } function hideTooltip() { if (tooltipTimeout) tooltipTimeout = clearTimeout(tooltipTimeout); if (tooltipAnnotation) { - tooltip.style.display = "none"; + tooltip.hide(); tooltipAnnotation = null; editor.removeEventListener("mousewheel", hideTooltip); } } function moveTooltip(e) { - var rect = editor.renderer.$gutter.getBoundingClientRect(); - tooltip.style.left = e.x - rect.left + 15 + "px"; - if (e.y + 3 * editor.renderer.lineHeight + 15 < rect.bottom) { - tooltip.style.bottom = ""; - tooltip.style.top = e.y - rect.top + 15 + "px"; - } else { - tooltip.style.top = ""; - tooltip.style.bottom = rect.bottom - e.y + 5 + "px"; - } + tooltip.setPosition(e.x, e.y); } 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) + if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse) moveTooltip(e); mouseEvent = e; if (tooltipTimeout) return; @@ -149,11 +143,39 @@ tooltipTimeout = setTimeout(function() { tooltipTimeout = null; hideTooltip(); }, 50); }); + + editor.on("changeSession", hideTooltip); +} +function GutterTooltip(parentNode) { + Tooltip.call(this, parentNode); } + +oop.inherits(GutterTooltip, Tooltip); + +(function(){ + this.setPosition = function(x, y) { + var windowWidth = window.innerWidth || document.documentElement.clientWidth; + var windowHeight = window.innerHeight || document.documentElement.clientHeight; + var width = this.getWidth(); + var height = this.getHeight(); + x += 15; + y += 15; + if (x + width > windowWidth) { + x -= (x + width) - windowWidth; + } + if (y + height > windowHeight) { + y -= 20 + height; + } + Tooltip.prototype.setPosition.call(this, x, y); + }; + +}).call(GutterTooltip.prototype); + + exports.GutterHandler = GutterHandler; });