Skip to content

Commit

Permalink
fix: text content with tab characters act different in view/edit (exc…
Browse files Browse the repository at this point in the history
…alidraw#8336)

Co-authored-by: dwelle <[email protected]>
  • Loading branch information
clarencechaan and dwelle authored Aug 9, 2024
1 parent 7b2bee9 commit f7b3bef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ import {
isMeasureTextSupported,
isValidTextContainer,
measureText,
normalizeText,
wrapText,
} from "../element/textElement";
import {
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion packages/excalidraw/element/textWysiwyg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand Down

0 comments on commit f7b3bef

Please sign in to comment.