Skip to content

Commit

Permalink
Merge pull request #7887 from surveyjs/string-editor-safari-firefox
Browse files Browse the repository at this point in the history
sinitize contenteditable - safari firefox
  • Loading branch information
OlgaLarina authored Feb 20, 2024
2 parents b8569f8 + 8b56383 commit 0a64072
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export function sanitizeEditableContent(element: any, cleanLineBreaks: boolean =
selection.addRange(range);
let tail = selection.toString();
let innerText = element.innerText;
tail = tail.replace(/\r/g, "");
if (cleanLineBreaks) {
tail = tail.replace(/\n/g, "");
innerText = innerText.replace(/\n/g, "");
Expand All @@ -389,14 +390,14 @@ export function sanitizeEditableContent(element: any, cleanLineBreaks: boolean =
element.innerText = innerText;
range = document.createRange();

range.setStart(element.lastChild, element.lastChild.textContent.length);
range.setEnd(element.lastChild, element.lastChild.textContent.length);
range.setStart(element.firstChild, 0);
range.setEnd(element.firstChild, 0);

selection.removeAllRanges();
selection.addRange(range);

for (let i = 0; i < tail_len; i++) {
(selection as any).modify("move", "backward", "character");
for (let i = 0; i < innerText.length - tail_len; i++) {
(selection as any).modify("move", "forward", "character");
}
}
}
Expand Down

0 comments on commit 0a64072

Please sign in to comment.