|
231 | 231 | var content = ts.options.completionTip ? ts.options.completionTip(cur.data) : cur.data.doc; |
232 | 232 | if (content) { |
233 | 233 | tooltip = makeTooltip(node.parentNode.getBoundingClientRect().right + window.pageXOffset, |
234 | | - node.getBoundingClientRect().top + window.pageYOffset, content, cm); |
235 | | - tooltip.className += " " + cls + "hint-doc"; |
| 234 | + node.getBoundingClientRect().top + window.pageYOffset, content, cm, cls + "hint-doc"); |
236 | 235 | } |
237 | 236 | }); |
238 | 237 | c(obj); |
|
637 | 636 | } |
638 | 637 | } |
639 | 638 |
|
640 | | - function makeTooltip(x, y, content, cm) { |
641 | | - var node = elt("div", cls + "tooltip", content); |
| 639 | + function makeTooltip(x, y, content, cm, className) { |
| 640 | + var node = elt("div", cls + "tooltip" + " " + (className || ""), content); |
642 | 641 | node.style.left = x + "px"; |
643 | 642 | node.style.top = y + "px"; |
644 | 643 | var container = ((cm.options || {}).hintOptions || {}).container || document.body; |
645 | 644 | container.appendChild(node); |
| 645 | + |
| 646 | + var pos = cm.cursorCoords(); |
| 647 | + var winW = window.innerWidth; |
| 648 | + var winH = window.innerHeight; |
| 649 | + var box = node.getBoundingClientRect(); |
| 650 | + var hints = document.querySelector(".CodeMirror-hints"); |
| 651 | + var overlapY = box.bottom - winH; |
| 652 | + var overlapX = box.right - winW; |
| 653 | + |
| 654 | + if (hints && overlapX > 0) { |
| 655 | + node.style.left = 0; |
| 656 | + var box = node.getBoundingClientRect(); |
| 657 | + node.style.left = (x = x - hints.offsetWidth - box.width) + "px"; |
| 658 | + overlapX = box.right - winW; |
| 659 | + } |
| 660 | + if (overlapY > 0) { |
| 661 | + var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top); |
| 662 | + if (curTop - height > 0) { // Fits above cursor |
| 663 | + node.style.top = (pos.top - height) + "px"; |
| 664 | + } else if (height > winH) { |
| 665 | + node.style.height = (winH - 5) + "px"; |
| 666 | + node.style.top = (pos.bottom - box.top) + "px"; |
| 667 | + } |
| 668 | + } |
| 669 | + if (overlapX > 0) { |
| 670 | + if (box.right - box.left > winW) { |
| 671 | + node.style.width = (winW - 5) + "px"; |
| 672 | + overlapX -= (box.right - box.left) - winW; |
| 673 | + } |
| 674 | + node.style.left = (x - overlapX) + "px"; |
| 675 | + } |
| 676 | + |
646 | 677 | return node; |
647 | 678 | } |
648 | 679 |
|
|
0 commit comments