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:
DanielJGeiger 2022-11-09 12:09:53 -06:00 committed by GitHub
parent dc97dc30bf
commit 335aff8838
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 119 additions and 13 deletions

View file

@ -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(