Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 3a129b2

Browse files
committed
fix popover positioning
1 parent 70053ae commit 3a129b2

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/editor/Editor.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,11 +1528,12 @@ define(function (require, exports, module) {
15281528
*/
15291529
Editor.prototype.displayErrorMessageAtCursor = function (errorMsg) {
15301530
var arrowBelow, cursorPos, cursorCoord, popoverRect,
1531-
top, left, clip, arrowLeft,
1531+
top, left, clip, arrowCenter, arrowLeft,
15321532
self = this,
15331533
$editorHolder = $("#editor-holder"),
15341534
POPOVER_MARGIN = 10,
1535-
POPOVER_ARROW_HALF_WIDTH = 10;
1535+
POPOVER_ARROW_HALF_WIDTH = 10,
1536+
POPOVER_ARROW_HALF_BASE = POPOVER_ARROW_HALF_WIDTH + 3; // 3 is border radius
15361537

15371538
function _removeListeners() {
15381539
$(self).off(".msgbox");
@@ -1611,8 +1612,14 @@ define(function (require, exports, module) {
16111612
// Popover text and arrow are positioned individually
16121613
this._$messagePopover.css({"top": top, "left": left});
16131614

1614-
// Position popover arrow exactly centered over/under cursor
1615-
arrowLeft = cursorCoord.left - left - POPOVER_ARROW_HALF_WIDTH;
1615+
// Position popover arrow centered over/under cursor...
1616+
arrowCenter = cursorCoord.left - left;
1617+
1618+
// ... but don't let it slide off text box
1619+
arrowCenter = Math.min(popoverRect.width - POPOVER_ARROW_HALF_BASE,
1620+
Math.max(arrowCenter, POPOVER_ARROW_HALF_BASE));
1621+
1622+
arrowLeft = arrowCenter - POPOVER_ARROW_HALF_WIDTH;
16161623
if (arrowBelow) {
16171624
this._$messagePopover.find(".arrowBelow").css({"margin-left": arrowLeft});
16181625
} else {

test/spec/InlineEditorProviders-test-files/test1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
<div id="anotherDiv{{6}}"></div>
1616
<div{{8}} {{7}}class="foo"></{{9}}div>
1717
<div class="{{10}}embeddedClass" title="abc{{12}}xyz"></div>
18-
<div class="embeddedClass" title="abc xyz">This is a long line of text so that cursor position at end of line will have to be scrolled into view</div>{{13}}
18+
<div class="embeddedClass" title="abc xyz">This is a long line of text so that cursor position at end of line will have to be scrolled into view. This is a long line of text so that cursor position at end of line will have to be scrolled into view.</div>{{13}}
1919
</body>
2020
</html>

test/spec/InlineEditorProviders-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
26-
/*global define, describe, it, xit, expect, beforeEach, afterEach, waits, waitsFor, waitsForDone, waitsForFail, runs, $, brackets, beforeFirst, afterLast */
26+
/*global define, describe, it, expect, beforeEach, afterEach, waits, waitsFor, waitsForDone, waitsForFail, runs, $, brackets, beforeFirst, afterLast */
2727

2828
define(function (require, exports, module) {
2929
'use strict';
@@ -580,7 +580,7 @@ define(function (require, exports, module) {
580580
});
581581
});
582582

583-
xit("should scroll cursor into view and position message popover inside right edge of window", function () {
583+
it("should scroll cursor into view and position message popover inside right edge of window", function () {
584584
var $popover, scrollPos, editor,
585585
openFile = "test1.html";
586586

0 commit comments

Comments
 (0)