This commit is contained in:
faizan ahmed 2025-03-26 05:15:28 +00:00 committed by GitHub
commit 6de8d954f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 4 deletions

View file

@ -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)) {

View file

@ -327,38 +327,60 @@ 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(),
); );
const font = getFontString({ const font = getFontString({
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 = () => {
const normalized = normalizeText(editable.value); const normalized = normalizeText(editable.value);
if (editable.value !== normalized) { if (editable.value !== normalized) {
@ -372,6 +394,7 @@ export const textWysiwyg = ({
onChange(editable.value); onChange(editable.value);
}; };
} }
editable.onkeydown = (event) => { editable.onkeydown = (event) => {
if (!event.shiftKey && actionZoomIn.keyTest(event)) { if (!event.shiftKey && actionZoomIn.keyTest(event)) {