Skip to content

Commit 4bbfdbe

Browse files
committed
Update codeit-autocomplete.js
1 parent 82b7ae1 commit 4bbfdbe

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/plugins/codeit-autocomplete.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,12 +698,20 @@ acp.utils.renderTopHitHTML = (topHit, query) => {
698698

699699

700700
// get position of caret from start of query
701-
acp.utils.getCaretPos = (originRange, query) => {
701+
acp.utils.getCaretPos = (cursor, query) => {
702702

703-
let range = originRange.cloneRange();
703+
let range = cursor.cloneRange();
704704

705-
const container = range.startContainer;
706-
const offset = range.startOffset - query.length;
705+
let container = range.startContainer;
706+
let offset = range.startOffset - query.length;
707+
708+
// if offset is negative, go back a node
709+
if (offset < 0) {
710+
711+
container = container.previousSibling;
712+
offset = offset + container.textContent.length;
713+
714+
}
707715

708716
range.setStart(container, offset);
709717

0 commit comments

Comments
 (0)