Skip to content

Commit f8b029b

Browse files
committed
Fixed checkCursorTag and checkCursorMenu not calculate doc height properly, fixed jquery-textcomplete support upSideDown
1 parent c4c9c4f commit f8b029b

2 files changed

Lines changed: 35 additions & 25 deletions

File tree

public/js/index.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,15 +1353,19 @@ function emitUserStatus(force) {
13531353
}
13541354

13551355
function checkCursorTag(coord, ele) {
1356+
if (!ele) return;
13561357
var curosrtagMargin = 60;
1357-
var viewport = editor.getViewport();
1358-
var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
1358+
var cursor = editor.getCursor();
1359+
//var viewport = editor.getViewport();
1360+
//var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
13591361
var editorWidth = ui.area.codemirror.width();
13601362
var editorHeight = ui.area.codemirror.height();
13611363
var width = ele.width();
13621364
var height = ele.height();
1365+
if (!lineHeightMap)
1366+
buildMapInner();
13631367
var left = coord.left;
1364-
var top = coord.top;
1368+
var top = lineHeightMap[cursor.line] * defaultTextHeight; //coord.top;
13651369
var offsetLeft = -3;
13661370
var offsetTop = defaultTextHeight;
13671371
var statusBarHeight = 0;
@@ -1371,8 +1375,8 @@ function checkCursorTag(coord, ele) {
13711375
if (left + width + offsetLeft > editorWidth - curosrtagMargin) {
13721376
offsetLeft = -(width + 10);
13731377
}
1374-
offsetTop = -(height);
13751378
if (top + height + offsetTop > Math.max(editor.doc.height, editorHeight) + curosrtagMargin - statusBarHeight * 2 && top - height > curosrtagMargin) {
1379+
offsetTop = -(height + 4);
13761380
}
13771381
}
13781382
ele[0].style.left = offsetLeft + 'px';
@@ -1863,10 +1867,11 @@ if ($('.cursor-menu').length <= 0) {
18631867
}
18641868

18651869
var upSideDown = false;
1866-
var menuMargin = 60;
18671870

18681871
function checkCursorMenu() {
1872+
var menuMargin = 60;
18691873
var dropdown = $('.cursor-menu .dropdown-menu');
1874+
if (dropdown.length <= 0) return;
18701875
var cursor = editor.getCursor();
18711876
var scrollInfo = editor.getScrollInfo();
18721877
if (!dropdown.hasClass('other-cursor'))
@@ -1877,24 +1882,32 @@ function checkCursorMenu() {
18771882
line: cursor.line,
18781883
ch: cursor.ch
18791884
}, 'windows');
1880-
var viewport = editor.getViewport();
1881-
var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
1885+
//var viewport = editor.getViewport();
1886+
//var viewportHeight = (viewport.to - viewport.from) * editor.defaultTextHeight();
18821887
var editorWidth = ui.area.codemirror.width();
18831888
var editorHeight = ui.area.codemirror.height();
1884-
var width = dropdown.width();
1885-
var height = dropdown.height();
1889+
var width = dropdown.outerWidth();
1890+
var height = dropdown.outerHeight();
1891+
if (!lineHeightMap)
1892+
buildMapInner();
18861893
var left = coord.left;
1887-
var top = coord.top;
1894+
var top = lineHeightMap[cursor.line] * defaultTextHeight; //coord.top;
18881895
var offsetLeft = 0;
18891896
var offsetTop = defaultTextHeight;
18901897
var statusBarHeight = 0;
18911898
if (statusBar)
18921899
statusBarHeight = statusBar.outerHeight();
18931900
if (left + width + offsetLeft > editorWidth - menuMargin)
18941901
offsetLeft = -(left + width - editorWidth + menuMargin);
1895-
offsetTop = -(height + defaultTextHeight);
18961902
if (top + height + offsetTop > Math.max(editor.doc.height, editorHeight) + menuMargin - statusBarHeight * 2 && top - height > menuMargin) {
1903+
offsetTop = -(height + 4);
18971904
upSideDown = true;
1905+
var items = dropdown.find('.textcomplete-item');
1906+
items.sort(function (a, b) {
1907+
return $(b).attr('data-index') - $(a).attr('data-index');
1908+
});
1909+
dropdown.html(items);
1910+
dropdown.scrollTop(dropdown[0].scrollHeight);
18981911
} else {
18991912
upSideDown = false;
19001913
}

public/vendor/jquery-textcomplete/jquery.textcomplete.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,16 @@ if (typeof jQuery === 'undefined') {
554554
if (!this.shown) { return; }
555555
if (this.isUp(e)) {
556556
e.preventDefault();
557-
this._up();
557+
if(typeof upSideDown != 'undefined' && upSideDown)
558+
this._down();
559+
else
560+
this._up();
558561
} else if (this.isDown(e)) {
559562
e.preventDefault();
560-
this._down();
563+
if(typeof upSideDown != 'undefined' && upSideDown)
564+
this._up();
565+
else
566+
this._down();
561567
} else if (this.isEnter(e)) {
562568
e.preventDefault();
563569
this._enter();
@@ -633,7 +639,7 @@ if (typeof jQuery === 'undefined') {
633639
},
634640

635641
_getActiveElement: function () {
636-
return this.$el.children('.textcomplete-item:nth(' + this._index + ')');
642+
return this.$el.children('.textcomplete-item[data-index=' + this._index + ']');
637643
},
638644

639645
_setScroll: function () {
@@ -661,20 +667,11 @@ if (typeof jQuery === 'undefined') {
661667
this.data.push(datum);
662668
item.push(datum.strategy.template(datum.value));
663669
}
664-
if(typeof upSideDown != 'undefined' && upSideDown) {
665-
for (i = item.length - 1; i >= 0; i--) {
666-
html += '<li class="textcomplete-item" data-index="' + i + '"><a>';
667-
html += item[i];
668-
html += '</a></li>';
669-
}
670-
this._index = this.data.length - 1;
671-
} else {
672-
for (i = 0; i < item.length; i++) {
670+
for (i = 0; i < item.length; i++) {
673671
html += '<li class="textcomplete-item" data-index="' + i + '"><a>';
674672
html += item[i];
675673
html += '</a></li>';
676-
}
677-
}
674+
}
678675
return html;
679676
},
680677

0 commit comments

Comments
 (0)