Skip to content

"Keep with next" paragraph setting does not prevent table rows from splitting across pages #3641

@brieyla1

Description

@brieyla1

Description

When paragraphs inside table cells have the "Keep with next" paragraph setting enabled (Line & Page Breaks > Keep with next), the table still splits across page breaks. The same document in MS Word correctly keeps the rows together on the same page.

Steps to reproduce

  1. Create a new document
  2. Add text to fill most of page 1
  3. Insert a table with 3-4 rows below the text
  4. Select all cells in the first row
  5. Open Paragraph > Advanced Settings > Line & Page Breaks
  6. Check "Keep with next"
  7. Observe: the table is split across pages (first row on page 1, remaining rows on page 2)

Expected behavior

The entire table should move to page 2, keeping all rows together — matching MS Word behavior.

Actual behavior

The table splits across the page break despite "Keep with next" being set.

Root cause

RecalculateKeepNext() in DocumentContentElementBase.js (line 292) returns early when this.Parent is not CDocument. Since paragraphs inside table cells have CDocumentContent as their parent, KeepNext is never evaluated for paragraphs within table cells. The table layout engine in TableRecalculate.js has no logic to check KeepNext on cell paragraphs when deciding where to split rows across pages.

Proposed fix

Added KeepNext backtracking in the table page-break logic in TableRecalculate.js. After determining which row triggers a page break, walk backward and also move rows whose last cell paragraph has KeepNext set. Includes an infinite-loop guard for when the table is the first element on the page.

See PR: ONLYOFFICE/sdkjs#4870

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions