Task 6 implements a configurable maximum line width setting that constrains and centers text content in the editor viewport. This feature applies to Raw, Rendered, Split, and Zen mode views.
Reference: GitHub Issue #15
Added MaxLineWidth enum with the following variants:
pub enum MaxLineWidth {
Off, // No width limit
Col80, // 80 characters
Col100, // 100 characters (default)
Col120, // 120 characters
Custom(u32), // Custom pixel width (400-2000px)
}Key methods:
to_pixels(char_width: f32) -> Option<f32>- Converts column count to pixelsdisplay_name() -> &'static str- Returns UI display namedescription() -> &'static str- Returns descriptive textis_custom() -> bool- Checks if this is a custom width
Added max_line_width field to Settings struct with default value MaxLineWidth::Col100.
Added "Maximum Line Width" section in the Editor settings panel:
- ComboBox dropdown for preset options (Off, 80, 100, 120 chars)
- Custom option with DragValue for pixel input (400-2000px range)
- Preset buttons for common custom values (600px, 800px, 1000px)
- Added
max_line_widthfield and builder method toEditorWidget - Modified centering logic to use
max_line_widthwhen not in Zen Mode:- Zen Mode uses
zen_max_column_width(in characters) - Otherwise uses
max_line_widthsetting
- Zen Mode uses
- Applied
content_marginfor centering andmax_content_width_pxfor TextEdit width constraint
- Added
max_line_widthfield and builder method toMarkdownEditor - Updated
with_settings()to applymax_line_widthfrom settings - Modified
show_rendered_editor()to wrap content in a centered container:- Horizontal layout with left/right margins for centering
- Vertical container with
set_max_width()for content constraint
Added max_line_width capture before mutable borrows in:
- Raw mode editor
- Split mode left (raw) editor
- Split mode right (preview) editor
- Rendered mode editor
- Open Settings (Ctrl+,)
- Navigate to Editor section
- Find "Maximum Line Width" dropdown
- Select a preset (80, 100, 120 characters) or Custom
- If Custom, enter pixel width (400-2000px)
The setting takes effect immediately without restart.
- Both Zen Mode and non-Zen Mode use the same
max_line_widthsetting - The only difference is centering behavior:
- Zen Mode: Content is constrained AND centered horizontally
- Non-Zen Mode: Content is constrained but left-aligned (no centering)
- The legacy
zen_max_column_widthsetting is no longer used for width calculation
When max_line_width is set but the available pane width is smaller than the configured width:
- Content width is capped to the available pane width
- Text wraps at the pane edge instead of overflowing
- This applies to split view panes when resizing the divider
| Scenario | Expected Behavior |
|---|---|
| Set to Off | Full width, left-aligned in all views |
| Set to 80 characters, wide window | Text constrained to ~80 columns, left-aligned |
| Set to 80 characters, Zen Mode ON | Text constrained to ~80 columns, centered |
| Switch to Split view | Same width constraint in both panes |
| Narrow the split pane below 80 chars | Text wraps at pane edge (no overflow) |
| Toggle 80/100/120 chars | Width changes immediately without restart |
| Custom pixel width (600px) | Column width ~600px |
| Extreme custom values | Clamped to 400-2000px range |
| App restart | Setting persisted and applied |
| File | Changes |
|---|---|
src/config/settings.rs |
Added MaxLineWidth enum and field |
src/ui/settings.rs |
Added Settings UI dropdown and input |
src/editor/widget.rs |
Raw/Split view layout logic |
src/markdown/editor.rs |
Rendered view width application |
src/app.rs |
Pass setting to editor widgets |