1 parent
5bda37b05d
commit
baec487a21
3 files changed
+52
-2
No files matched your search
@@ -6,5 +6,19 @@ describe("firstLineCellDisplayValue", () => {
|
||||
expect(firstLineCellDisplayValue("111\n222")).toBe("111");
|
||||
expect(firstLineCellDisplayValue("111\r\n222")).toBe("111");
|
||||
expect(firstLineCellDisplayValue("111\r222")).toBe("111");
|
||||
expect(firstLineCellDisplayValue("single line")).toBe("single line");
|
||||
});
|
||||
|
||||
it("skips leading blank lines without stripping content indentation", () => {
|
||||
expect(firstLineCellDisplayValue("\nINNODB MONITOR OUTPUT\nbody")).toBe("INNODB MONITOR OUTPUT");
|
||||
expect(firstLineCellDisplayValue("\r\nINNODB MONITOR OUTPUT\r\nbody")).toBe("INNODB MONITOR OUTPUT");
|
||||
expect(firstLineCellDisplayValue("\rINNODB MONITOR OUTPUT\rbody")).toBe("INNODB MONITOR OUTPUT");
|
||||
expect(firstLineCellDisplayValue(" \n indented content\nbody")).toBe(" indented content");
|
||||
});
|
||||
|
||||
it("preserves values that do not contain a content line", () => {
|
||||
expect(firstLineCellDisplayValue("")).toBe("");
|
||||
expect(firstLineCellDisplayValue(" ")).toBe(" ");
|
||||
expect(firstLineCellDisplayValue("\n\r\n \r")).toBe("\n\r\n \r");
|
||||
});
|
||||
});
|
||||
@@ -11,8 +11,25 @@ export function displayCellValue(value: CellValue): string {
|
||||
}
|
||||
|
||||
export function firstLineCellDisplayValue(value: string): string {
|
||||
const lineBreakIndex = value.search(/\r\n|\r|\n/);
|
||||
return lineBreakIndex === -1 ? value : value.slice(0, lineBreakIndex);
|
||||
const lineBreakPattern = /\r\n|\r|\n/g;
|
||||
const firstLineBreak = lineBreakPattern.exec(value);
|
||||
if (!firstLineBreak) return value;
|
||||
|
||||
const firstLine = value.slice(0, firstLineBreak.index);
|
||||
if (/\S/u.test(firstLine)) return firstLine;
|
||||
|
||||
let lineStart = lineBreakPattern.lastIndex;
|
||||
|
||||
while (lineStart <= value.length) {
|
||||
const lineBreak = lineBreakPattern.exec(value);
|
||||
const lineEnd = lineBreak?.index ?? value.length;
|
||||
const line = value.slice(lineStart, lineEnd);
|
||||
if (/\S/u.test(line)) return line;
|
||||
if (!lineBreak) return value;
|
||||
lineStart = lineBreakPattern.lastIndex;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export function limitDataGridCellDisplay(value: string, maxLength = DATA_GRID_CELL_DISPLAY_MAX_LENGTH): string {
|
||||
|
||||
Reference in new issue
Block a user