From df2f2f22d4126acb2be4a496b430799228664ee4 Mon Sep 17 00:00:00 2001 From: Mathias Jakobsen Date: Wed, 13 Sep 2023 09:56:51 +0100 Subject: [PATCH] Merge pull request #14811 from overleaf/mj-table-cell-overflow-selection-border [visual] Fix cell overflow and cell selection outline GitOrigin-RevId: 91cea09956d27162283c12e842f0b5e1680ed582 --- .../components/table-generator/cell.tsx | 2 +- .../components/table-generator/table.tsx | 25 ++++++++----------- .../extensions/visual/table-generator.ts | 7 ++++-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/cell.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/cell.tsx index e71260ca97..cde64a37d1 100644 --- a/services/web/frontend/js/features/source-editor/components/table-generator/cell.tsx +++ b/services/web/frontend/js/features/source-editor/components/table-generator/cell.tsx @@ -180,7 +180,7 @@ export const Cell: FC<{ [update, filterInput] ) - let body =
+ let body =
if (editing) { body = ( { const { table: tableData } = useTableContext() const tableRef = useRef(null) const view = useCodeMirrorViewContext() - const cellWidths: number[] = useMemo(() => { + const { columns: cellWidths, tableWidth } = useMemo(() => { const columns = Array.from( { length: tableData.columns.length }, () => MINIMUM_CELL_WIDTH_CHARACTERS @@ -95,9 +95,9 @@ export const Table: FC = () => { // Third pass, normalize the columns to the total width of the table const totalLog = columns.reduce((a, b) => a + b, 0) for (let i = 0; i < columns.length; ++i) { - columns[i] = Math.round((columns[i] / totalLog) * total) + columns[i] = Math.round((columns[i] / totalLog) * 100) } - return columns + return { columns, tableWidth: total } }, [ tableData, cellData?.cellIndex, @@ -333,20 +333,15 @@ export const Table: FC = () => { onKeyDown={onKeyDown} tabIndex={-1} ref={tableRef} + style={{ width: `${tableWidth}ch` }} > + + + {tableData.columns.map((_, index) => ( + + ))} + - {/* A workaround for a chrome bug where it will not respect colspan - unless there is a row filled with cells without colspan */} - - {/* A td for the row selector */} - - {tableData.columns.map((_, columnIndex) => ( - - ))} - {tableData.columns.map((_, columnIndex) => ( diff --git a/services/web/frontend/js/features/source-editor/extensions/visual/table-generator.ts b/services/web/frontend/js/features/source-editor/extensions/visual/table-generator.ts index 4fa772701d..dbcd1f204e 100644 --- a/services/web/frontend/js/features/source-editor/extensions/visual/table-generator.ts +++ b/services/web/frontend/js/features/source-editor/extensions/visual/table-generator.ts @@ -117,8 +117,11 @@ export const tableGeneratorTheme = EditorView.baseTheme({ 'border-bottom-color': 'var(--table-generator-active-border-color)', 'border-bottom-width': 'var(--table-generator-active-border-width)', }, - 'overflow-x': 'auto', - 'overflow-y': 'hidden', + '& .table-generator-cell-render': { + 'overflow-x': 'auto', + 'overflow-y': 'hidden', + width: '100%', + }, }, '.table-generator-table': {