Permalink
Browse files

[show-hint addon] Don't cover cursor when taking up full screen height

Closes #2213
  • Loading branch information...
1 parent 5a0ebbe commit 53df1102acc3e5047fdba5c0df86b258aad55e86 @marijnh marijnh committed Feb 3, 2014
Showing with 18 additions and 13 deletions.
  1. +18 −13 addon/hint/show-hint.js
View
@@ -193,26 +193,31 @@
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
(options.container || document.body).appendChild(hints);
- var box = hints.getBoundingClientRect();
- var overlapX = box.right - winW, overlapY = box.bottom - winH;
+ var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
+ if (overlapY > 0) {
+ var height = box.bottom - box.top, curTop = box.top - (pos.bottom - pos.top);
+ if (curTop - height > 0) { // Fits above cursor
+ hints.style.top = (top = curTop - height) + "px";
+ below = false;
+ } else if (height > winH) {
+ hints.style.height = (winH - 5) + "px";
+ hints.style.top = (top = pos.bottom - box.top) + "px";
+ var cursor = cm.getCursor();
+ if (data.from.ch != cursor.ch) {
+ pos = cm.cursorCoords(cursor);
+ hints.style.left = (left = pos.left) + "px";
+ box = hints.getBoundingClientRect();
+ }
+ }
+ }
+ var overlapX = box.left - winW;
if (overlapX > 0) {
if (box.right - box.left > winW) {
hints.style.width = (winW - 5) + "px";
overlapX -= (box.right - box.left) - winW;
}
hints.style.left = (left = pos.left - overlapX) + "px";
}
- if (overlapY > 0) {
- var height = box.bottom - box.top;
- if (box.top - (pos.bottom - pos.top) - height > 0) {
- overlapY = height + (pos.bottom - pos.top);
- below = false;
- } else if (height > winH) {
- hints.style.height = (winH - 5) + "px";
- overlapY -= height - winH;
- }
- hints.style.top = (top = pos.bottom - overlapY) + "px";
- }
cm.addKeyMap(this.keyMap = buildKeyMap(options, {
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },

0 comments on commit 53df110

Please sign in to comment.