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) {
|
function checkCursorTag(coord, ele) {
|
||||||
|
if (!ele) return;
|
||||||
var curosrtagMargin = 60;
|
var curosrtagMargin = 60;
|
||||||
var viewport = editor.getViewport();
|
var cursor = editor.getCursor();
|
||||||
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 editorWidth = ui.area.codemirror.width();
|
||||||
var editorHeight = ui.area.codemirror.height();
|
var editorHeight = ui.area.codemirror.height();
|
||||||
var width = ele.width();
|
var width = ele.width();
|
||||||
var height = ele.height();
|
var height = ele.height();
|
||||||
|
if (!lineHeightMap)
|
||||||
|
buildMapInner();
|
||||||
var left = coord.left;
|
var left = coord.left;
|
||||||
var top = coord.top;
|
var top = lineHeightMap[cursor.line] * defaultTextHeight; //coord.top;
|
||||||
var offsetLeft = -3;
|
var offsetLeft = -3;
|
||||||
var offsetTop = defaultTextHeight;
|
var offsetTop = defaultTextHeight;
|
||||||
var statusBarHeight = 0;
|
var statusBarHeight = 0;
|
||||||
|
@ -1371,8 +1375,8 @@ function checkCursorTag(coord, ele) {
|
||||||
if (left + width + offsetLeft > editorWidth - curosrtagMargin) {
|
if (left + width + offsetLeft > editorWidth - curosrtagMargin) {
|
||||||
offsetLeft = -(width + 10);
|
offsetLeft = -(width + 10);
|
||||||
}
|
}
|
||||||
offsetTop = -(height);
|
|
||||||
if (top + height + offsetTop > Math.max(editor.doc.height, editorHeight) + curosrtagMargin - statusBarHeight * 2 && top - height > curosrtagMargin) {
|
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';
|
ele[0].style.left = offsetLeft + 'px';
|
||||||
|
@ -1863,10 +1867,11 @@ if ($('.cursor-menu').length <= 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var upSideDown = false;
|
var upSideDown = false;
|
||||||
var menuMargin = 60;
|
|
||||||
|
|
||||||
function checkCursorMenu() {
|
function checkCursorMenu() {
|
||||||
|
var menuMargin = 60;
|
||||||
var dropdown = $('.cursor-menu .dropdown-menu');
|
var dropdown = $('.cursor-menu .dropdown-menu');
|
||||||
|
if (dropdown.length <= 0) return;
|
||||||
var cursor = editor.getCursor();
|
var cursor = editor.getCursor();
|
||||||
var scrollInfo = editor.getScrollInfo();
|
var scrollInfo = editor.getScrollInfo();
|
||||||
if (!dropdown.hasClass('other-cursor'))
|
if (!dropdown.hasClass('other-cursor'))
|
||||||
|
@ -1877,14 +1882,16 @@ function checkCursorMenu() {
|
||||||
line: cursor.line,
|
line: cursor.line,
|
||||||
ch: cursor.ch
|
ch: cursor.ch
|
||||||
}, 'windows');
|
}, 'windows');
|
||||||
var viewport = editor.getViewport();
|
//var viewport = editor.getViewport();
|
||||||
var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
|
//var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
|
||||||
var editorWidth = ui.area.codemirror.width();
|
var editorWidth = ui.area.codemirror.width();
|
||||||
var editorHeight = ui.area.codemirror.height();
|
var editorHeight = ui.area.codemirror.height();
|
||||||
var width = dropdown.width();
|
var width = dropdown.outerWidth();
|
||||||
var height = dropdown.height();
|
var height = dropdown.outerHeight();
|
||||||
|
if (!lineHeightMap)
|
||||||
|
buildMapInner();
|
||||||
var left = coord.left;
|
var left = coord.left;
|
||||||
var top = coord.top;
|
var top = lineHeightMap[cursor.line] * defaultTextHeight; //coord.top;
|
||||||
var offsetLeft = 0;
|
var offsetLeft = 0;
|
||||||
var offsetTop = defaultTextHeight;
|
var offsetTop = defaultTextHeight;
|
||||||
var statusBarHeight = 0;
|
var statusBarHeight = 0;
|
||||||
|
@ -1892,9 +1899,15 @@ function checkCursorMenu() {
|
||||||
statusBarHeight = statusBar.outerHeight();
|
statusBarHeight = statusBar.outerHeight();
|
||||||
if (left + width + offsetLeft > editorWidth - menuMargin)
|
if (left + width + offsetLeft > editorWidth - menuMargin)
|
||||||
offsetLeft = -(left + width - 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) {
|
if (top + height + offsetTop > Math.max(editor.doc.height, editorHeight) + menuMargin - statusBarHeight * 2 && top - height > menuMargin) {
|
||||||
|
offsetTop = -(height + 4);
|
||||||
upSideDown = true;
|
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 {
|
} else {
|
||||||
upSideDown = false;
|
upSideDown = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -554,9 +554,15 @@ if (typeof jQuery === 'undefined') {
|
||||||
if (!this.shown) { return; }
|
if (!this.shown) { return; }
|
||||||
if (this.isUp(e)) {
|
if (this.isUp(e)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if(typeof upSideDown != 'undefined' && upSideDown)
|
||||||
|
this._down();
|
||||||
|
else
|
||||||
this._up();
|
this._up();
|
||||||
} else if (this.isDown(e)) {
|
} else if (this.isDown(e)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if(typeof upSideDown != 'undefined' && upSideDown)
|
||||||
|
this._up();
|
||||||
|
else
|
||||||
this._down();
|
this._down();
|
||||||
} else if (this.isEnter(e)) {
|
} else if (this.isEnter(e)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -633,7 +639,7 @@ if (typeof jQuery === 'undefined') {
|
||||||
},
|
},
|
||||||
|
|
||||||
_getActiveElement: function () {
|
_getActiveElement: function () {
|
||||||
return this.$el.children('.textcomplete-item:nth(' + this._index + ')');
|
return this.$el.children('.textcomplete-item[data-index=' + this._index + ']');
|
||||||
},
|
},
|
||||||
|
|
||||||
_setScroll: function () {
|
_setScroll: function () {
|
||||||
|
@ -661,20 +667,11 @@ if (typeof jQuery === 'undefined') {
|
||||||
this.data.push(datum);
|
this.data.push(datum);
|
||||||
item.push(datum.strategy.template(datum.value));
|
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++) {
|
for (i = 0; i < item.length; i++) {
|
||||||
html += '<li class="textcomplete-item" data-index="' + i + '"><a>';
|
html += '<li class="textcomplete-item" data-index="' + i + '"><a>';
|
||||||
html += item[i];
|
html += item[i];
|
||||||
html += '</a></li>';
|
html += '</a></li>';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return html;
|
return html;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue