Fixed checkCursorTag and checkCursorMenu not calculate doc height properly, fixed jquery-textcomplete support upSideDown
This commit is contained in:
parent
c4c9c4fed6
commit
f8b029b2f4
2 changed files with 35 additions and 25 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -554,9 +554,15 @@ if (typeof jQuery === 'undefined') {
|
|||
if (!this.shown) { return; }
|
||||
if (this.isUp(e)) {
|
||||
e.preventDefault();
|
||||
if(typeof upSideDown != 'undefined' && upSideDown)
|
||||
this._down();
|
||||
else
|
||||
this._up();
|
||||
} else if (this.isDown(e)) {
|
||||
e.preventDefault();
|
||||
if(typeof upSideDown != 'undefined' && upSideDown)
|
||||
this._up();
|
||||
else
|
||||
this._down();
|
||||
} else if (this.isEnter(e)) {
|
||||
e.preventDefault();
|
||||
|
@ -633,7 +639,7 @@ if (typeof jQuery === 'undefined') {
|
|||
},
|
||||
|
||||
_getActiveElement: function () {
|
||||
return this.$el.children('.textcomplete-item:nth(' + this._index + ')');
|
||||
return this.$el.children('.textcomplete-item[data-index=' + this._index + ']');
|
||||
},
|
||||
|
||||
_setScroll: function () {
|
||||
|
@ -661,20 +667,11 @@ if (typeof jQuery === 'undefined') {
|
|||
this.data.push(datum);
|
||||
item.push(datum.strategy.template(datum.value));
|
||||
}
|
||||
if(typeof upSideDown != 'undefined' && upSideDown) {
|
||||
for (i = item.length - 1; i >= 0; i--) {
|
||||
html += '<li class="textcomplete-item" data-index="' + i + '"><a>';
|
||||
html += item[i];
|
||||
html += '</a></li>';
|
||||
}
|
||||
this._index = this.data.length - 1;
|
||||
} else {
|
||||
for (i = 0; i < item.length; i++) {
|
||||
html += '<li class="textcomplete-item" data-index="' + i + '"><a>';
|
||||
html += item[i];
|
||||
html += '</a></li>';
|
||||
}
|
||||
}
|
||||
return html;
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue