Files
zoeae/src/message.rs
T
Stevan Freeborn b382f14a55 feat: add word wrap toggle functionality
Add the ability to toggle word wrap in the text editor with Alt+Z.
Word wrap can be enabled or disabled, affecting how long lines are
displayed in edit mode.

Changes:
- Add `is_word_wrap_on` state field with default value of false
- Implement `toggle_word_wrap()` and `is_word_wrap_on()` methods
- Add ToggleWordWrap variant to ViewAction enum
- Bind Alt+Z keyboard shortcut to toggle word wrap
- Refactor editor view to support dynamic wrapping behavior
  - Use responsive widget when wrap is enabled to constrain width
  - Apply Wrapping::WordOrGlyph when enabled, Wrapping::None otherwise
- Update editor view signature to accept word wrap state parameter
- Fix indentation inconsistencies in file.rs and state.rs
2026-02-25 17:17:34 -06:00

79 lines
1.8 KiB
Rust

use std::{fmt::Display, path::PathBuf};
use iced::{widget::text_editor, window};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileAction {
New,
Save,
SaveAs,
Open,
Close(Option<usize>),
}
impl FileAction {
pub const ALL: &'static [FileAction] = &[
FileAction::New,
FileAction::Save,
FileAction::SaveAs,
FileAction::Open,
FileAction::Close(None),
];
}
impl Display for FileAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FileAction::New => write!(f, "New file"),
FileAction::Save => write!(f, "Save"),
FileAction::SaveAs => write!(f, "Save as... "),
FileAction::Open => write!(f, "Open"),
FileAction::Close(_) => write!(f, "Close"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ViewAction {
Increase,
Decrease,
Reset,
TogglePreview,
ToggleWordWrap,
}
impl ViewAction {
pub const ALL: &'static [ViewAction] = &[
ViewAction::Increase,
ViewAction::Decrease,
ViewAction::Reset,
ViewAction::TogglePreview,
ViewAction::ToggleWordWrap,
];
}
impl Display for ViewAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ViewAction::Decrease => write!(f, "Decrease font"),
ViewAction::Increase => write!(f, "Increase font"),
ViewAction::Reset => write!(f, "Reset font"),
ViewAction::TogglePreview => write!(f, "Toggle preview"),
ViewAction::ToggleWordWrap => write!(f, "Toggle word wrap"),
}
}
}
#[derive(Debug, Clone)]
pub enum Message {
WindowOpened(window::Id),
WindowClosed(window::Id),
Edit(text_editor::Action),
FileActionSelected(FileAction),
ViewActionSelected(ViewAction),
SwitchTab(usize),
LinkClicked(String),
FileOpened(Result<(PathBuf, String), String>),
FileSaved(Result<PathBuf, String>),
}