From e9434fc1df47a229cdb0afcce8f36a388c8843d3 Mon Sep 17 00:00:00 2001 From: Eric Arnold Date: Thu, 9 Jan 2014 13:29:51 -0800 Subject: [PATCH 1/2] Added option for annotation tooltip to be floating (follows mouse, current functionality) or fixed (stationary per annotation). --- lib/ace/editor.js | 13 +++++++++++++ lib/ace/mouse/default_gutter_handler.js | 13 +++++++++++-- lib/ace/mouse/mouse_handler.js | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index dfca96b8..a9cbc7f1 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -1029,6 +1029,18 @@ var Editor = function(renderer, session) { this.getHighlightGutterLine = function() { return this.getOption("highlightGutterLine"); }; + + /** + * Determines if the annotation tooltip follows the mouse or is stationary to the annotation. + * @return {Boolean} + **/ + this.setTooltipFollowsMouse = function(tooltipShouldFollowMouse) { + this.setOption("tooltipFollowsMouse", tooltipShouldFollowMouse); + }; + this.getTooltipFollowsMouse = function() { + return this.getOption("tooltipFollowsMouse"); + }; + /** * Determines if the currently selected word should be highlighted. * @param {Boolean} shouldHighlight Set to `true` to highlight the currently selected word @@ -2432,6 +2444,7 @@ config.defineOptions(Editor.prototype, "editor", { dragDelay: "$mouseHandler", dragEnabled: "$mouseHandler", focusTimout: "$mouseHandler", + tooltipFollowsMouse: "$mouseHandler", firstLineNumber: "session", overwrite: "session", diff --git a/lib/ace/mouse/default_gutter_handler.js b/lib/ace/mouse/default_gutter_handler.js index 1ad8119c..d9e90297 100644 --- a/lib/ace/mouse/default_gutter_handler.js +++ b/lib/ace/mouse/default_gutter_handler.js @@ -96,7 +96,16 @@ function GutterHandler(mouseHandler) { tooltip.innerHTML = tooltipAnnotation; editor.on("mousewheel", hideTooltip); - moveTooltip(mouseEvent); + if (mouseHandler.$tooltipFollowsMouse) { + moveTooltip(mouseEvent); + } else { + gutterElement = gutter.$cells[row].element; + var rect = gutterElement.getBoundingClientRect(); + var tooltipLeft = rect.right; + var tooltipTop = rect.top + Math.round(rect.height / 2); + tooltip.style.left = tooltipLeft + "px"; + tooltip.style.top = tooltipTop - 5 + "px"; + } } function hideTooltip() { @@ -127,7 +136,7 @@ function GutterHandler(mouseHandler) { if (dom.hasCssClass(target, "ace_fold-widget")) return hideTooltip(); - if (tooltipAnnotation) + if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse) moveTooltip(e); mouseEvent = e; diff --git a/lib/ace/mouse/mouse_handler.js b/lib/ace/mouse/mouse_handler.js index d9f6188f..47457f17 100644 --- a/lib/ace/mouse/mouse_handler.js +++ b/lib/ace/mouse/mouse_handler.js @@ -153,7 +153,8 @@ config.defineOptions(MouseHandler.prototype, "mouseHandler", { scrollSpeed: {initialValue: 2}, dragDelay: {initialValue: 150}, dragEnabled: {initialValue: true}, - focusTimout: {initialValue: 0} + focusTimout: {initialValue: 0}, + tooltipFollowsMouse: {initialValue: true} }); From be0d187a60aa8d7701fc6e5b7c66ebaef8bc3180 Mon Sep 17 00:00:00 2001 From: Eric Arnold Date: Tue, 14 Jan 2014 17:10:44 -0800 Subject: [PATCH 2/2] Review changes --- lib/ace/editor.js | 11 ----------- lib/ace/mouse/default_gutter_handler.js | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index a9cbc7f1..2426247d 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -1030,17 +1030,6 @@ var Editor = function(renderer, session) { return this.getOption("highlightGutterLine"); }; - /** - * Determines if the annotation tooltip follows the mouse or is stationary to the annotation. - * @return {Boolean} - **/ - this.setTooltipFollowsMouse = function(tooltipShouldFollowMouse) { - this.setOption("tooltipFollowsMouse", tooltipShouldFollowMouse); - }; - this.getTooltipFollowsMouse = function() { - return this.getOption("tooltipFollowsMouse"); - }; - /** * Determines if the currently selected word should be highlighted. * @param {Boolean} shouldHighlight Set to `true` to highlight the currently selected word diff --git a/lib/ace/mouse/default_gutter_handler.js b/lib/ace/mouse/default_gutter_handler.js index d9e90297..1ce8aaab 100644 --- a/lib/ace/mouse/default_gutter_handler.js +++ b/lib/ace/mouse/default_gutter_handler.js @@ -99,10 +99,10 @@ function GutterHandler(mouseHandler) { if (mouseHandler.$tooltipFollowsMouse) { moveTooltip(mouseEvent); } else { - gutterElement = gutter.$cells[row].element; + var gutterElement = gutter.$cells[row].element; var rect = gutterElement.getBoundingClientRect(); var tooltipLeft = rect.right; - var tooltipTop = rect.top + Math.round(rect.height / 2); + var tooltipTop = rect.bottom; tooltip.style.left = tooltipLeft + "px"; tooltip.style.top = tooltipTop - 5 + "px"; }