mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: merge existing text with new when pasted (#5856)
* Fix #5855. * fix test * tweak * Add specs * Add more snaps Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
This commit is contained in:
parent
dc97dc30bf
commit
335aff8838
2 changed files with 119 additions and 13 deletions
|
@ -284,20 +284,30 @@ export const textWysiwyg = ({
|
|||
return;
|
||||
}
|
||||
const data = normalizeText(clipboardData.text);
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
const text = editable.value;
|
||||
const start = Math.min(editable.selectionStart, editable.selectionEnd);
|
||||
const end = Math.max(editable.selectionStart, editable.selectionEnd);
|
||||
const newText = `${text.substring(0, start)}${data}${text.substring(
|
||||
end,
|
||||
)}`;
|
||||
|
||||
const container = getContainerElement(element);
|
||||
|
||||
const font = getFontString({
|
||||
fontSize: app.state.currentItemFontSize,
|
||||
fontFamily: app.state.currentItemFontFamily,
|
||||
});
|
||||
const wrappedText = container
|
||||
? wrapText(data, font, getMaxContainerWidth(container))
|
||||
: data;
|
||||
|
||||
const wrappedText = container
|
||||
? wrapText(newText, font, getMaxContainerWidth(container))
|
||||
: newText;
|
||||
const dimensions = measureText(wrappedText, font);
|
||||
editable.style.height = `${dimensions.height}px`;
|
||||
|
||||
onChange(wrappedText);
|
||||
onChange(newText);
|
||||
};
|
||||
editable.oninput = () => {
|
||||
const updatedTextElement = Scene.getScene(element)?.getElement(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue