Skip to content

Commit

Permalink
fix(compass-components): calculate the maximum line length in a more …
Browse files Browse the repository at this point in the history
…stack efficient way COMPASS-7647 (#5509)

fix for very many line breaks and a regression test
  • Loading branch information
lerouxb committed Mar 1, 2024
1 parent 967d7dd commit 0481310
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('Document', function () {
num: 123,
date: new Date(0),
null_value: null,
// Regression test for very large numbers of parameters passed to
// Math.max(). One test starts to fail at around 62535 line breaks, more
// after that. It depends on how much data is already on the stack at that
// point.
crazy_string: Array.from({ length: 100000 }, () => '\n').join('\n'),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,13 @@ export const ValueEditor: React.FunctionComponent<{
const inputStyle = useMemo(() => {
if (type === 'String') {
const lines = val.split('\n');
const longestLineCharLength = Math.max(
...lines.map((line) => line.length)
);
let longestLineCharLength = 0;
for (const line of lines) {
const length = line.length;
if (length > longestLineCharLength) {
longestLineCharLength = length;
}
}
const width = `${Math.min(
// Adding one to account for a textarea resize icon button thingie
longestLineCharLength + 1,
Expand Down

0 comments on commit 0481310

Please sign in to comment.