summaryrefslogtreecommitdiff
path: root/public/js/index.js
diff options
context:
space:
mode:
authorWu Cheng-Han2015-09-25 13:39:08 +0800
committerWu Cheng-Han2015-09-25 13:39:08 +0800
commitf8b029b2f4e9801aa20b80c77b452537ff463de5 (patch)
tree8fa5fe28cde5ac2914d82eec330d455e80f890b7 /public/js/index.js
parentc4c9c4fed63249d21c1a06becc1257136ceafa1a (diff)
Fixed checkCursorTag and checkCursorMenu not calculate doc height properly, fixed jquery-textcomplete support upSideDown
Diffstat (limited to 'public/js/index.js')
-rw-r--r--public/js/index.js35
1 files changed, 24 insertions, 11 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 75634cf1..ae3edb28 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1353,15 +1353,19 @@ function emitUserStatus(force) {
}
function checkCursorTag(coord, ele) {
+ if (!ele) return;
var curosrtagMargin = 60;
- var viewport = editor.getViewport();
- var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
+ var cursor = editor.getCursor();
+ //var viewport = editor.getViewport();
+ //var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
var editorWidth = ui.area.codemirror.width();
var editorHeight = ui.area.codemirror.height();
var width = ele.width();
var height = ele.height();
+ if (!lineHeightMap)
+ buildMapInner();
var left = coord.left;
- var top = coord.top;
+ var top = lineHeightMap[cursor.line] * defaultTextHeight; //coord.top;
var offsetLeft = -3;
var offsetTop = defaultTextHeight;
var statusBarHeight = 0;
@@ -1371,8 +1375,8 @@ function checkCursorTag(coord, ele) {
if (left + width + offsetLeft > editorWidth - curosrtagMargin) {
offsetLeft = -(width + 10);
}
- offsetTop = -(height);
if (top + height + offsetTop > Math.max(editor.doc.height, editorHeight) + curosrtagMargin - statusBarHeight * 2 && top - height > curosrtagMargin) {
+ offsetTop = -(height + 4);
}
}
ele[0].style.left = offsetLeft + 'px';
@@ -1863,10 +1867,11 @@ if ($('.cursor-menu').length <= 0) {
}
var upSideDown = false;
-var menuMargin = 60;
function checkCursorMenu() {
+ var menuMargin = 60;
var dropdown = $('.cursor-menu .dropdown-menu');
+ if (dropdown.length <= 0) return;
var cursor = editor.getCursor();
var scrollInfo = editor.getScrollInfo();
if (!dropdown.hasClass('other-cursor'))
@@ -1877,14 +1882,16 @@ function checkCursorMenu() {
line: cursor.line,
ch: cursor.ch
}, 'windows');
- var viewport = editor.getViewport();
- var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
+ //var viewport = editor.getViewport();
+ //var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
var editorWidth = ui.area.codemirror.width();
var editorHeight = ui.area.codemirror.height();
- var width = dropdown.width();
- var height = dropdown.height();
+ var width = dropdown.outerWidth();
+ var height = dropdown.outerHeight();
+ if (!lineHeightMap)
+ buildMapInner();
var left = coord.left;
- var top = coord.top;
+ var top = lineHeightMap[cursor.line] * defaultTextHeight; //coord.top;
var offsetLeft = 0;
var offsetTop = defaultTextHeight;
var statusBarHeight = 0;
@@ -1892,9 +1899,15 @@ function checkCursorMenu() {
statusBarHeight = statusBar.outerHeight();
if (left + width + offsetLeft > editorWidth - menuMargin)
offsetLeft = -(left + width - editorWidth + menuMargin);
- offsetTop = -(height + defaultTextHeight);
if (top + height + offsetTop > Math.max(editor.doc.height, editorHeight) + menuMargin - statusBarHeight * 2 && top - height > menuMargin) {
+ offsetTop = -(height + 4);
upSideDown = true;
+ var items = dropdown.find('.textcomplete-item');
+ items.sort(function (a, b) {
+ return $(b).attr('data-index') - $(a).attr('data-index');
+ });
+ dropdown.html(items);
+ dropdown.scrollTop(dropdown[0].scrollHeight);
} else {
upSideDown = false;
}