Skip to content

Commit

Permalink
Account for position of caret on auto-wrapped text. Closes knadh#1.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Dec 10, 2023
1 parent 93b7721 commit 2bbceb0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/floatype.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions floatype.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ export function floatype(el, options = {}) {

// Update shadow div content up to the cursor position
const cl = "floatype-caret";
shadow.innerHTML = el.value.substring(0, start) + `<span id="${cl}" style="display: inline-block;"></span>` + el.value.substring(start);
shadow.innerHTML = el.value.substring(0, start) + `<span id="${cl}" style="display: inline-block;">${el.value.substring(start)}</span>`;

const m = document.getElementById(cl);
const rect = el.getBoundingClientRect();

return {
x: rect.left + m.offsetLeft - el.scrollLeft,
y: rect.top + m.offsetTop - el.scrollTop + 10
y: rect.top + m.offsetTop - el.scrollTop + (parseInt(getComputedStyle(m).height) + 5)
};
}

Expand Down

0 comments on commit 2bbceb0

Please sign in to comment.