mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 17:55:45 +01:00
Revert "Merge pull request #3738 from dotCooCoo/fix/selectable-text-click-response"
This reverts commit205995c95c, reversing changes made to85d26f43e0.
This commit is contained in:
1 parent
b0370f2298
commit
72ddff0c18
3 files changed
+2
-78
No files matched your search
@@ -682,12 +682,6 @@ pub(crate) fn run<C: Component>(
|
||||
}
|
||||
|
||||
impl<C: Component> Cx<'_, C> {
|
||||
/// The response of a declared selection part after `paint` shows it, or `None` when the part has no widget.
|
||||
pub fn selection_response(&self, part: impl Into<PartRef>) -> Option<egui::Response> {
|
||||
let part = part.into();
|
||||
self.core.selections.contains(&part).then(|| self.core.ctx.read_response(selection_id(self.core.id, part))).flatten()
|
||||
}
|
||||
|
||||
/// Changes the text part's draft in the next pass: `Some(text)` puts `text` in as a change of the typing run (one
|
||||
/// that begins the run when none is under way), the caret at its end; `None` ends the run with the text from
|
||||
/// before it, without the run's Escape reaching the host. A combo box's keys in its open list put the active
|
||||
|
||||
@@ -107,14 +107,6 @@ impl Component for SelectableText<'_> {
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> Response {
|
||||
let mut response = cx.response.clone();
|
||||
if let Some(text) = cx.selection_response(TEXT) {
|
||||
let clicked = cx.resolved.enabled && !cx.resolved.read_only && text.clicked_by(egui::PointerButton::Primary);
|
||||
response.flags.set(egui::response::Flags::CLICKED, clicked);
|
||||
if clicked {
|
||||
response.interact_pointer_pos_or_nan = text.interact_pointer_pos_or_nan;
|
||||
}
|
||||
}
|
||||
response
|
||||
cx.response.clone()
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use craft_ui::table::{MetadataGroup, MetadataRow, MetadataTable};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use craft_ui::text::{SelectableText, TextField};
|
||||
use egui::{Event, Id, Key, Modifiers, Rect, Sense, Vec2, ViewportId};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn stop(fixture: &Fixture) -> Option<Id> {
|
||||
@@ -53,68 +53,6 @@ fn painted(fixture: &Fixture, text: &str) -> Rect {
|
||||
fixture.texts().iter().find(|painted| painted.text == text).unwrap_or_else(|| panic!("{text:?} is painted")).rect
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn selectable_text_response_reports_its_clicks_and_modifiers() {
|
||||
let clicks = Rc::new(RefCell::new(Vec::new()));
|
||||
let seen = clicks.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let response = SelectableText::new("Length", "234 pt").show(ui);
|
||||
assert_eq!(craft_ui::contract::clicked(&response), response.clicked());
|
||||
if response.clicked() {
|
||||
seen.borrow_mut().push((response.double_clicked(), craft_ui::runtime::pointer::frame(ui.ctx()).pick_mods));
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
let at = painted(&fixture, "234 pt").center();
|
||||
fixture.click_at(at);
|
||||
assert_eq!(&*clicks.borrow(), &[(false, craft_keymap::Mods::NONE)]);
|
||||
clicks.borrow_mut().clear();
|
||||
fixture.advance(1.0);
|
||||
let button = |pressed, modifiers| Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers };
|
||||
fixture.frame_through(vec![
|
||||
button(true, Modifiers::NONE),
|
||||
button(false, Modifiers::NONE),
|
||||
button(true, Modifiers::NONE),
|
||||
button(false, Modifiers::NONE),
|
||||
]);
|
||||
assert_eq!(&*clicks.borrow(), &[(false, craft_keymap::Mods::NONE), (true, craft_keymap::Mods::NONE)]);
|
||||
clicks.borrow_mut().clear();
|
||||
fixture.advance(1.0);
|
||||
fixture.frame_through(vec![button(true, Modifiers::SHIFT), button(false, Modifiers::SHIFT), Event::ModifiersChanged(Modifiers::NONE)]);
|
||||
assert_eq!(&*clicks.borrow(), &[(false, craft_keymap::Mods { shift: true, ..craft_keymap::Mods::NONE })]);
|
||||
clicks.borrow_mut().clear();
|
||||
let rect = painted(&fixture, "234 pt");
|
||||
fixture.drag_at(rect.left_center() + Vec2::new(1.0, 0.0), Vec2::new(rect.width() * 0.75, 0.0));
|
||||
assert!(clicks.borrow().is_empty());
|
||||
fixture.frame_through(vec![
|
||||
Event::PointerButton { pos: at, button: egui::PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE },
|
||||
Event::PointerButton { pos: at, button: egui::PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE },
|
||||
]);
|
||||
assert!(clicks.borrow().is_empty());
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn read_only_selectable_text_keeps_selection_without_reporting_activation() {
|
||||
for inherited in [false, true] {
|
||||
let clicked = Rc::new(Cell::new(false));
|
||||
let seen = clicked.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
craft_ui::runtime::env::with_env(
|
||||
ui,
|
||||
|scope| scope.read_only = Some(inherited),
|
||||
|ui| {
|
||||
let response = SelectableText::new("Length", "234 pt").read_only(!inherited).show(ui);
|
||||
seen.set(seen.get() || response.clicked());
|
||||
},
|
||||
);
|
||||
});
|
||||
fixture.settle();
|
||||
fixture.click_at(painted(&fixture, "234 pt").center());
|
||||
assert!(!clicked.get(), "inherited read-only: {inherited}");
|
||||
assert_eq!(copy_all(&mut fixture), ["234 pt"]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Select All then Copy in the focused text.
|
||||
fn copy_all(fixture: &mut Fixture) -> Vec<String> {
|
||||
fixture.key(Key::A, Modifiers::COMMAND);
|
||||
|
||||
Reference in new issue
Block a user