Muhammad Sufyan Arshad 1 day ago committed by GitHub
parent
commit
a26930da8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      excalidraw-app/index.tsx
  2. 21
      packages/excalidraw/components/App.tsx

20
excalidraw-app/index.tsx

@ -9,7 +9,25 @@ import ExcalidrawApp from "./App"; @@ -9,7 +9,25 @@ import ExcalidrawApp from "./App";
window.__EXCALIDRAW_SHA__ = import.meta.env.VITE_APP_GIT_SHA;
const rootElement = document.getElementById("root")!;
const root = createRoot(rootElement);
registerSW();
// In dev, ensure no Service Worker from previous runs interferes with module loading
if (import.meta.env.DEV && "serviceWorker" in navigator) {
void navigator.serviceWorker
.getRegistrations()
.then((regs) => regs.forEach((reg) => reg.unregister()))
.catch(() => void 0);
}
// Only register PWA Service Worker in production or when explicitly enabled
if (
import.meta.env.PROD ||
import.meta.env.VITE_APP_ENABLE_PWA === "true"
) {
try {
registerSW();
} catch {
// noop
}
}
root.render(
<StrictMode>
<ExcalidrawApp />

21
packages/excalidraw/components/App.tsx

@ -3551,7 +3551,18 @@ class App extends React.Component<AppProps, AppState> { @@ -3551,7 +3551,18 @@ class App extends React.Component<AppProps, AppState> {
}
// ------------------- Text -------------------
this.addTextFromPaste(data.text, isPlainPaste);
// Preserve formatting as a single block when the content looks like code;
// otherwise keep default behavior (split into multiple lines/elements).
const looksLikeCodeForText = (s: string) => {
if (!s) return false;
if (/```|\b(function|const|let|var|class|import|export|return|if|else|for|while|try|catch)\b/.test(s)) return true;
if (/\{\s*\}|=>|::|::=/.test(s)) return true;
const lines = s.split(/\r?\n/);
const indented = lines.filter((l) => /^\s{2,}|\t/.test(l)).length;
return indented >= 2;
};
this.addTextFromPaste(data.text, isPlainPaste || looksLikeCodeForText(data.text));
}
public pasteFromClipboard = withBatchedUpdates(
@ -3804,8 +3815,8 @@ class App extends React.Component<AppProps, AppState> { @@ -3804,8 +3815,8 @@ class App extends React.Component<AppProps, AppState> {
const textNodes = mixedContent.filter((node) => node.type === "text");
if (textNodes.length) {
this.addTextFromPaste(
textNodes.map((node) => node.value).join("\n\n"),
isPlainPaste,
textNodes.map((node) => node.value).join(""),
true,
);
}
}
@ -3852,8 +3863,8 @@ class App extends React.Component<AppProps, AppState> { @@ -3852,8 +3863,8 @@ class App extends React.Component<AppProps, AppState> {
const lines = isPlainPaste ? [text] : text.split("\n");
const textElements = lines.reduce(
(acc: ExcalidrawTextElement[], line, idx) => {
const originalText = normalizeText(line).trim();
if (originalText.length) {
const originalText = normalizeText(line);
if (originalText.trim().length) {
const topLayerFrame = this.getTopLayerFrameAtSceneCoords({
x,
y: currentY,

Loading…
Cancel
Save