Files
excalidraw/packages
David Luzar eaa7fa32a6 feat(editor): paste multiline text as a single element, with a toast to split it into lines (#12712)
* fix(editor): stack text pasted as separate lines without overlap, as the text is aligned

Each line was centered on a running y advanced by the previous line's
height, so a line wrapping to more rows than the one above overlapped
it. Lines now stack top to bottom, half a line height apart (blank lines
no longer add room), and take the current text align: the block is
centered at the pointer and its lines aligned in it.

* fix(editor): don't restart the toast's timer on each render

Its onClose is a new function on each LayerUI render, and the timer
depended on it: every render cleared the timer and started a full-length
one, so a toast stayed for as long as the UI kept re-rendering. The
timer now restarts only when the toast shows something else.

* feat(editor): paste multiline text as a single element, splitting it into lines from a toast

Ctrl/Cmd+V of a text with more lines pasted an element per line. It's
one text element now, and a toast offers to split it: each non-blank
line an element of its own, in place of the pasted one (wrapped and
aligned as in it, half a line height apart), as one step to undo.

The toast takes an optional action for that: a link-like button after
its message.

* fix(editor): give a toast shown again its full duration

Since the timer no longer restarts on a render, the same plain toast
shown again within its duration got only what was left of the first
one's. The toast takes a timerKey (LayerUI passes the toast object), so
that another toast restarts the timer, and a re-render still doesn't.

* fix(editor): split a pasted text into lines as it's laid out, in its place

Review fixes for splitting a pasted text from the toast:

- the lines keep their indentation and the rows they were wrapped to
  (wrapping a line anew at the text's measured width could break a long
  word elsewhere)
- a line moved out of the frame by the gaps is taken out of it
- the lines take the text's place in the layer order, and arrows bound
  to the text are let go of
- the focus is back in the editor after the toast's button is gone, so
  that the next paste isn't ignored
- a later paste retires the offer to split the text pasted before
2026-11-24 19:24:56 +01:00
..