From 1c46935cc5980adbb5acddbc878bc9d9c71c041d Mon Sep 17 00:00:00 2001 From: Yuri Karamian Date: Sat, 20 Jun 2026 15:01:01 +0200 Subject: [PATCH] Add Note Width setting to cap editor content width (#137) --- src-tauri/src/commands.rs | 8 +++++ src-tauri/src/lib.rs | 1 + src-tauri/src/types.rs | 3 ++ src/lib/api.ts | 4 +++ src/lib/components/Editor.svelte | 12 ++++++- src/lib/components/SettingsPanel.svelte | 44 ++++++++++++++++++++++++- src/lib/types.ts | 1 + src/routes/+page.svelte | 3 ++ 8 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index c4c507d..660fcec 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -122,6 +122,14 @@ pub fn set_ui_scale(state: State<'_, AppState>, scale: f64) -> Result<(), String Ok(()) } +#[tauri::command] +pub fn set_content_width(state: State<'_, AppState>, width: Option) -> Result<(), String> { + let mut config = state.config.lock().map_err(|e| e.to_string())?; + config.content_width = width; + save_app_config(&config)?; + Ok(()) +} + // ── Notebooks ── #[tauri::command] diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1d8c648..364fe54 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -106,6 +106,7 @@ pub fn run() { commands::set_font_family, commands::set_line_height, commands::set_ui_scale, + commands::set_content_width, commands::get_notebooks, commands::count_root_notes, commands::create_notebook, diff --git a/src-tauri/src/types.rs b/src-tauri/src/types.rs index 368f93d..421d11d 100644 --- a/src-tauri/src/types.rs +++ b/src-tauri/src/types.rs @@ -72,6 +72,8 @@ pub struct AppConfig { #[serde(default)] pub ui_scale: Option, #[serde(default)] + pub content_width: Option, + #[serde(default)] pub compact_notes: bool, #[serde(default = "default_true")] pub show_note_dates: bool, @@ -205,6 +207,7 @@ impl Default for AppConfig { font_family: None, line_height: None, ui_scale: None, + content_width: None, compact_notes: false, show_note_dates: true, time_format: "relative".to_string(), diff --git a/src/lib/api.ts b/src/lib/api.ts index d2350ac..01aad83 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -52,6 +52,10 @@ export async function setUiScale(scale: number): Promise { return invoke("set_ui_scale", { scale }); } +export async function setContentWidth(width: number | null): Promise { + return invoke("set_content_width", { width }); +} + export async function getNotebooks(): Promise { return invoke("get_notebooks"); } diff --git a/src/lib/components/Editor.svelte b/src/lib/components/Editor.svelte index 265cb9a..6b88cf5 100644 --- a/src/lib/components/Editor.svelte +++ b/src/lib/components/Editor.svelte @@ -7433,7 +7433,8 @@ resize: none; outline: none; padding: 0 0 var(--editor-scroll-past-end, 65vh); - margin: 0; + margin: 0 auto; + max-width: var(--editor-content-width, none); user-select: text; /* Wrap long lines instead of horizontal-scrolling (matches mobile). (issue #100) */ white-space: pre-wrap; @@ -7447,6 +7448,9 @@ Keep no-wrap (horizontal scroll) whenever line numbers are on. (issue #100) */ white-space: pre; overflow-x: auto; + /* The line-number gutter is pinned to the left edge, so don't center/cap here. (#137) */ + max-width: none; + margin: 0; } .line-numbers-clip { @@ -7479,6 +7483,12 @@ .tiptap-wrapper { height: 100%; user-select: text; + /* Optional reading-width cap (Settings > Styling > Note Width). Default `none` = full + width; when set, the text column is capped and centered. Scrollbar stays at the + panel edge because only the inner content is constrained, not .editor-body. (#137) */ + max-width: var(--editor-content-width, none); + margin-left: auto; + margin-right: auto; } :global(.tiptap-wrapper .tiptap) { diff --git a/src/lib/components/SettingsPanel.svelte b/src/lib/components/SettingsPanel.svelte index ceb392b..35ec4f0 100644 --- a/src/lib/components/SettingsPanel.svelte +++ b/src/lib/components/SettingsPanel.svelte @@ -1,6 +1,6 @@