mirror of
https://github.com/penpot/penpot.git
synced 2025-05-31 20:36:21 +02:00
🐛 Fix problem with Safari and text resize
This commit is contained in:
parent
b5e696c6b4
commit
e22ef536ed
1 changed files with 14 additions and 3 deletions
|
@ -18,7 +18,7 @@ goog.scope(function () {
|
||||||
const range = document.createRange();
|
const range = document.createRange();
|
||||||
range.setStart(node, start);
|
range.setStart(node, start);
|
||||||
range.setEnd(node, end);
|
range.setEnd(node, end);
|
||||||
return range.getClientRects();
|
return [...range.getClientRects()].filter((r) => r.width > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.parse_text_nodes = function(parent, textNode) {
|
self.parse_text_nodes = function(parent, textNode) {
|
||||||
|
@ -31,10 +31,20 @@ goog.scope(function () {
|
||||||
let result = [];
|
let result = [];
|
||||||
let prevRect = null;
|
let prevRect = null;
|
||||||
|
|
||||||
|
// This variable is to make sure there are not infinite loops
|
||||||
|
// when we don't advance `to` we store true and then force to
|
||||||
|
// advance `to` on the next iteration if the condition is true again
|
||||||
|
let safeguard = false;
|
||||||
|
|
||||||
while (to < textSize) {
|
while (to < textSize) {
|
||||||
const rects = getRangeRects(textNode, from, to + 1);
|
const rects = getRangeRects(textNode, from, to + 1);
|
||||||
|
|
||||||
if (rects.length > 1) {
|
if (rects.length > 1 && safeguard) {
|
||||||
|
from++;
|
||||||
|
to++;
|
||||||
|
safeguard = false;
|
||||||
|
|
||||||
|
} else if (rects.length > 1) {
|
||||||
const position = prevRect;
|
const position = prevRect;
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
|
@ -45,11 +55,12 @@ goog.scope(function () {
|
||||||
|
|
||||||
from = to;
|
from = to;
|
||||||
current = "";
|
current = "";
|
||||||
|
safeguard = true;
|
||||||
} else {
|
} else {
|
||||||
prevRect = rects[0];
|
prevRect = rects[0];
|
||||||
current += content[to];
|
current += content[to];
|
||||||
to = to + 1;
|
to = to + 1;
|
||||||
|
safeguard = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue