mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
panels-w13: net change of 1 commits
- panels-w13: the bare-caret warning answers every attempt to apply a character style, a click on the selected row and Enter included (tools run round)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//! Clear Override and Redefine, then Style Options, Duplicate, New and Delete. The styles, their attributes and the
|
||||
//! commands are the app's; the panel reports what the user asked for.
|
||||
|
||||
use craft_behavior::{IconId, Selection, SelectionChange, keyed};
|
||||
use craft_behavior::{IconId, Selection, keyed};
|
||||
use craft_theme::variant::Tone;
|
||||
use craft_ui::bars::StatusMessage;
|
||||
use craft_ui::contract::{
|
||||
@@ -411,20 +411,15 @@ impl<'a> TextStylesPanel<'a> {
|
||||
|
||||
let pointer = craft_ui::runtime::pointer::frame(ui.ctx());
|
||||
let alt = pointer.mods.alt;
|
||||
// A press reports the selection it makes, then the lead it moved.
|
||||
let by_pointer =
|
||||
events.iter().any(|event| matches!(event, CollectionEvent::LeadMoved { by: craft_ui::contract::LeadSource::Pointer, .. }));
|
||||
let plain = !pointer.mods.shift && !pointer.mods.cmd;
|
||||
for event in events {
|
||||
match event {
|
||||
CollectionEvent::Selection(SelectionChange::Set(keys)) if by_pointer && keys.len() == 1 => {
|
||||
if target && !paragraph && !text_selected {
|
||||
hint.set(true);
|
||||
}
|
||||
}
|
||||
CollectionEvent::Activate(id) if second && (id != 0 || paragraph) => action.set(Some(TextStyleAction::Options(id))),
|
||||
CollectionEvent::Activate(id) if target && (paragraph || text_selected) && !pointer.mods.shift && !pointer.mods.cmd => {
|
||||
CollectionEvent::Activate(id) if target && (paragraph || text_selected) && plain => {
|
||||
action.set(Some(TextStyleAction::apply(id, alt)));
|
||||
}
|
||||
// A character style at a bare caret has nothing to apply to: the attempt warns instead.
|
||||
CollectionEvent::Activate(_) if target && !paragraph && !text_selected && plain => hint.set(true),
|
||||
CollectionEvent::Delete(keys) if keys.len() > 1 => action.set(Some(TextStyleAction::DeleteHighlighted)),
|
||||
CollectionEvent::Delete(keys) => {
|
||||
if let Some(id) = keys.first().copied().filter(|id| *id != 0) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The styles panel's click rules: a click applies, Alt-click clears overrides, a double click opens Options, except on
|
||||
//! the character style None.
|
||||
//! the character style None; at a bare caret every attempt to apply a character style warns.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
@@ -8,7 +8,7 @@ use craft_behavior::Selection;
|
||||
use craft_text::ui::style_panel::{TextStyleAction, TextStyleKind, TextStyleRow, TextStylesPanel};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::Modifiers;
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
#[trial]
|
||||
fn a_click_applies_alt_clears_overrides_and_a_double_click_opens_options_except_on_none() {
|
||||
@@ -41,3 +41,31 @@ fn a_click_applies_alt_clears_overrides_and_a_double_click_opens_options_except_
|
||||
fixture.click(&none).click(&none).idle(4);
|
||||
assert!(!taken(&state).contains(&TextStyleAction::Options(0)), "a double click on None opens nothing");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn every_attempt_to_apply_a_character_style_at_a_bare_caret_warns_and_applies_nothing() {
|
||||
let state = Rc::new(RefCell::new((Selection::<u64>::default(), Vec::<TextStyleAction>::new(), 0usize)));
|
||||
let shared = state.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let rows = [TextStyleRow::new(0, "None"), TextStyleRow::new(1, "Emphasis")];
|
||||
let mut guard = shared.borrow_mut();
|
||||
let (selection, actions, warnings) = &mut *guard;
|
||||
let out = TextStylesPanel::new("Character Styles", TextStyleKind::Character, &rows, Bind::bound(selection))
|
||||
.target(true)
|
||||
.text_selected(false)
|
||||
.show(ui);
|
||||
actions.extend(out.action);
|
||||
*warnings += usize::from(out.status.is_some());
|
||||
});
|
||||
fixture.idle(10);
|
||||
let warnings = |state: &Rc<RefCell<(Selection<u64>, Vec<TextStyleAction>, usize)>>| std::mem::take(&mut state.borrow_mut().2);
|
||||
|
||||
let emphasis = fixture.by_label("Emphasis").expect("the Emphasis row is shown");
|
||||
fixture.click(&emphasis).idle(4);
|
||||
assert_eq!(warnings(&state), 1, "a click warns");
|
||||
fixture.advance(1.0).click(&emphasis).idle(4);
|
||||
assert_eq!(warnings(&state), 1, "a click on the row already selected warns again");
|
||||
fixture.key(Key::Enter, Modifiers::NONE).idle(4);
|
||||
assert_eq!(warnings(&state), 1, "Enter on the row warns");
|
||||
assert!(state.borrow().1.is_empty(), "nothing is applied at a bare caret");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user