mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: introduce baseline to fix the layout shift when switching to text editor (#6397)
* fix: introduce baseline to fix the layout shift when switching to text editor * uncomment * change offset to 8pixels * [debug] * introduce DOM baseline in canvas rendering instead * introduce baseline in element making it backward compat * fix * lint * fix * update baseline when resizing text element * fix safari backward compat * fix for safari * lint * reduce safari LS * floor line height and height when dom height increases than canvas height * Revert "floor line height and height when dom height increases than canvas height" This reverts commit8de6516823
. * cleanup * use DOM height only for safari to fix LS * Revert "use DOM height only for safari to fix LS" This reverts commitd75889238d
. * fix lint and test * fix * calculate line height by rounding off instead of DOM * cleanup --------- Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
0b8fc4f4b6
commit
ec215362a1
9 changed files with 161 additions and 50 deletions
|
@ -145,6 +145,7 @@ export const newTextElement = (
|
|||
const text = normalizeText(opts.text);
|
||||
const metrics = measureText(text, getFontString(opts), lineHeight);
|
||||
const offsets = getTextElementPositionOffsets(opts, metrics);
|
||||
|
||||
const textElement = newElementWith(
|
||||
{
|
||||
..._newElementBase<ExcalidrawTextElement>("text", opts),
|
||||
|
@ -157,6 +158,7 @@ export const newTextElement = (
|
|||
y: opts.y - offsets.y,
|
||||
width: metrics.width,
|
||||
height: metrics.height,
|
||||
baseline: metrics.baseline,
|
||||
containerId: opts.containerId || null,
|
||||
originalText: text,
|
||||
lineHeight,
|
||||
|
@ -174,14 +176,15 @@ const getAdjustedDimensions = (
|
|||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
baseline: number;
|
||||
} => {
|
||||
const container = getContainerElement(element);
|
||||
|
||||
const { width: nextWidth, height: nextHeight } = measureText(
|
||||
nextText,
|
||||
getFontString(element),
|
||||
element.lineHeight,
|
||||
);
|
||||
const {
|
||||
width: nextWidth,
|
||||
height: nextHeight,
|
||||
baseline: nextBaseline,
|
||||
} = measureText(nextText, getFontString(element), element.lineHeight);
|
||||
const { textAlign, verticalAlign } = element;
|
||||
let x: number;
|
||||
let y: number;
|
||||
|
@ -256,6 +259,7 @@ const getAdjustedDimensions = (
|
|||
return {
|
||||
width: nextWidth,
|
||||
height: nextHeight,
|
||||
baseline: nextBaseline,
|
||||
x: Number.isFinite(x) ? x : element.x,
|
||||
y: Number.isFinite(y) ? y : element.y,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue