Skip to content

feat: support automatic bidi direction in editor content#95

Open
n00ki wants to merge 2 commits intoerictli:mainfrom
n00ki:feat/auto-text-direction
Open

feat: support automatic bidi direction in editor content#95
n00ki wants to merge 2 commits intoerictli:mainfrom
n00ki:feat/auto-text-direction

Conversation

@n00ki
Copy link

@n00ki n00ki commented Mar 7, 2026

  • add auto as a first-class text direction option for note content
  • wire the editor to use Tiptap's built-in textDirection support so mixed RTL/LTR content is detected correctly
  • remove the old CSS direction override so editor content direction is driven by the editor/DOM instead of a global style

Why

This improves note authoring for multilingual content by letting the editor automatically detect text direction per content block, while still preserving explicit LTR and RTL overrides in settings.

Details

  • src/types/note.ts
    • expand TextDirection to include auto
  • src/context/ThemeContext.tsx
    • default content direction to auto
    • load/save/reset auto consistently
    • stop setting the old --editor-direction CSS variable
  • src/components/settings/EditorSettingsSection.tsx
    • add an Auto option to the text direction setting
    • treat Auto as the default value
  • src/components/editor/Editor.tsx
    • pass textDirection into Tiptap editor options
  • src/App.css
    • remove the .ProseMirror direction override so it doesn't fight content-level auto direction

Summary by CodeRabbit

  • New Features

    • Added an "Auto" text direction option that detects and applies direction based on content.
  • Improvements

    • Default text direction changed to "Auto" for a better initial experience.
    • Text direction is now managed independently of layout width for clearer behavior and settings.

@coderabbitai
Copy link

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1edf21d4-c2b5-4707-beaf-ca54336d1e57

📥 Commits

Reviewing files that changed from the base of the PR and between 75e76ea and 43ebcc4.

📒 Files selected for processing (1)
  • src-tauri/src/lib.rs

📝 Walkthrough

Walkthrough

Introduces an "auto" text direction option, treats "auto" as the default, decouples text direction from layout width handling, passes textDirection into editor initialization, updates types and Tauri settings to support the new enum, and removes the CSS direction variable from the ProseMirror container.

Changes

Cohort / File(s) Summary
Type Definition
src/types/note.ts
Extend TextDirection union to include "auto" alongside "ltr" and "rtl".
Settings UI
src/components/settings/EditorSettingsSection.tsx
Add "auto" option to textDirectionOptions; treat "auto" as the default when detecting custom fonts.
Context & Layout
src/context/ThemeContext.tsx
Change initial textDirection to "auto"; add isTextDirection guard; remove direction argument from layout application and related effect dependencies; adjust reset/persist to use "auto".
Editor Initialization
src/components/editor/Editor.tsx
Pass textDirection into editor initialization/configuration via the editor hook.
Styling
src/App.css
Remove application of direction CSS variable for ProseMirror container; keep max-width sourcing from settings.
Backend (Tauri)
src-tauri/src/lib.rs
Add TextDirection enum (Auto, Ltr, Rtl) with serde support; change Settings.text_direction type from Option<String> to Option<TextDirection>.

Sequence Diagram(s)

sequenceDiagram
  participant User as "User"
  participant Settings as "Settings UI"
  participant Theme as "ThemeContext"
  participant Editor as "Editor"
  participant Tauri as "Tauri (backend)"

  User->>Settings: select text direction ("auto"/"ltr"/"rtl")
  Settings->>Theme: update settings (textDirection)
  Theme->>Tauri: persist settings (text_direction as enum)
  Theme->>Editor: provide textDirection on init / update
  Editor-->>Theme: confirm applied direction
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • erictli

Poem

🐰 I sniffed the settings, found a way to flow,

"Auto" whispers where left or right should go.
Layout hops steady, direction minds its cue,
Editor wakes up, and the pages feel new. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: support automatic bidi direction in editor content' directly and clearly summarizes the main change—adding automatic bidirectional text direction support to the editor.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/types/note.ts (1)

21-21: Keep the Rust settings schema aligned with TextDirection.

Line 21 tightens the frontend contract, but the persisted backend field is still Option<String> in src-tauri/src/lib.rs Lines 100-101. That means unsupported values can still be stored and only get filtered later in ThemeContext. Please switch the Rust side to an enum or validated wrapper so the settings contract is enforced end-to-end.

As per coding guidelines, "Maintain type safety throughout by using TypeScript types in both frontend (src/types/) and backend (Rust structs), ensuring serialization compatibility."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/types/note.ts` at line 21, The frontend tightened TextDirection to "auto"
| "ltr" | "rtl", but the backend still stores that setting as Option<String>,
allowing invalid values; change the Rust side to use a strongly-typed enum
(e.g., enum TextDirection { Auto, Ltr, Rtl }) instead of Option<String> in the
settings struct (the field currently used in lib.rs), derive serde
Serialize/Deserialize with the same string naming (rename_all or explicit
renames) and implement a Default or Option<TextDirection> as required to
preserve optionality; update any conversions/DB/serialization code that
reads/writes the setting to use this enum so the contract is enforced end-to-end
and serialization remains compatible with the frontend.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/types/note.ts`:
- Line 21: The frontend tightened TextDirection to "auto" | "ltr" | "rtl", but
the backend still stores that setting as Option<String>, allowing invalid
values; change the Rust side to use a strongly-typed enum (e.g., enum
TextDirection { Auto, Ltr, Rtl }) instead of Option<String> in the settings
struct (the field currently used in lib.rs), derive serde Serialize/Deserialize
with the same string naming (rename_all or explicit renames) and implement a
Default or Option<TextDirection> as required to preserve optionality; update any
conversions/DB/serialization code that reads/writes the setting to use this enum
so the contract is enforced end-to-end and serialization remains compatible with
the frontend.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 733b9c1b-ae3d-4f15-827f-e5aa58fa9f25

📥 Commits

Reviewing files that changed from the base of the PR and between 3331c1e and 75e76ea.

📒 Files selected for processing (5)
  • src/App.css
  • src/components/editor/Editor.tsx
  • src/components/settings/EditorSettingsSection.tsx
  • src/context/ThemeContext.tsx
  • src/types/note.ts

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