Fix getCaretPosition in text complete might get undefined position error

This commit is contained in:
Wu Cheng-Han 2016-10-12 17:50:01 +08:00
parent 12b7646f24
commit f3d4b55856

View file

@ -863,16 +863,31 @@ if (typeof jQuery === 'undefined') {
// //
// FIXME: Calculate the left top corner of `this.option.appendTo` element. // FIXME: Calculate the left top corner of `this.option.appendTo` element.
getCaretPosition: function () { getCaretPosition: function () {
//var position = this._getCaretRelativePosition(); if ($('.CodeMirror-cursor').length > 0) {
//var offset = this.$el.offset(); var position = $('.CodeMirror-cursor').position();
//var offset = $('.CodeMirror-cursor').offset(); var menu = $('.cursor-menu .dropdown-menu');
var position = $('.CodeMirror-cursor').position(); var offsetLeft = parseFloat(menu.attr('data-offset-left'));
var menu = $('.cursor-menu .dropdown-menu'); var offsetTop = parseFloat(menu.attr('data-offset-top'));
var offsetLeft = parseFloat(menu.attr('data-offset-left')); position.left += offsetLeft;
var offsetTop = parseFloat(menu.attr('data-offset-top')); position.top += offsetTop;
position.left += offsetLeft; return position;
position.top += offsetTop; } else {
return position; 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. // Focus on the element.