mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Merge e4b61fde29
into ab89d4c16f
This commit is contained in:
commit
6de8d954f1
2 changed files with 44 additions and 4 deletions
|
@ -389,6 +389,23 @@ export const parseClipboard = async (
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const systemClipboardData = JSON.parse(parsedEventData.value);
|
const systemClipboardData = JSON.parse(parsedEventData.value);
|
||||||
|
try{
|
||||||
|
// If object is being pasted in textbox, insted of returning whole object return only text
|
||||||
|
const isTextBox = (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement);
|
||||||
|
if(isTextBox){
|
||||||
|
var onlyTexts = ""
|
||||||
|
for(const element of systemClipboardData.elements){
|
||||||
|
if(element.type == 'text'){
|
||||||
|
onlyTexts += " " + element.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
text : onlyTexts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (error: any) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
const programmaticAPI =
|
const programmaticAPI =
|
||||||
systemClipboardData.type === EXPORT_DATA_TYPES.excalidrawClipboardWithAPI;
|
systemClipboardData.type === EXPORT_DATA_TYPES.excalidrawClipboardWithAPI;
|
||||||
if (clipboardContainsElements(systemClipboardData)) {
|
if (clipboardContainsElements(systemClipboardData)) {
|
||||||
|
|
|
@ -327,14 +327,32 @@ export const textWysiwyg = ({
|
||||||
|
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
editable.onpaste = async (event) => {
|
editable.onpaste = async (event) => {
|
||||||
|
event.preventDefault(); // Prevent the default paste action
|
||||||
|
|
||||||
const clipboardData = await parseClipboard(event, true);
|
const clipboardData = await parseClipboard(event, true);
|
||||||
if (!clipboardData.text) {
|
if (!clipboardData.text) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = normalizeText(clipboardData.text);
|
|
||||||
|
const data = normalizeText(clipboardData.text)
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle text selection and replace the selected text with the pasted data
|
||||||
|
const selectionStart = editable.selectionStart;
|
||||||
|
const selectionEnd = editable.selectionEnd;
|
||||||
|
|
||||||
|
const beforeText = editable.value.substring(0, selectionStart);
|
||||||
|
const afterText = editable.value.substring(selectionEnd);
|
||||||
|
|
||||||
|
editable.value = beforeText + data + afterText;
|
||||||
|
|
||||||
|
// Move the cursor to the end of the pasted text
|
||||||
|
const newCursorPos = selectionStart + data.length;
|
||||||
|
editable.selectionStart = newCursorPos;
|
||||||
|
editable.selectionEnd = newCursorPos;
|
||||||
|
|
||||||
const container = getContainerElement(
|
const container = getContainerElement(
|
||||||
element,
|
element,
|
||||||
app.scene.getNonDeletedElementsMap(),
|
app.scene.getNonDeletedElementsMap(),
|
||||||
|
@ -344,19 +362,23 @@ export const textWysiwyg = ({
|
||||||
fontSize: app.state.currentItemFontSize,
|
fontSize: app.state.currentItemFontSize,
|
||||||
fontFamily: app.state.currentItemFontFamily,
|
fontFamily: app.state.currentItemFontFamily,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (container) {
|
if (container) {
|
||||||
const boundTextElement = getBoundTextElement(
|
const boundTextElement = getBoundTextElement(
|
||||||
container,
|
container,
|
||||||
app.scene.getNonDeletedElementsMap(),
|
app.scene.getNonDeletedElementsMap(),
|
||||||
);
|
);
|
||||||
const wrappedText = wrapText(
|
const wrappedText = wrapText(
|
||||||
`${editable.value}${data}`,
|
editable.value,
|
||||||
font,
|
font,
|
||||||
getBoundTextMaxWidth(container, boundTextElement),
|
getBoundTextMaxWidth(container, boundTextElement),
|
||||||
);
|
);
|
||||||
const width = getTextWidth(wrappedText, font);
|
const width = getTextWidth(wrappedText, font);
|
||||||
editable.style.width = `${width}px`;
|
editable.style.width = `${width}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trigger the onChange callback with the updated value
|
||||||
|
onChange(editable.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
editable.oninput = () => {
|
editable.oninput = () => {
|
||||||
|
@ -373,6 +395,7 @@ export const textWysiwyg = ({
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
editable.onkeydown = (event) => {
|
editable.onkeydown = (event) => {
|
||||||
if (!event.shiftKey && actionZoomIn.keyTest(event)) {
|
if (!event.shiftKey && actionZoomIn.keyTest(event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue