Skip to content

feat: allow per-block-type content padding via DefaultTextBlockStyle - #2760

Open
Tseshongfeeshur wants to merge 1 commit into
singerdmx:masterfrom
Tseshongfeeshur:master
Open

feat: allow per-block-type content padding via DefaultTextBlockStyle#2760
Tseshongfeeshur wants to merge 1 commit into
singerdmx:masterfrom
Tseshongfeeshur:master

Conversation

@Tseshongfeeshur

Copy link
Copy Markdown

Problem

DefaultTextBlockStyle currently has no way to control the spacing
between a block's content and its own decoration (e.g. the left
border on a blockquote, the background box on a code block). The
only related padding is EditableTextBlock.contentPadding, which is
a single global value shared by every block type in the editor —
there's no per-block override.

As a result, something as simple as "add a bit of vertical breathing
room between the blockquote text and its left border" isn't possible
without reaching into text_block.dart and hardcoding values.

Change

  • Add an optional EdgeInsets? contentPadding field to
    DefaultTextBlockStyle, with the corresponding copyWith support.
  • Forward it through DefaultListBlockStyle's constructor and
    copyWith override, so list styles can opt in as well.
  • In EditableTextBlock, add _getContentPaddingForBlock() (mirrors
    the existing _getDecorationForBlock()) to resolve a per-block
    contentPadding from DefaultStyles.quote / DefaultStyles.code,
    falling back to the editor's existing global contentPadding when
    the block style doesn't define one.

Why this shape

This reuses the existing contentPaddingRenderEditableTextBlock
rendering path (which already separates decoration painting from
content padding) rather than introducing a new spacing concept, so
the actual rendering logic (_paintDecoration, _EditableBlock,
RenderEditableTextBlock) doesn't need to change at all.

Compatibility

Fully backward compatible: the new field defaults to null, and
EditableTextBlock only uses it when a block style explicitly sets
it — otherwise the previous global contentPadding value is used
exactly as before. No existing call sites need to change.

Example

quote: DefaultTextBlockStyle(
  ...,
  contentPadding: const EdgeInsets.symmetric(vertical: 8),
),

Testing

  • Verified blockquote/code block render unchanged when
    contentPadding is left unset.
  • Verified setting contentPadding on DefaultStyles.quote adds
    vertical spacing between the text and the left border without
    shifting the border itself.

Currently only a single global contentPadding can be set for all text
blocks, so there's no way to insert spacing between a block's content
and its own decoration boundary (e.g. the left border on blockquote,
the background on code block) without affecting every other block
type.

Add an optional `contentPadding` field to `DefaultTextBlockStyle`
(and forward it through `DefaultListBlockStyle`). When set for a
given block type, `EditableTextBlock` now resolves and uses it in
place of the editor's global contentPadding for that block only;
falls back to the previous behavior when left unset.

No breaking changes: the new field is optional and defaults to null,
existing DefaultTextBlockStyle constructors and copyWith calls are
unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant