Skip to content

Give typed text the body style when nothing neighbours it - #97

Merged
Wavesonics merged 2 commits into
mainfrom
fix/typed-text-body-style
Aug 7, 2026
Merged

Give typed text the body style when nothing neighbours it#97
Wavesonics merged 2 commits into
mainfrom
fix/typed-text-body-style

Conversation

@Wavesonics

Copy link
Copy Markdown
Collaborator

The bug

Typed text adopts the styles of the character next to the caret: the one before it, or the one it sits in front of. When neither exists, getSpanStylesForEditAt returned nothing, so the text carried no SpanStyle at all and rendered at the host's bare TextStyle size instead of the document's body size.

That is not a rare edge case. Paragraphs are separated by a blank line, so every paragraph after the first starts at column 0 with an empty line above it: no preceding character, and none in front either. Any newly typed paragraph came out at the default size while the imported text around it stayed correct.

Found in Hammer, which passes TextStyle.Default as the editor style and carries the real (user-scalable) font size as a span on every character. A list typed between two loaded paragraphs rendered noticeably smaller than the prose around it.

The fix

When nothing neighbouring supplies a style, fall back to markdownConfiguration.defaultTextStyle.

That configuration is only meaningful once a markdown or HTML extension installs it, so TextEditorState now tracks whether that happened. A plain editor never opts in and keeps the previous behaviour: its typed text is left to the host's TextStyle rather than being stamped with a 16sp body style it never asked for.

Tests

TypedTextBodyStyleTest covers a paragraph typed after a blank line, a list typed after a blank line, typing into an empty document, a neighbouring style still winning over the fallback, and a plain editor staying untouched.

Full :ComposeTextEditor:desktopTest passes.

Typed text adopts the styles of the character next to the caret. Where
there is none, it carried no style at all and rendered at the host's bare
TextStyle size rather than the document's body size.

That is not a rare edge: paragraphs are separated by a blank line, so
every paragraph after the first starts at column 0 with an empty line
above it. Any new paragraph, list or otherwise, came out at the default
size while the imported text around it stayed correct.

Markdown and HTML editors now fall back to the configured
defaultTextStyle. Plain editors opt out via hasMarkdownConfiguration so
their typed text is still left to the host's TextStyle.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 10 complexity · 2 duplication

Metric Results
Complexity 10
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@Wavesonics
Wavesonics merged commit 34ddb65 into main Aug 7, 2026
2 checks passed
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