diff --git a/crates/text/src/ui/style_panel.rs b/crates/text/src/ui/style_panel.rs index 71ad84b0d9..6491dff78d 100644 --- a/crates/text/src/ui/style_panel.rs +++ b/crates/text/src/ui/style_panel.rs @@ -59,7 +59,8 @@ pub enum TextStyleKind { } /// A style in the list. Id 0 is the base style: "None" for character styles (shown dimmed, never deleted, -/// redefined or edited) and "Basic Paragraph" for paragraph styles (editable, never deleted). +/// redefined or edited) and "Basic Paragraph" for paragraph styles (editable, never deleted). With +/// [`TextStylesPanel::base_character_style`], character style 0 is editable and never deleted as well. #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct TextStyleRow { @@ -121,7 +122,8 @@ pub enum TextStyleAction { /// Clear Override, with a target whose style is overridden. ClearOverride, /// Redefine: the style of this id takes the target's attributes: the current style from the footer and the panel - /// menu, the row's from its menu. Not for character style 0. + /// menu, the row's from its menu. Not for character style 0 unless it is a base style + /// ([`TextStylesPanel::base_character_style`]). Redefine(u64), /// New: a style from the selected type when there is a target (`from_selection`), else a default one. The app /// opens its Style Options for the new id. @@ -136,7 +138,8 @@ pub enum TextStyleAction { Duplicate(u64), /// Delete the selected row's style (never id 0). Delete(u64), - /// Style Options for a style: a double click or Enter on a row, or the footer button (not for character style 0). + /// Style Options for a style: a double click or Enter on a row, or the footer button (not for character style 0 + /// unless it is a base style, [`TextStylesPanel::base_character_style`]). Options(u64), /// Duplicate with several rows highlighted: every highlighted style, in list order. DuplicateHighlighted, @@ -182,7 +185,9 @@ impl Outcome for TextStylesPanelOutput { /// What the panel knows of the last pass: the rules the footer, the panel menu and the keys share. #[derive(Clone, Debug, Default, PartialEq, Eq)] struct Facts { - paragraph: bool, + /// Whether style 0 is a base style the user edits: paragraph style 0, or character style 0 with + /// [`TextStylesPanel::base_character_style`]. + base: bool, target: bool, overridden: bool, current: Option, @@ -195,11 +200,11 @@ struct Facts { impl Facts { /// The action of a footer button or menu command, `None` when its condition doesn't hold. fn action(&self, command: TextStyleCommand) -> Option { - let editable = self.picked.filter(|id| *id != 0 || self.paragraph); + let editable = self.picked.filter(|id| *id != 0 || self.base); let several = self.selected.len() > 1; match command { TextStyleCommand::ClearOverride => (self.target && self.overridden).then_some(TextStyleAction::ClearOverride), - TextStyleCommand::Redefine => self.current.filter(|id| self.target && (*id != 0 || self.paragraph)).map(TextStyleAction::Redefine), + TextStyleCommand::Redefine => self.current.filter(|id| self.target && (*id != 0 || self.base)).map(TextStyleAction::Redefine), TextStyleCommand::New => Some(TextStyleAction::new_style(self.target, false)), TextStyleCommand::Duplicate if several => Some(TextStyleAction::DuplicateHighlighted), TextStyleCommand::Delete if several => Some(TextStyleAction::DeleteHighlighted), @@ -289,6 +294,10 @@ pub struct TextStylesPanel<'a> { /// Several rows select together: the footer's Duplicate and Delete act on all of them. #[prop] highlighting: bool, + /// Character style 0 is a base style the user edits instead of "No character style": it takes Style Options, + /// Duplicate and Redefine as paragraph style 0 does, is drawn like the other rows, and is still never deleted. + #[prop] + base_character_style: bool, /// The list's text with no rows, passed to the collection's `empty` prop. #[prop(into)] empty: Option