Skip to content

Add hyphenation#4018

Open
Annonnymmousss wants to merge 3 commits intoGraphiteEditor:masterfrom
Annonnymmousss:feat_hyphenation
Open

Add hyphenation#4018
Annonnymmousss wants to merge 3 commits intoGraphiteEditor:masterfrom
Annonnymmousss:feat_hyphenation

Conversation

@Annonnymmousss
Copy link
Copy Markdown
Contributor

@Annonnymmousss Annonnymmousss commented Apr 8, 2026

Partially closes #2351

The hyphenation should ideally be merged only after parley implement hyphenation support (insertion of "-" on breaking points). Currently with Hyphenate crate we can break the words according to dictionary.

Screen.Recording.2026-04-09.at.3.34.58.AM.mov
Screen.Recording.2026-04-09.at.3.36.17.AM.mov

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements text hyphenation support by integrating the hyphenation crate and adding a hyphenate toggle to the TypesettingConfig. The implementation includes a new utility to insert soft hyphens into English text when a maximum width is specified. Feedback suggests improving the robustness of dictionary initialization to prevent potential panics and making the OverflowWrap::BreakWord setting conditional on the hyphenation toggle to avoid unintended layout changes for standard text.

Comment on lines +18 to +27
static EN_US_DICT: OnceLock<Standard> = OnceLock::new();

fn get_dict_for_language(lang: Language) -> Option<&'static Standard> {
match lang {
Language::EnglishUS | Language::EnglishGB => EN_US_DICT
.get_or_init(|| Standard::from_embedded(Language::EnglishUS).expect("embed_all feature must be enabled"))
.into(),
_ => None,
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using expect during dictionary initialization will cause the application to panic if the hyphenation data fails to load (e.g., if the embed_all feature is missing or the binary data is corrupted). It is safer to use OnceLock<Option<Standard>> and handle the failure gracefully by logging an error and returning None. This allows the text to render without hyphenation instead of crashing the entire application.

static EN_US_DICT: OnceLock<Option<Standard>> = OnceLock::new();

fn get_dict_for_language(lang: Language) -> Option<&'static Standard> {
	match lang {
		Language::EnglishUS | Language::EnglishGB => EN_US_DICT
			.get_or_init(|| {
				Standard::from_embedded(Language::EnglishUS).map_err(|err| {
					log::error!("Failed to load hyphenation dictionary: {err}");
					err
				}).ok()
			})
			.as_ref(),
		_ => None,
	}
}

@Annonnymmousss
Copy link
Copy Markdown
Contributor Author

Annonnymmousss commented Apr 8, 2026

I have also tried manually inserting "-" at breaking, but it would be better to extend parley's support rather than mix implementaton.

Screen.Recording.2026-04-09.at.2.12.42.AM.mov
Screen.Recording.2026-04-09.at.2.10.47.AM.mov

@Annonnymmousss
Copy link
Copy Markdown
Contributor Author

Ideally we should break URLs or emails in a specific way but currently parley doesn't support it.

@Annonnymmousss Annonnymmousss changed the title feat: hyphenation Add hyphenation Apr 8, 2026
@Annonnymmousss
Copy link
Copy Markdown
Contributor Author

@cubic-dev

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai bot commented Apr 9, 2026

@cubic-dev

@Annonnymmousss I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 11 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@Annonnymmousss Annonnymmousss marked this pull request as ready for review April 9, 2026 07:43
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 11 files

Confidence score: 3/5

  • There is a concrete backward-compatibility risk: inserting the new hyphenate input shifts positional indices, so existing saved graphs may misinterpret inputs when deserialized.
  • Severity is mid-range and user-impacting (graphs could load with incorrect input mapping), which keeps this at a moderate risk rather than a safe-to-merge 4/5.
  • Pay close attention to node-graph/nodes/gstd/src/text.rs - positional Vec<NodeInput> index shift affecting saved graphs.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="node-graph/nodes/gstd/src/text.rs">

<violation number="1" location="node-graph/nodes/gstd/src/text.rs:62">
P2: Inserting the new `hyphenate` input between existing parameters shifts positional input indices. Because node inputs are serialized in a positional `Vec<NodeInput>`, existing saved graphs may interpret the previous `separate_glyph_elements` input as `hyphenate` unless a migration handles the reindexing.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@Annonnymmousss Annonnymmousss marked this pull request as draft April 9, 2026 09:08
@Annonnymmousss Annonnymmousss marked this pull request as ready for review April 9, 2026 09:09
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 12 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

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.

Text alignment, justification, and hyphenation

1 participant