Browse Source

fix: text content with tab characters act different in view/edit (#8336)

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
zsviczian-fix-8346
Clarence Chan 1 year ago committed by GitHub
parent
commit
f7b3befd0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      packages/excalidraw/components/App.tsx
  2. 11
      packages/excalidraw/element/textWysiwyg.tsx

3
packages/excalidraw/components/App.tsx

@ -332,6 +332,7 @@ import { @@ -332,6 +332,7 @@ import {
isMeasureTextSupported,
isValidTextContainer,
measureText,
normalizeText,
wrapText,
} from "../element/textElement";
import {
@ -3412,7 +3413,7 @@ class App extends React.Component<AppProps, AppState> { @@ -3412,7 +3413,7 @@ class App extends React.Component<AppProps, AppState> {
const lines = isPlainPaste ? [text] : text.split("\n");
const textElements = lines.reduce(
(acc: ExcalidrawTextElement[], line, idx) => {
const originalText = line.trim();
const originalText = normalizeText(line).trim();
if (originalText.length) {
const topLayerFrame = this.getTopLayerFrameAtSceneCoords({
x,

11
packages/excalidraw/element/textWysiwyg.tsx

@ -357,7 +357,16 @@ export const textWysiwyg = ({ @@ -357,7 +357,16 @@ export const textWysiwyg = ({
};
editable.oninput = () => {
onChange(normalizeText(editable.value));
const normalized = normalizeText(editable.value);
if (editable.value !== normalized) {
const selectionStart = editable.selectionStart;
editable.value = normalized;
// put the cursor at some position close to where it was before
// normalization (otherwise it'll end up at the end of the text)
editable.selectionStart = selectionStart;
editable.selectionEnd = selectionStart;
}
onChange(editable.value);
};
}

Loading…
Cancel
Save