mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 23:49:35 +00:00
Merge remote-tracking branch 'origin/next' into fix/vc-tabs-sections
This commit is contained in:
@@ -548,8 +548,12 @@ const MAX_XATTR_TOTAL_BYTES: usize = 64 * 1024 * 1024;
|
||||
/// binding, quarantine, resource forks) to the stage. The attributes are as untrusted as the
|
||||
/// bytes, so the reads are bounded; one that cannot be read or written whole, or passes a bound,
|
||||
/// refuses the save rather than dropping the user's metadata unnoticed. Only a volume without
|
||||
/// extended attributes (`ENOTSUP`) is skipped. `com.apple.provenance` belongs to macOS, which
|
||||
/// gives the new file its own. Compression bookkeeping stays hidden (no `XATTR_SHOWCOMPRESSION`).
|
||||
/// extended attributes (`ENOTSUP`) is skipped. So is a file whose data the user may not read when
|
||||
/// its attribute names can't be listed either, as with mode 0200: its attributes are dropped, as
|
||||
/// before attributes were kept, since the user can't read them (or its bytes) at all. One whose
|
||||
/// data is denied but whose names can be listed (an ACL that denies reading) refuses the save.
|
||||
/// `com.apple.provenance` belongs to macOS, which gives the new file its own. Compression
|
||||
/// bookkeeping stays hidden (no `XATTR_SHOWCOMPRESSION`).
|
||||
#[cfg(target_os = "macos")]
|
||||
fn copy_xattrs(target: &Path, stage: &File) -> io::Result<()> {
|
||||
use rustix::fs::{Mode, OFlags, XattrFlags, fgetxattr, fgetxattr_query, flistxattr, fsetxattr, open};
|
||||
@@ -560,6 +564,7 @@ fn copy_xattrs(target: &Path, stage: &File) -> io::Result<()> {
|
||||
let source = match open(target, OFlags::RDONLY | OFlags::CLOEXEC | OFlags::NOFOLLOW | OFlags::NONBLOCK, Mode::empty()) {
|
||||
Ok(fd) => File::from(fd),
|
||||
Err(Errno::NOENT | Errno::LOOP) => return Ok(()),
|
||||
Err(Errno::ACCESS) => return unreadable_has_no_attributes(target),
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
if !source.metadata()?.is_file() {
|
||||
@@ -595,6 +600,27 @@ fn copy_xattrs(target: &Path, stage: &File) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// For a target whose data can't be opened for reading: `Ok` when the user can list no extended
|
||||
/// attribute names on it (none, only `com.apple.provenance`, none supported, or listing is denied too,
|
||||
/// as for mode 0200, whose attributes are then dropped); otherwise refuse the save, as the attributes
|
||||
/// can't be copied without opening the file. The names are read without following a link, by path.
|
||||
#[cfg(target_os = "macos")]
|
||||
fn unreadable_has_no_attributes(target: &Path) -> io::Result<()> {
|
||||
use rustix::fs::llistxattr;
|
||||
use rustix::io::Errno;
|
||||
let mut names = vec![0u8; MAX_XATTR_NAMES_BYTES];
|
||||
match llistxattr(target, names.as_mut_slice()) {
|
||||
Ok(0) | Err(Errno::NOTSUP | Errno::ACCESS | Errno::NOENT) => Ok(()),
|
||||
Ok(len) if names.get(..len).is_some_and(|names| names.split(|b| *b == 0).all(|name| name.is_empty() || name == b"com.apple.provenance")) => {
|
||||
Ok(())
|
||||
}
|
||||
Ok(_) | Err(Errno::RANGE) => {
|
||||
Err(io::Error::new(io::ErrorKind::PermissionDenied, "the file can't be read, so its extended attributes can't be copied"))
|
||||
}
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Read one attribute value of `size` bytes (already within the bounds) with `read`, then ask
|
||||
/// its size again with `query_size`. A read that does not fill `size`, or a size that changed,
|
||||
/// is refused: a growing resource fork returns the prefix that fits instead of an error.
|
||||
|
||||
@@ -99,3 +99,49 @@ fn private_staging_preserves_existing_modes_after_callback() -> io::Result<()> {
|
||||
assert_no_temp(&d.0);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Extended attribute names on `path`, read by path.
|
||||
#[cfg(target_os = "macos")]
|
||||
fn xattr_names(path: &Path) -> Vec<Vec<u8>> {
|
||||
let mut names = vec![0u8; 64 * 1024];
|
||||
let len = rustix::fs::listxattr(path, names.as_mut_slice()).unwrap_or(0);
|
||||
names.truncate(len);
|
||||
names.split(|b| *b == 0).filter(|n| !n.is_empty()).map(<[u8]>::to_vec).collect()
|
||||
}
|
||||
|
||||
/// A write-only file (mode 0200) saves: macOS lets its owner neither read its data nor list its
|
||||
/// attributes, so its attributes are dropped, as before attributes were kept.
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn a_write_only_file_saves_and_drops_the_attributes_it_cannot_read() -> io::Result<()> {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let d = TempDir::new("write_only_xattrs");
|
||||
let p = d.0.join("doc.craft");
|
||||
std::fs::write(&p, ORIGINAL)?;
|
||||
rustix::fs::setxattr(&p, "com.craft.t", b"tag", rustix::fs::XattrFlags::empty())?;
|
||||
std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o200))?;
|
||||
atomic_write(&p, b"new")?;
|
||||
std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o600))?;
|
||||
assert_eq!(std::fs::read(&p)?, b"new");
|
||||
assert!(!xattr_names(&p).iter().any(|n| n == b"com.craft.t"), "the unreadable attribute is dropped");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A file whose data an ACL denies but whose attribute names can be listed is not replaced: its
|
||||
/// attributes can't be copied without its data, and the save refuses rather than drop them.
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn an_unreadable_file_with_listable_attributes_is_not_replaced() -> io::Result<()> {
|
||||
let d = TempDir::new("acl_denied_xattrs");
|
||||
let p = d.0.join("doc.craft");
|
||||
std::fs::write(&p, ORIGINAL)?;
|
||||
rustix::fs::setxattr(&p, "com.craft.t", b"tag", rustix::fs::XattrFlags::empty())?;
|
||||
let denied = std::process::Command::new("/bin/chmod").arg("+a").arg("everyone deny read").arg(&p).status()?;
|
||||
assert!(denied.success(), "the ACL is set");
|
||||
let result = atomic_write(&p, b"new");
|
||||
let _ = std::process::Command::new("/bin/chmod").arg("-N").arg(&p).status();
|
||||
assert!(result.is_err(), "the save is refused");
|
||||
assert_eq!(std::fs::read(&p)?, ORIGINAL, "the original is unchanged");
|
||||
assert!(xattr_names(&p).iter().any(|n| n == b"com.craft.t"), "and keeps its attribute");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -389,11 +389,10 @@ fn read_system() -> Region {
|
||||
Region::from_tag(&sys_locale::get_locale().unwrap_or_default())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, unix, not(any(target_vendor = "apple", target_os = "android"))))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))]
|
||||
#[test]
|
||||
fn each_locale_category_decides_its_own_part_and_lc_all_all_of_them() {
|
||||
let env =
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! The in-window bar's own rules over the model.
|
||||
|
||||
use craft_host::target::Os;
|
||||
use craft_menu::{Item, Menu, MenuBar, MenuBarUi, Node};
|
||||
use craft_ui::contract::Tracked;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
@@ -18,6 +19,8 @@ fn a_disabled_submenu_is_greyed_and_does_not_open() {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
MenuBarUi::new(&bar).show(ui);
|
||||
});
|
||||
// The in-window bar's rules; a Mac's menus are in the system bar.
|
||||
fixture.os(Os::Linux);
|
||||
fixture.settle();
|
||||
let Some(file) = fixture.by_label("File") else { panic!("the bar shows File") };
|
||||
fixture.click(&file).settle();
|
||||
|
||||
@@ -1544,7 +1544,8 @@ impl KeyMoves {
|
||||
/// Page Up and Down a screen less a key line (a row when not continuous, and with Cmd), Home and End the first
|
||||
/// and last page, Up and Down a key line (not continuous, a turn once the row is at its edge that way), Left and
|
||||
/// Right a key line sideways while the current page or spread has more to show that way, else a turn of a page or
|
||||
/// spread; Cmd with Left or Right turns at once. Home and End with Shift or Cmd, and Page Up, Page Down, Up and
|
||||
/// spread; Cmd with Left or Right turns at once. Home and End with Shift, or with Cmd off macOS (which gives Cmd
|
||||
/// with them no move), and Page Up, Page Down, Up and
|
||||
/// Down with Shift and Cmd together, go to the first or last page; Alt, and Shift alone with the other keys,
|
||||
/// leave them to nothing.
|
||||
fn of(
|
||||
|
||||
@@ -1007,12 +1007,11 @@ fn shift_and_command_with_the_page_keys_and_arrows_go_to_the_ends() {
|
||||
);
|
||||
focus_canvas(&mut fixture);
|
||||
let keys = [(Key::PageDown, both, 4), (Key::PageUp, both, 0), (Key::ArrowDown, both, 4), (Key::ArrowUp, both, 0)];
|
||||
let ends = [
|
||||
(Key::End, Modifiers::SHIFT, 4),
|
||||
(Key::Home, Modifiers::SHIFT, 0),
|
||||
(Key::End, Modifiers::COMMAND, 4),
|
||||
(Key::Home, Modifiers::COMMAND, 0),
|
||||
];
|
||||
// Off macOS Ctrl+End and Ctrl+Home go to the ends too; macOS gives Cmd with Home and End no move.
|
||||
let mut ends = vec![(Key::End, Modifiers::SHIFT, 4), (Key::Home, Modifiers::SHIFT, 0)];
|
||||
if !cfg!(target_os = "macos") {
|
||||
ends.extend([(Key::End, Modifiers::COMMAND, 4), (Key::Home, Modifiers::COMMAND, 0)]);
|
||||
}
|
||||
for (key, mods, want) in keys.into_iter().chain(ends) {
|
||||
fixture.key(key, mods);
|
||||
fixture.idle(2);
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
//!
|
||||
//! On Windows a file created in a folder inherits the folder's access list, and folders such as
|
||||
//! a new folder at a drive root, `C:\Users\Public` or `C:\ProgramData` let every signed-in user
|
||||
//! read what is created in them. [`restrict_to_owner`] replaces the whole list with the current
|
||||
//! user and SYSTEM only, makes that user the owner, and checks the result. [`create_private_dir`]
|
||||
//! read what is created in them. `restrict_to_owner` replaces the whole list with the current
|
||||
//! user and SYSTEM only, makes that user the owner, and checks the result. `create_private_dir`
|
||||
//! does the same for a new folder whose list the files created in it inherit, so a file can be
|
||||
//! private from the moment it exists. [`read_with_sddl`] reads a file and its security descriptor
|
||||
//! private from the moment it exists. `read_with_sddl` reads a file and its security descriptor
|
||||
//! through one handle. [`foreign_access`] reads the descriptor in SDDL form, which names accounts
|
||||
//! by SID and so reads the same in every Windows language, and says why another user could have
|
||||
//! written or could read the file. They run the tools Windows ships rather than calling the
|
||||
//! security API directly, which would need `unsafe`.
|
||||
|
||||
/// Why the file whose security descriptor is `sddl` (`O:` owner and `D:` access list, in SDDL or
|
||||
/// as [`read_with_sddl`] writes it) can't be trusted as user `me`'s own: it is owned by someone else, it has no
|
||||
/// as `read_with_sddl` writes it) can't be trusted as user `me`'s own: it is owned by someone else, it has no
|
||||
/// access list (everyone may use it), or it lets an account other than `me` or SYSTEM use it.
|
||||
/// Accounts are compared by SID; `None` means it is `me`'s alone.
|
||||
///
|
||||
/// Stricter than OpenSSH's rule for private keys, which also lets Administrators in: an entry for
|
||||
/// the Administrators group would let another administrator read the token without taking the
|
||||
/// file over. [`restrict_to_owner`] never grants it, so the app's own file always passes; a file
|
||||
/// file over. `restrict_to_owner` never grants it, so the app's own file always passes; a file
|
||||
/// that inherited it from a user's folder is refused.
|
||||
pub fn foreign_access(sddl: &str, me: &str) -> Option<String> {
|
||||
let me = me.trim();
|
||||
|
||||
@@ -376,6 +376,11 @@ impl EditorMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// `text` on one line: each line ending (`\r\n`, `\r` or `\n`) becomes one space.
|
||||
fn one_line(text: &str) -> String {
|
||||
text.replace("\r\n", " ").replace(['\r', '\n'], " ")
|
||||
}
|
||||
|
||||
/// What the editor did this pass.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
@@ -572,6 +577,80 @@ fn show_i_beam(cx: &mut Cx<'_, TextEditor<'_>>, phase: &PressPhase, vertical: bo
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies one pass's editor steps to `edits` in order: typing, the marked text, moves, deletes, selections, the edit
|
||||
/// commands and the commands keys fired. Returns the text a Copy or Cut put on the clipboard, and whether a command
|
||||
/// asked for the character panel.
|
||||
fn apply_steps(
|
||||
edits: &mut Edits<'_>,
|
||||
steps: Vec<EditorStep<TextEditorCommand>>,
|
||||
mode: EditorMode,
|
||||
masked: bool,
|
||||
pasted: Option<&str>,
|
||||
fallback: Rect,
|
||||
) -> (Option<String>, bool) {
|
||||
let mut copied: Option<String> = None;
|
||||
let mut ending: Option<Range<usize>> = None;
|
||||
let mut character_panel = false;
|
||||
for step in steps {
|
||||
// A commit or cancel ends the session; an input method's committed text still lands.
|
||||
if (edits.done.commit || edits.done.cancel) && ending.is_none() {
|
||||
break;
|
||||
}
|
||||
let input = match step {
|
||||
EditorStep::Input(input) => input,
|
||||
EditorStep::Command(command, _) => {
|
||||
edits.command(command, &mut character_panel);
|
||||
continue;
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
if let Some(range) = ending.take() {
|
||||
if let EditorInput::Text(text) = &input {
|
||||
edits.commit_marked(range, text);
|
||||
continue;
|
||||
}
|
||||
edits.drop_marked(range);
|
||||
}
|
||||
match input {
|
||||
EditorInput::Preedit { text, cursor, .. } => {
|
||||
let active = cursor.map(|bytes| byte_range_to_chars(&text, bytes));
|
||||
ending = edits.preedit(&text, active);
|
||||
}
|
||||
EditorInput::ImeCommit => ending = edits.session.preedit.take(),
|
||||
EditorInput::Text(text) => edits.done.changed |= edits.insert_typed(&text),
|
||||
EditorInput::Newline { .. } if edits.session.preedit.is_none() && mode.multiline() => {
|
||||
edits.done.changed |= edits.insert_text("\n", EditKind::Typed);
|
||||
}
|
||||
EditorInput::Tab if mode.takes_tab() => edits.done.changed |= edits.insert_text("\t", EditKind::Typed),
|
||||
EditorInput::Move(step, mods) => edits.motion(step, mods),
|
||||
EditorInput::Delete { forward, by, .. } => edits.done.changed |= edits.delete(forward, by),
|
||||
EditorInput::DeleteSurrounding { before, after, unit, .. } => edits.done.changed |= edits.delete_around(before, after, unit),
|
||||
EditorInput::Select { anchor, focus, .. } => {
|
||||
let lines = lines_of(&mut *edits.host, fallback);
|
||||
edits.end_composition();
|
||||
edits.selection = TextSelection { anchor: char_at(&lines, anchor), caret: char_at(&lines, focus) };
|
||||
}
|
||||
EditorInput::Edit(EditCommand::SelectAll) => edits.select_all(),
|
||||
EditorInput::Edit(EditCommand::Copy) if !masked => copied = edits.selected_text(),
|
||||
EditorInput::Edit(EditCommand::Cut) if !masked => {
|
||||
copied = edits.selected_text();
|
||||
edits.done.changed |= edits.delete_selection();
|
||||
}
|
||||
EditorInput::Edit(EditCommand::Paste) => {
|
||||
if let Some(text) = pasted {
|
||||
let text = if mode.multiline() { text.to_string() } else { one_line(text) };
|
||||
edits.done.changed |= edits.insert_text(&text, EditKind::Pasted);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if let Some(range) = ending {
|
||||
edits.drop_marked(range);
|
||||
}
|
||||
(copied, character_panel)
|
||||
}
|
||||
|
||||
/// The clipboard's text when the pass's input asks to paste and the clipboard has it ready.
|
||||
fn pasted_text(cx: &mut Cx<'_, TextEditor<'_>>, steps: &[EditorStep<TextEditorCommand>]) -> Option<std::sync::Arc<str>> {
|
||||
if !steps.iter().any(|step| matches!(step, EditorStep::Input(EditorInput::Edit(EditCommand::Paste)))) {
|
||||
@@ -636,7 +715,6 @@ impl Component for TextEditor<'_> {
|
||||
let now = cx.now();
|
||||
let pasted = pasted_text(cx, &steps);
|
||||
let (mode, masked) = (self.mode, self.masked);
|
||||
let mut copied: Option<String> = None;
|
||||
let mut session = std::mem::take(cx.memory::<Session>());
|
||||
let mut edits = Edits {
|
||||
host: &mut *self.host,
|
||||
@@ -652,64 +730,7 @@ impl Component for TextEditor<'_> {
|
||||
edits.reconcile();
|
||||
let fallback = space.doc_rect(cx.rect);
|
||||
|
||||
let mut ending: Option<Range<usize>> = None;
|
||||
let mut character_panel = false;
|
||||
for step in steps {
|
||||
// A commit or cancel ends the session; an input method's committed text still lands.
|
||||
if (edits.done.commit || edits.done.cancel) && ending.is_none() {
|
||||
break;
|
||||
}
|
||||
let input = match step {
|
||||
EditorStep::Input(input) => input,
|
||||
EditorStep::Command(command, _) => {
|
||||
edits.command(command, &mut character_panel);
|
||||
continue;
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
if let Some(range) = ending.take() {
|
||||
if let EditorInput::Text(text) = &input {
|
||||
edits.commit_marked(range, text);
|
||||
continue;
|
||||
}
|
||||
edits.drop_marked(range);
|
||||
}
|
||||
match input {
|
||||
EditorInput::Preedit { text, cursor, .. } => {
|
||||
let active = cursor.map(|bytes| byte_range_to_chars(&text, bytes));
|
||||
ending = edits.preedit(&text, active);
|
||||
}
|
||||
EditorInput::ImeCommit => ending = edits.session.preedit.take(),
|
||||
EditorInput::Text(text) => edits.done.changed |= edits.insert_typed(&text),
|
||||
EditorInput::Newline { .. } if edits.session.preedit.is_none() && mode.multiline() => {
|
||||
edits.done.changed |= edits.insert_text("\n", EditKind::Typed);
|
||||
}
|
||||
EditorInput::Tab if mode.takes_tab() => edits.done.changed |= edits.insert_text("\t", EditKind::Typed),
|
||||
EditorInput::Move(step, mods) => edits.motion(step, mods),
|
||||
EditorInput::Delete { forward, by, .. } => edits.done.changed |= edits.delete(forward, by),
|
||||
EditorInput::DeleteSurrounding { before, after, unit, .. } => edits.done.changed |= edits.delete_around(before, after, unit),
|
||||
EditorInput::Select { anchor, focus, .. } => {
|
||||
let lines = lines_of(&mut *edits.host, fallback);
|
||||
edits.end_composition();
|
||||
edits.selection = TextSelection { anchor: char_at(&lines, anchor), caret: char_at(&lines, focus) };
|
||||
}
|
||||
EditorInput::Edit(EditCommand::SelectAll) => edits.select_all(),
|
||||
EditorInput::Edit(EditCommand::Copy) if !masked => copied = edits.selected_text(),
|
||||
EditorInput::Edit(EditCommand::Cut) if !masked => {
|
||||
copied = edits.selected_text();
|
||||
edits.done.changed |= edits.delete_selection();
|
||||
}
|
||||
EditorInput::Edit(EditCommand::Paste) => {
|
||||
if let Some(text) = &pasted {
|
||||
edits.done.changed |= edits.insert_text(text, EditKind::Pasted);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if let Some(range) = ending {
|
||||
edits.drop_marked(range);
|
||||
}
|
||||
let (copied, character_panel) = apply_steps(&mut edits, steps, mode, masked, pasted.as_deref(), fallback);
|
||||
// A press is the pass's last pointer event (H0), so the pass's editor input came before it.
|
||||
match press.phase {
|
||||
PressPhase::Down { start, .. } if start.button == craft_behavior::PointerButton::Primary => {
|
||||
|
||||
@@ -451,6 +451,7 @@ fn a_quick_drag_in_one_frame_starts_at_the_press() {
|
||||
assert_eq!((events.first(), events.last()), (Some(&"begin"), Some(&"commit")), "{events:?}");
|
||||
}
|
||||
|
||||
/// Control is pressed once the resize has started: on macOS a press with Control held is a secondary click.
|
||||
#[trial]
|
||||
fn the_control_key_held_during_a_resize_turns_snapping_off() {
|
||||
for (held, right) in [(Modifiers::NONE, 310.0), (Modifiers::CTRL, 307.0)] {
|
||||
@@ -459,7 +460,13 @@ fn the_control_key_held_during_a_resize_turns_snapping_off() {
|
||||
s.snap_x = Some(310.0);
|
||||
s
|
||||
});
|
||||
rig.drag(rig.at(300.0, 220.0), rig.at(307.0, 220.0), held);
|
||||
let (from, to) = (rig.at(300.0, 220.0), rig.at(307.0, 220.0));
|
||||
rig.press(from);
|
||||
rig.frames.hold(held);
|
||||
rig.move_to(from.lerp(to, 0.5));
|
||||
rig.move_to(to);
|
||||
rig.release(to);
|
||||
rig.frames.hold(Modifiers::NONE);
|
||||
assert!((rig.rect().x1 - right).abs() < 1e-6, "{held:?}: {:?}", rig.rect());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +260,12 @@ struct Session {
|
||||
dropped: Option<u64>,
|
||||
/// A file drop has arrived but no pointer position is available yet.
|
||||
waiting_for_pointer: bool,
|
||||
/// Where the OS dropped the files: the pass that takes a drop after the frame of its arrival places it there, not
|
||||
/// at a pointer that has moved on (files hovering again for a drag of their own).
|
||||
dropped_at: Option<Pos2>,
|
||||
/// Files the OS holds over the window in the pass that takes this session's drop: a drag of their own, which
|
||||
/// starts when the drop ends this session (`end_pass`).
|
||||
hovering_next: Vec<OsFile>,
|
||||
/// The root frame the session started in, the only one in which [`amend`] changes its payload.
|
||||
began: u64,
|
||||
}
|
||||
@@ -364,6 +370,8 @@ pub fn start(
|
||||
os: false,
|
||||
dropped: None,
|
||||
waiting_for_pointer: false,
|
||||
dropped_at: None,
|
||||
hovering_next: Vec::new(),
|
||||
began,
|
||||
});
|
||||
board.ended = None;
|
||||
@@ -489,8 +497,7 @@ fn os_files(ctx: &Context) {
|
||||
let hovering = !seen.hovered.is_empty();
|
||||
// A session whose window closed has no pass left to end it.
|
||||
let closed = source_viewport(ctx).is_some_and(|window| !pass::live_viewports(ctx).contains(&window));
|
||||
let host = WindowHost::of(ctx);
|
||||
let position = if host.desktop_pointer().is_some() { host.pointer_in(viewport) } else { pointer::frame_raw(ctx).pos };
|
||||
let position = os_files_pointer(ctx, viewport, pointer::frame_raw(ctx).pos);
|
||||
let positioned = position.is_some();
|
||||
// A window target can take the drop immediately only if the pointer has not moved since resolution.
|
||||
let window_winner = PerViewport::<Targets>::with(ctx, viewport, |targets| targets.winner_window && targets.pointer == position);
|
||||
@@ -501,23 +508,11 @@ fn os_files(ctx: &Context) {
|
||||
if has_drop {
|
||||
repaint = true;
|
||||
}
|
||||
board.session = Some(Session {
|
||||
source: Id::NULL.with("craft_ui::os_files"),
|
||||
moving: Moving::default(),
|
||||
viewport,
|
||||
button: PointerButton::Primary,
|
||||
payload: Arc::new(OsFiles { files: if has_drop { seen.dropped } else { seen.hovered } }),
|
||||
also: Vec::new(),
|
||||
preview: DragPreview::None,
|
||||
env: None,
|
||||
mark: None,
|
||||
released: None,
|
||||
taken: false,
|
||||
os: true,
|
||||
dropped: (has_drop && positioned).then_some(frame.saturating_add(1)),
|
||||
waiting_for_pointer: has_drop && !positioned,
|
||||
began: frame,
|
||||
});
|
||||
let mut session = os_session(if has_drop { seen.dropped } else { seen.hovered }, viewport, frame);
|
||||
session.dropped = (has_drop && positioned).then_some(frame.saturating_add(1));
|
||||
session.dropped_at = position.filter(|_| has_drop);
|
||||
session.waiting_for_pointer = has_drop && !positioned;
|
||||
board.session = Some(session);
|
||||
board.ended = None;
|
||||
board.started += 1;
|
||||
}
|
||||
@@ -527,6 +522,7 @@ fn os_files(ctx: &Context) {
|
||||
let files = seen.dropped.into_iter().map(|file| with_hovered_type(file, hovered)).collect();
|
||||
session.payload = Arc::new(OsFiles { files });
|
||||
session.viewport = viewport;
|
||||
session.dropped_at = position;
|
||||
if window_winner {
|
||||
session.dropped = Some(frame);
|
||||
} else if positioned {
|
||||
@@ -540,9 +536,13 @@ fn os_files(ctx: &Context) {
|
||||
// Targets register this pass and take the drop in the next, after their winner is resolved.
|
||||
session.waiting_for_pointer = false;
|
||||
session.dropped = Some(frame.saturating_add(1));
|
||||
session.dropped_at = position;
|
||||
repaint = true;
|
||||
} else if hovering {
|
||||
session.viewport = viewport;
|
||||
if session.dropped == Some(frame) {
|
||||
session.hovering_next = seen.hovered;
|
||||
}
|
||||
} else if (session.viewport == viewport || closed)
|
||||
&& !seen.reading
|
||||
&& !session.waiting_for_pointer
|
||||
@@ -560,6 +560,29 @@ fn os_files(ctx: &Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/// A session of `files` the OS holds over `viewport`, started in root frame `frame`.
|
||||
fn os_session(files: Vec<OsFile>, viewport: ViewportId, frame: u64) -> Session {
|
||||
Session {
|
||||
source: Id::NULL.with("craft_ui::os_files"),
|
||||
moving: Moving::default(),
|
||||
viewport,
|
||||
button: PointerButton::Primary,
|
||||
payload: Arc::new(OsFiles { files }),
|
||||
also: Vec::new(),
|
||||
preview: DragPreview::None,
|
||||
env: None,
|
||||
mark: None,
|
||||
released: None,
|
||||
taken: false,
|
||||
os: true,
|
||||
dropped: None,
|
||||
waiting_for_pointer: false,
|
||||
dropped_at: None,
|
||||
hovering_next: Vec::new(),
|
||||
began: frame,
|
||||
}
|
||||
}
|
||||
|
||||
/// `file` with the media type the OS gave the hovered file at the same path, which egui does not repeat on a drop.
|
||||
fn with_hovered_type(mut file: OsFile, hovered: Option<&OsFiles>) -> OsFile {
|
||||
let held = hovered.and_then(|hovered| hovered.files.iter().find(|held| held.path.is_some() && held.path == file.path));
|
||||
@@ -588,12 +611,22 @@ pub fn cross_window_pointer(ctx: &Context, viewport: ViewportId) -> Option<Pos2>
|
||||
}
|
||||
|
||||
/// The pointer of the running session in screen space, whatever its payload: the pointer `dragging_of` pairs with a
|
||||
/// payload, where the button went up in the pass of its release (`PointerFrame::pick_pos`). `None` without a session or
|
||||
/// a pointer.
|
||||
/// payload, where the button went up in the pass of its release (`PointerFrame::pick_pos`); for an OS drop, where the
|
||||
/// files were dropped in the pass that takes it. `None` without a session or a pointer.
|
||||
pub(crate) fn session_pointer(ctx: &Context) -> Option<Pos2> {
|
||||
let os = board(ctx, |board| board.session.as_ref().map(|session| session.os))?;
|
||||
let host = WindowHost::of(ctx);
|
||||
if os && host.desktop_pointer().is_some() { host.pointer_in(pass::current_viewport(ctx)) } else { pointer::frame_raw(ctx).pick_pos }
|
||||
let frame = pass::root_frame_nr(ctx);
|
||||
let (os, dropped_at) =
|
||||
board(ctx, |board| board.session.as_ref().map(|session| (session.os, session.dropped_at.filter(|_| session.dropped == Some(frame)))))?;
|
||||
let own = pointer::frame_raw(ctx).pick_pos;
|
||||
if os { dropped_at.or_else(|| os_files_pointer(ctx, pass::current_viewport(ctx), own)) } else { own }
|
||||
}
|
||||
|
||||
/// The pointer of OS files over `viewport`: the system pointer where the platform tells one, since the OS sends the
|
||||
/// window no pointer events while it drags files over it; else `own`, the pass's own pointer. A drag's noted source
|
||||
/// pointer (`windows::note_source_pointer`) is from the pass before, for the other windows, so it never stands in for
|
||||
/// the pass's own.
|
||||
fn os_files_pointer(ctx: &Context, viewport: ViewportId, own: Option<Pos2>) -> Option<Pos2> {
|
||||
if windows::system_pointer(ctx).is_some() { WindowHost::of(ctx).pointer_in(viewport) } else { own }
|
||||
}
|
||||
|
||||
/// The running session's payload whose type is `payload` and the pointer in screen space. For files the OS drags, the
|
||||
@@ -799,8 +832,7 @@ pub(crate) fn ended<P: 'static>(ctx: &Context, source: Id) -> Option<DropOperati
|
||||
/// window holds the drop, it waits there for one more frame so that window's pass takes it.
|
||||
pub(crate) fn end_pass(ctx: &Context) {
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
let host = WindowHost::of(ctx);
|
||||
let position = if host.desktop_pointer().is_some() { host.pointer_in(viewport) } else { pointer::frame_raw(ctx).pos };
|
||||
let position = os_files_pointer(ctx, viewport, pointer::frame_raw(ctx).pos);
|
||||
// A modal holds input: targets on layers below it, and on the window, never accept, except OS files on a target
|
||||
// that takes them there.
|
||||
let os = carries_os_files(ctx);
|
||||
@@ -851,7 +883,9 @@ pub(crate) fn end_pass(ctx: &Context) {
|
||||
let expired = session.released.is_some_and(|released| frame > released + 1);
|
||||
let ended_here = is_source && !held && session.released.is_none();
|
||||
if expired || (ended_here && !foreign_target) {
|
||||
board.session = None;
|
||||
let next = std::mem::take(&mut session.hovering_next);
|
||||
board.session = (!next.is_empty()).then(|| os_session(next, viewport, frame));
|
||||
board.started += u64::from(board.session.is_some());
|
||||
} else if ended_here {
|
||||
session.released = Some(frame);
|
||||
}
|
||||
|
||||
@@ -541,12 +541,17 @@ enum PressUse {
|
||||
|
||||
/// The chords the focused component of `record` claims: its stop's, the state-dependent ones (`keys::claim`) of the
|
||||
/// component, its arena root and its menu level, and a bare End where it declares `EndKey::EndMode`. With nothing
|
||||
/// focused and no modal layer open, the window's document canvas's state-dependent claims hold instead.
|
||||
/// focused and no modal layer open, the window's document canvas's state-dependent claims hold instead, except Tab and
|
||||
/// Shift+Tab.
|
||||
pub(super) fn focused_claims(record: &focus::FocusedRecord, stage: &Stage) -> Vec<Chord> {
|
||||
let mut claims = record.claims.clone();
|
||||
let canvas = record.canvas.filter(|_| !record.foreign);
|
||||
let holds = |owner: Id| [record.focused, record.root, record.menu, record.menu_bar, canvas].contains(&Some(owner));
|
||||
claims.extend(stage.claims.iter().filter(|(owner, _)| holds(*owner)).map(|(_, chord)| *chord));
|
||||
let holds = |owner: Id| [record.focused, record.root, record.menu, record.menu_bar].contains(&Some(owner));
|
||||
// The unfocused canvas's tool never takes Tab or Shift+Tab: with nothing focused they move focus into the window,
|
||||
// so a tool that claims the plain keys cannot trap keyboard navigation.
|
||||
let canvas_holds =
|
||||
|owner: Id, chord: &Chord| Some(owner) == canvas && !(chord.key == Key::Tab && (chord.mods == Mods::NONE || chord.mods == Mods::SHIFT));
|
||||
claims.extend(stage.claims.iter().filter(|(owner, chord)| holds(*owner) || canvas_holds(*owner, chord)).map(|(_, chord)| *chord));
|
||||
// A bare End belongs to a stop that declares `EndKey::EndMode`: it reads the key as a claimed chord and toggles its
|
||||
// mode, so no collection navigation or scroll owner takes it as a move to the end.
|
||||
if record.keys.is_some_and(|keys| keys.end == EndKey::EndMode) {
|
||||
|
||||
@@ -137,13 +137,15 @@ fn rows_from_another_list_drop_into_a_gap_only_where_a_kind_takes_them() {
|
||||
}
|
||||
|
||||
/// A list's copy keys decide which held key makes its own row drag a copy, and the pointer over it shows the copy
|
||||
/// while they are held: off macOS Ctrl for the platform's keys, Alt for Alt; the other key moves.
|
||||
/// while they are held: the platform's keys copy with Ctrl off macOS and Option on it, Alt copies with Alt; the other
|
||||
/// key moves.
|
||||
#[trial]
|
||||
fn a_lists_copy_keys_pick_the_key_that_copies_its_rows() {
|
||||
use craft_behavior::{CopyKeys, Cursor, CursorIcon};
|
||||
use egui::Modifiers;
|
||||
let ctrl = Modifiers::CTRL | Modifiers::COMMAND;
|
||||
for (keys, copies, moves) in [(CopyKeys::Platform, ctrl, Modifiers::ALT), (CopyKeys::Alt, Modifiers::ALT, ctrl)] {
|
||||
let platform = if cfg!(target_os = "macos") { (Modifiers::ALT, ctrl) } else { (ctrl, Modifiers::ALT) };
|
||||
for (keys, copies, moves) in [(CopyKeys::Platform, platform.0, platform.1), (CopyKeys::Alt, Modifiers::ALT, ctrl)] {
|
||||
for (held, copy) in [(copies, true), (moves, false)] {
|
||||
let words = Words::flat(&["a", "b", "c", "d"]);
|
||||
let run = Run::default();
|
||||
|
||||
@@ -196,8 +196,8 @@ fn a_recent_row_names_its_full_path_and_reveals_remove_on_hover_or_focus() {
|
||||
assert!(log.borrow().contains(&StartAction::ClearRecent), "Clear reports ClearRecent: {:?}", log.borrow());
|
||||
}
|
||||
|
||||
/// A recent file's menu offers Show in Folder exactly where the platform can reveal a file, and the menu key and
|
||||
/// Shift+F10 open it from the focused card. The menu is told by "Clear Recent Files", which only the menu has: the
|
||||
/// A recent file's menu offers Show in Folder exactly where the platform can reveal a file, and the menu key (off
|
||||
/// macOS, which has none) and Shift+F10 open it from the focused card. The menu is told by "Clear Recent Files", which only the menu has: the
|
||||
/// card's hover action carries "Remove from Recent" too.
|
||||
#[trial]
|
||||
fn the_recent_menu_offers_show_in_folder_where_the_platform_can_reveal() {
|
||||
@@ -213,7 +213,9 @@ fn the_recent_menu_offers_show_in_folder_where_the_platform_can_reveal() {
|
||||
assert!(fixture.by_label(MENU_ONLY).is_some(), "a right click on a recent file opens its menu");
|
||||
assert_eq!(fixture.by_label("Show in Folder").is_some(), craft_platform::open::CAN_REVEAL);
|
||||
|
||||
for (key, modifiers) in [(Key::Menu, Modifiers::NONE), (Key::F10, Modifiers::SHIFT)] {
|
||||
let keys: &[(Key, Modifiers)] =
|
||||
if cfg!(target_os = "macos") { &[(Key::F10, Modifiers::SHIFT)] } else { &[(Key::Menu, Modifiers::NONE), (Key::F10, Modifiers::SHIFT)] };
|
||||
for &(key, modifiers) in keys {
|
||||
fixture.key(Key::Escape, Modifiers::NONE).idle(3);
|
||||
assert!(fixture.by_label(MENU_ONLY).is_none(), "Escape closes the menu before {key:?}");
|
||||
let card = fixture.by_label("Poster.psd").expect("the card shows");
|
||||
|
||||
@@ -236,7 +236,7 @@ Grouped by gallery level, then shape, then name.
|
||||
| `Watermark` | Pattern | `craft_ui_patterns::patterns::form_dialogs::watermark` | The watermark rows of an export dialog: Style (Text, Graphic), the text field or the image path with Choose…, Orientation, Position as the 3 by 3 reference point, Rotation, Size, Opacity, Inset X and Y, and Shadow |
|
||||
| `WindowMenuRows` | Pattern | `craft_ui_panels::docking::window_menu` | One check row per panel in the order the app gives, for a Window menu |
|
||||
| `WorkspaceSwitcher` | Pattern | `craft_ui_patterns::patterns::dock::switcher` | The switcher at the end of an options bar: a small select showing the current workspace's name |
|
||||
| `ZoomField` | Pattern | `craft_ui_widgets::text::zoom_field` | A zoom field: a `NumberField` over the view's zoom in percent on its [`ZoomScale`] (device pixels unless set), with the zoom codec and the zoom ladder's range |
|
||||
| `ZoomField` | Pattern | `craft_ui_widgets::text::zoom_field` | A zoom field: a `NumberField` over the view's zoom in percent on its [`ZoomScale`] (device pixels unless set), with the zoom codec and the zoom scheme's range |
|
||||
| `RecoveryDialog` | Dialog | `craft_ui_panels::dialog::recovery` | Recover Unsaved Work, one document at a time: a prompt saying when the document was autosaved, with Discard and Recover (the accepting answer) |
|
||||
|
||||
### Shells
|
||||
@@ -273,7 +273,7 @@ Grouped by gallery level, then shape, then name.
|
||||
| `craft_behavior::eviction` | When a component's remembered state is due for eviction |
|
||||
| `craft_behavior::fit` | The fit rules: which tabs, bar items or titles stay in a strip and which go to an overflow menu |
|
||||
| `craft_behavior::flow` | `Insets`, `Flow` and `Axis`: start and end geometry resolved once for the layout direction |
|
||||
| `craft_behavior::focus` | Pure focus rules (spec 9.3, 9.4, 8.3): key ownership, focus after removal, the Escape order and the focus-on-press kinds |
|
||||
| `craft_behavior::focus` | Pure focus rules (spec 9.3, 9.4, 8.3): key ownership, the Escape order and the focus-on-press kinds |
|
||||
| `craft_behavior::frame_step` | The step of one pass of motion: a Hand glide, a held Zoom press and an autoscroll integrate over it |
|
||||
| `craft_behavior::grid` | The `Grid` cursor: columns resolved from last pass's measurements, and the cell each child takes |
|
||||
| `craft_behavior::hit` | Hit shapes, their priority and the arena's resolve rule (8.3) |
|
||||
|
||||
Reference in New Issue
Block a user