show tooltips immediately
This commit is contained in:
parent
542364bf32
commit
9c1101c814
4 changed files with 112 additions and 4 deletions
|
|
@ -39,14 +39,16 @@
|
|||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
var dom = require("../lib/dom");
|
||||
var event = require("../lib/event");
|
||||
|
||||
function GutterHandler(mouseHandler) {
|
||||
var editor = mouseHandler.editor;
|
||||
var gutter = editor.renderer.$gutterLayer;
|
||||
|
||||
mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) {
|
||||
if (!editor.isFocused())
|
||||
return;
|
||||
var gutterRegion = editor.renderer.$gutterLayer.getRegion(e);
|
||||
var gutterRegion = gutter.getRegion(e);
|
||||
|
||||
if (gutterRegion)
|
||||
return;
|
||||
|
|
@ -62,6 +64,98 @@ function GutterHandler(mouseHandler) {
|
|||
mouseHandler.captureMouse(e, "selectByLines");
|
||||
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);
|
||||
}
|
||||
|
||||
function showTooltip() {
|
||||
if (!tooltip) {
|
||||
createTooltip();
|
||||
}
|
||||
var row = mouseEvent.getDocumentPosition().row;
|
||||
var annotation = gutter.$annotations[row];
|
||||
if (!annotation)
|
||||
return hideTooltip();
|
||||
|
||||
var maxRow = editor.session.getLength();
|
||||
if (row == maxRow) {
|
||||
var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row;
|
||||
var pos = mouseEvent.$pos;
|
||||
if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column))
|
||||
return hideTooltip();
|
||||
}
|
||||
|
||||
if (tooltipAnnotation == annotation)
|
||||
return;
|
||||
tooltipAnnotation = annotation.text.join("\n");
|
||||
|
||||
tooltip.style.display = "block";
|
||||
tooltip.innerHTML = tooltipAnnotation;
|
||||
editor.on("mousewheel", hideTooltip);
|
||||
|
||||
moveTooltip(mouseEvent);
|
||||
}
|
||||
|
||||
function hideTooltip() {
|
||||
if (tooltipTimeout)
|
||||
tooltipTimeout = clearTimeout(tooltipTimeout);
|
||||
if (tooltipAnnotation) {
|
||||
tooltip.style.display = "none";
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
moveTooltip(e);
|
||||
|
||||
mouseEvent = e;
|
||||
if (tooltipTimeout)
|
||||
return;
|
||||
tooltipTimeout = setTimeout(function() {
|
||||
tooltipTimeout = null;
|
||||
if (mouseEvent)
|
||||
showTooltip();
|
||||
else
|
||||
hideTooltip();
|
||||
}, 50);
|
||||
});
|
||||
|
||||
event.addListener(editor.renderer.$gutter, "mouseout", function(e) {
|
||||
mouseEvent = null;
|
||||
if (!tooltipAnnotation || tooltipTimeout)
|
||||
return;
|
||||
|
||||
tooltipTimeout = setTimeout(function() {
|
||||
tooltipTimeout = null;
|
||||
hideTooltip();
|
||||
}, 50);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
exports.GutterHandler = GutterHandler;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue