Fix getCaretPosition in text complete might get undefined position error
This commit is contained in:
parent
12b7646f24
commit
f3d4b55856
1 changed files with 25 additions and 10 deletions
|
@ -863,9 +863,7 @@ if (typeof jQuery === 'undefined') {
|
|||
//
|
||||
// FIXME: Calculate the left top corner of `this.option.appendTo` element.
|
||||
getCaretPosition: function () {
|
||||
//var position = this._getCaretRelativePosition();
|
||||
//var offset = this.$el.offset();
|
||||
//var offset = $('.CodeMirror-cursor').offset();
|
||||
if ($('.CodeMirror-cursor').length > 0) {
|
||||
var position = $('.CodeMirror-cursor').position();
|
||||
var menu = $('.cursor-menu .dropdown-menu');
|
||||
var offsetLeft = parseFloat(menu.attr('data-offset-left'));
|
||||
|
@ -873,6 +871,23 @@ if (typeof jQuery === 'undefined') {
|
|||
position.left += offsetLeft;
|
||||
position.top += offsetTop;
|
||||
return position;
|
||||
} else {
|
||||
var position = this._getCaretRelativePosition();
|
||||
var offset = this.$el.offset();
|
||||
|
||||
// Calculate the left top corner of `this.option.appendTo` element.
|
||||
var $parent = this.option.appendTo;
|
||||
if ($parent) {
|
||||
if (!($parent instanceof $)) { $parent = $($parent); }
|
||||
var parentOffset = $parent.offsetParent().offset();
|
||||
offset.top -= parentOffset.top;
|
||||
offset.left -= parentOffset.left;
|
||||
}
|
||||
|
||||
position.top += offset.top;
|
||||
position.left += offset.left;
|
||||
return position;
|
||||
}
|
||||
},
|
||||
|
||||
// Focus on the element.
|
||||
|
|
Loading…
Reference in a new issue