Skip to content

feat: bold, italic, underline and strikeout, written into the line's own text - #100

Merged
xAlcahest merged 1 commit into
mainfrom
style-toggles
Sep 6, 2026
Merged

feat: bold, italic, underline and strikeout, written into the line's own text#100
xAlcahest merged 1 commit into
mainfrom
style-toggles

Conversation

@xAlcahest

Copy link
Copy Markdown
Owner

Summary

The panel gains the four inline style buttons. Select a word and press Bold and the word is wrapped in the tags that make it bold; press it again and the tags come off. With no selection the tag is written at the caret and takes effect to the end of the line. Each is its own undo step, and bold and italic on one line never merge into one.

The whole of it is one rule. The flag starts wherever the style the line names sets it, any tag already in force at the caret overrides that, and the opposite value is written there; then, for a selection, the original value is written back at the far end, shifted by however many bytes the first write inserted. That shift is why the writer returns one, and it is what the tag writer landed for.

It is planned and applied in Rust, not computed in the panel. Edit::ToggleStyle names the cue, the flag and the two offsets, and everything that could corrupt a line happens behind the same plan, splice, re-parse and verify every other edit goes through. The panel's part is to say where the selection is, which it already reported for splitting and now reports both ends of.

Verified on Linux: full gate green, battery green at 276 of 276, four Rust tests over the edit and one behavioural check over the button. The check was made to fail before being believed: with the far end of the selection ignored, "wraps the selected words in a style tag" reddens first, on a build seen compiling.

Changes

  • crates/sublore-formats/src/override_tags.rs: StyleFlag names the four and says which tag carries each and what a style sets it to, flag_value reads a tag's value, and the caret on a block boundary now takes the braced side, so a caret just past a closing brace is inside the block that closed rather than in the words after it.
  • crates/sublore-edit/src/plan.rs: Edit::ToggleStyle and plan_toggle_style, which is the rule above.
  • crates/sublore-edit/src/splice.rs: EditKind::ToggleStyle, carrying which flag, so two flags on one line are two steps.
  • crates/sublore-edit/tests/session.rs: a selection wrapped and undone, a caret writing one tag, a second toggle replacing the tag rather than adding one, and a range past the end of the text refused.
  • src-tauri/src/subtitle/mod.rs and src-tauri/src/lib.rs: subtitle_toggle_style and its registration.
  • src/hooks/useSubtitleFile.ts and src/types/subtitle.ts: toggleStyle and the flag name it takes.
  • src/components/CurrentLine.tsx: reports both ends of the selection, and draws the four buttons before Next line, which is where row three puts them.
  • src/App.tsx: the four registry commands, their place in the Edit menu, and the selection it hands them.
  • src/i18n/en.ts: the four labels.
  • e2e/specs/command-registry.spec.js: the four in the declared list and in the greyed-with-nothing-open list.
  • e2e/specs/current-line-bands.spec.js: the behavioural check, the button in the sweep, and the shortfall ceiling.
  • e2e/wdio.conf.js: EXPECTED_TESTS to 276.

How to verify it by using the app

  1. Open the app and open fixtures/subtitles/ass/clean/speakers.ass.
  2. Click the first line. Under the text box there are now Bold, Italic, Underline and Strikeout beside Next line.
  3. In the text box, select the word harbour, then press Bold. The text becomes The {\b1}harbour{\b0} freezes over by December.
  4. Press Ctrl+Z. The word goes back to plain.
  5. Put the caret in the middle of the line without selecting anything and press Italic. One tag appears at the caret and nothing closes it, so the rest of the line is italic.
  6. Press Italic again with the caret just after that tag. The tag flips to off in place rather than a second one being added.
  7. Save and open the file in a text editor. The tags are in the line's text and no other byte has moved.

@xAlcahest
xAlcahest merged commit 170c662 into main Sep 6, 2026
14 checks passed
@xAlcahest
xAlcahest deleted the style-toggles branch September 6, 2026 17:27
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