View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0017998 | Scribus | Tables | public | 2026-10-09 10:47 | 2026-10-30 06:16 |
| Reporter | marhaec | Assigned To | |||
| Priority | normal | Severity | tweak | Reproducibility | always |
| Status | new | Resolution | open | ||
| OS | Linux | ||||
| Product Version | 1.7.4.svn | ||||
| Summary | 0017998: apply paragraph style to multiple table cells at once | ||||
| Description | In in scribus/pageitem_table.cpp and scribus/scribusdoc.cpp ScribusDoc::itemSelection_ApplyParagraphStyle currently silently collapses a multi-cell selection to just the active cell, so paragraph styles only ever applied to one cell at a time. The fix delegates to a new PageItem_Table::setSelectedCellsParagraphStyle() method that applies the style to every selected cell's text frame. | ||||
| Tags | #patch_to_be_reviewed, #waiting | ||||
| Attached Files | Apply-paragraph-style-to-multiple-selected-table-cel.patch (7,208 bytes)
From 7aabbc800999833475735f95bf70999118bd9437 Mon Sep 17 00:00:00 2001
From: Scribus PR Author <pr-author@example.com>
Date: Fri, 9 Oct 2026 10:40:57 +0000
Subject: [PATCH] #181: Apply paragraph style to multiple selected table cells
When in table-edit mode with multiple cells selected, applying a
paragraph style from the PP palette (or via the Scripter) was silently
applied only to the active cell, ignoring the rest of the selection.
The bug was in ScribusDoc::itemSelection_ApplyParagraphStyle: it
unconditionally collapsed the table's selection to activeCell().textFrame().
This change adds PageItem_Table::setSelectedCellsParagraphStyle(), which
iterates the cell selection (with the same active-cell fallback that
setCellStyle() uses) and applies the new paragraph style to every
paragraph in every selected cell's text frame, using the same per-
paragraph ScOldNewState<ParagraphStyle> undo entries that the single-
cell code path produces. The result is a single undo step that
reverses the whole multi-cell apply.
---
scribus/pageitem_table.cpp | 76 ++++++++++++++++++++++++++++++++++++++
scribus/pageitem_table.h | 25 +++++++++++++
scribus/scribusdoc.cpp | 9 ++++-
3 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/scribus/pageitem_table.cpp b/scribus/pageitem_table.cpp
index 93cad16..a1e31ff 100644
--- a/scribus/pageitem_table.cpp
+++ b/scribus/pageitem_table.cpp
@@ -32,6 +32,7 @@ for which a new license (GPL+exception) is in place.
#include "styles/tablestyle.h"
#include "tablehandle.h"
#include "tableutils.h"
+#include "text/specialchars.h"
#include "undomanager.h"
#include "undostate.h"
#include "util_text.h"
@@ -1942,6 +1943,81 @@ void PageItem_Table::setCellStyle(const QString& cellStyle)
emit changed();
}
+int PageItem_Table::setSelectedCellsParagraphStyle(const ParagraphStyle& newStyle, bool rmDirectFormatting)
+{
+ // Pick the set of cells we will touch. Behaviour mirrors setCellStyle() in
+ // this same file: when the user is in table-edit mode, the selection
+ // (m_selection) is used; if it is empty, fall back to the active cell;
+ // outside table-edit mode, every cell in the table is touched.
+ QSet<TableCell> targetCells;
+ if (m_Doc->appMode == modeEditTable)
+ {
+ targetCells = m_selection;
+ if (targetCells.isEmpty())
+ targetCells.insert(m_activeCell);
+ }
+ else
+ {
+ targetCells = this->cells();
+ }
+
+ if (targetCells.isEmpty())
+ return 0;
+
+ int affectedCells = 0;
+ for (const TableCell& cell : targetCells)
+ {
+ PageItem_TextFrame* cellFrame = cell.textFrame();
+ if (!cellFrame)
+ continue;
+
+ const int textLen = cellFrame->itemText.length();
+ if (textLen <= 0)
+ continue;
+
+ // Walk every paragraph separator in this cell and apply the new
+ // paragraph style. The pattern is the same one used in
+ // ScribusDoc::itemSelection_ApplyParagraphStyle() for a single text
+ // frame, so the per-paragraph undo entries produced here are
+ // indistinguishable from those produced when applying the style to a
+ // regular text frame in the document.
+ for (int pos = 0; pos < textLen; ++pos)
+ {
+ if (cellFrame->itemText.text(pos) == SpecialChars::PARSEP)
+ {
+ if (UndoManager::undoEnabled())
+ {
+ auto* is = new ScOldNewState<ParagraphStyle>(Um::SetStyle);
+ is->set("APPLY_PARASTYLE");
+ is->set("POS", pos);
+ is->setStates(cellFrame->itemText.paragraphStyle(pos), newStyle);
+ undoManager->action(cellFrame, is);
+ }
+ cellFrame->itemText.applyStyle(pos, newStyle, rmDirectFormatting);
+ }
+ }
+ // The trailing paragraph starts at the end of the cell text and also
+ // needs the new style applied to it.
+ if (UndoManager::undoEnabled())
+ {
+ auto* is = new ScOldNewState<ParagraphStyle>(Um::SetStyle);
+ is->set("APPLY_PARASTYLE");
+ is->set("POS", textLen);
+ is->setStates(cellFrame->itemText.paragraphStyle(textLen), newStyle);
+ undoManager->action(cellFrame, is);
+ }
+ cellFrame->itemText.applyStyle(textLen, newStyle, rmDirectFormatting);
+ cellFrame->invalid = true;
+ cellFrame->invalidateLayout();
+ ++affectedCells;
+ }
+
+ if (affectedCells > 0)
+ emit changed();
+
+ return affectedCells;
+}
+
void PageItem_Table::setStyle(const QString& style)
{
if (UndoManager::undoEnabled())
diff --git a/scribus/pageitem_table.h b/scribus/pageitem_table.h
index c9224c2..31eb8ce 100644
--- a/scribus/pageitem_table.h
+++ b/scribus/pageitem_table.h
@@ -23,6 +23,7 @@ for which a new license (GPL+exception) is in place.
#include "scribusapi.h"
#include "scribusstructs.h"
#include "styles/cellstyle.h"
+#include "styles/paragraphstyle.h"
#include "styles/styleset.h"
#include "styles/tablearea.h"
#include "styles/tablestyle.h"
@@ -577,6 +578,30 @@ public:
/// Sets the cell style of this table to @a cellStyle.
void setCellStyle(const QString& cellStyle);
+ /**
+ * Applies @a newStyle to every paragraph in every currently selected cell's
+ * text frame. Used by the paragraph-style / character-style palettes and
+ * by the Scripter when the user has multiple table cells selected and
+ * picks a paragraph style.
+ *
+ * The selection falls back to the active cell when no cell is selected
+ * (mirroring the behaviour of setCellStyle() in this same file).
+ *
+ * If @a rmDirectFormatting is true, direct formatting on the existing
+ * paragraph style is wiped before @a newStyle is applied. This matches
+ * the behaviour of ScribusDoc::itemSelection_ApplyParagraphStyle() for
+ * regular text frames.
+ *
+ * The caller is responsible for opening an UndoTransaction; this method
+ * only emits per-paragraph ScOldNewState<ParagraphStyle> undo entries
+ * for each cell, matching the pattern used by setCellStyle().
+ *
+ * Returns the number of cells whose text was actually modified. A return
+ * value of 0 means nothing was changed (no selection, no cell text, or
+ * the table is not in modeEditTable and has no cells at all).
+ */
+ int setSelectedCellsParagraphStyle(const ParagraphStyle& newStyle, bool rmDirectFormatting = false);
+
/// Sets the table style of this table to @a style.
void setStyle(const QString& style);
diff --git a/scribus/scribusdoc.cpp b/scribus/scribusdoc.cpp
index 59edd2a..42dc1f5 100644
--- a/scribus/scribusdoc.cpp
+++ b/scribus/scribusdoc.cpp
@@ -9945,8 +9945,15 @@ void ScribusDoc::itemSelection_ApplyParagraphStyle(const ParagraphStyle & newSty
for (int i = 0; i < selectedItemCount; ++i)
{
PageItem *currItem = itemSelection->itemAt(i);
+ // When the user is in table-edit mode and has multiple cells selected,
+ // delegate the per-cell text application to PageItem_Table so that the
+ // paragraph style is applied to every selected cell's text frame, not
+ // only the text frame of the active cell. See issue #181.
if (currItem->isTable() && appMode == modeEditTable)
- currItem = currItem->asTable()->activeCell().textFrame();
+ {
+ currItem->asTable()->setSelectedCellsParagraphStyle(newStyle, rmDirectFormatting);
+ continue;
+ }
int currItemTextCount = currItem->itemText.length();
if ((currItemTextCount == 0) || ((appMode != modeEdit) && (appMode != modeEditTable)))
{
--
2.39.5
| ||||
| Patch | Yes | ||||
|
|
I am not sure if your patch is missing something or not. When in edit text mode, you get the Text Properties palette. If you select multiple cells, you only get the Table Properties palette, so what you are doing cannot be achieved from the UI. You can achieve it with current code by applying a cell style across multiple cells already however. Maybe check for other changes, plus supply a sample script. |
|
|
ping |
|
|
First, I don't see either how this patch is working. In the future we might need to think about having multiple content palettes to be shown for the same selection. But I would not just do it, without serious thoughts on how to best achieve it. In the short term, there is a ticket for enabling shift-esc also for the table mode (0018053) and the Style Browser is also planned to also allow applying styles that do not match the current "mode". A further enhancement could be to allow the text selection across multiple adjacent cells. But that would probably need some changes in the way tables are edited (as an example, by requiring the user to enter twice the edit mode of the table: once to select the cell and then to edit its content) |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-10-09 10:47 | marhaec | New Issue | |
| 2026-10-09 10:47 | marhaec | Tag Attached: #patch_to_be_reviewed | |
| 2026-10-09 10:47 | marhaec | File Added: Apply-paragraph-style-to-multiple-selected-table-cel.patch | |
| 2026-10-12 19:55 | cbradney | Note Added: 0054523 | |
| 2026-10-29 19:17 | cbradney | Note Added: 0054624 | |
| 2026-10-30 06:15 | ale | Note Added: 0054628 | |
| 2026-10-30 06:16 | ale | Tag Attached: #waiting |