diff --git a/crates/text/src/ui/editor.rs b/crates/text/src/ui/editor.rs index 989397fbc..9cbff7484 100644 --- a/crates/text/src/ui/editor.rs +++ b/crates/text/src/ui/editor.rs @@ -411,7 +411,7 @@ impl Outcome for TextEditorOutput { /// them. Backspace and Delete by char, Alt by word, Cmd+Backspace to the line start. Cmd+A all, Cmd+C, Cmd+X and /// Cmd+V the clipboard. Enter a line break; Cmd+Enter commits; Esc commits or cancels; Cmd+. cancels; /// Cmd+T asks the host for its Character panel. In a form field ([`mode`](Self::mode)) Tab and Shift+Tab end the -/// session toward the next or previous field, and in a one-line field Enter commits. The +/// session toward the next or previous field, a press that moves focus away commits, and in a one-line field Enter commits. The /// [`TextEditorCommand`]s format. In vertical text the arrows turn with the flow, the formatting keys too: Alt+Up /// and Alt+Down track, Alt+Left and Alt+Right set the leading. A formatting key the host does not take moves the /// caret as its arrow does: a line, a word, or with Cmd to the text's start or end; Shift extends. @@ -674,6 +674,11 @@ impl Component for TextEditor<'_> { edits.session.dragging = None; edits.done.commit = true; } + if mode != EditorMode::Canvas && cx.editor_commit_requested() { + edits.end_composition(); + edits.session.dragging = None; + edits.done.commit = true; + } // Commands and the claimed keys arrive with the pass's own input: a second pass of the frame takes none, so // a commit, a cancel, a move to another field or the panel toggle is reported by one pass only. No key ends diff --git a/crates/text/tests/it/editor.rs b/crates/text/tests/it/editor.rs index ebdf8fb05..65007002a 100644 --- a/crates/text/tests/it/editor.rs +++ b/crates/text/tests/it/editor.rs @@ -381,6 +381,18 @@ fn field(mode: EditorMode, masked: bool) -> Session { editor } +#[trial] +fn a_form_editor_commits_when_a_press_focuses_another_editor() { + for mode in [EditorMode::FieldLine, EditorMode::FieldLines] { + let mut editor = session_on(Host { text: "abc".to_owned(), ..Host::default() }, None, true, mode, false); + editor.focus(); + editor.fixture.frame(vec![Event::Text("d".to_owned())]).settle(); + editor.fixture.click_at(pos2(20.0, 50.0)).settle(); + assert_eq!(*editor.ends.borrow(), [EditorEnd::Commit], "the form session ends on a press in the other editor ({mode:?})"); + assert_eq!(editor.text(), "abcd", "the committed text is kept"); + } +} + /// A one-line field ends its session on Enter (commit), Tab (next) and Shift+Tab (previous) and pastes line breaks as /// spaces; a multi-line field takes Enter as a line break and ends on Tab; while a composition is open no key ends a /// field's session; the canvas editor still types Tab as a tab character. diff --git a/crates/ui-canvas/src/canvas/mod.rs b/crates/ui-canvas/src/canvas/mod.rs index 24e73bad6..64bd6c55a 100644 --- a/crates/ui-canvas/src/canvas/mod.rs +++ b/crates/ui-canvas/src/canvas/mod.rs @@ -45,7 +45,7 @@ pub use raster_source::{PixelRect, RasterSource}; mod pasteboard; mod split; pub use pasteboard::{PageBorder, PageFrame, Pasteboard, PasteboardColor, PasteboardOutput, PasteboardStyle}; -pub use split::{SplitAt, SplitLayout, SplitPane, SplitPaneAt, SplitStyle, SplitViews, SplitViewsOutput, TabDrop, TabDropTarget}; +pub use split::{PanePress, SplitAt, SplitLayout, SplitPane, SplitPaneAt, SplitStyle, SplitViews, SplitViewsOutput, TabDrop, TabDropTarget}; pub use words::SplitWords; mod app_paint; diff --git a/crates/ui-canvas/src/canvas/split/mod.rs b/crates/ui-canvas/src/canvas/split/mod.rs index fb3210a69..4d9473daa 100644 --- a/crates/ui-canvas/src/canvas/split/mod.rs +++ b/crates/ui-canvas/src/canvas/split/mod.rs @@ -1,6 +1,7 @@ //! `SplitViews`: one canvas area shown as views of one document, or a grid of panes the caller fills (one document //! each). One view is active and is the full interactive view (tools, overlays, keys); the others show their document -//! from their own view and become active on a click. The dividers between panes move with the pointer and, when +//! from their own view and become active on a click. [`PanePress`] chooses whether that click also reaches the view. +//! The dividers between panes move with the pointer and, when //! focused, with the arrow keys. //! //! The panes are the cells [`arrange_rects`] gives for the arrangement the caller names, with the dividers moved to @@ -37,6 +38,16 @@ const PANE: PartKey = PartKey::new("pane"); /// panes, shows one pane over the whole area. pub use craft_behavior::dock::Arrangement as SplitLayout; +/// How a pointer press in an inactive pane activates it. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum PanePress { + /// The first press selects the pane; its contents receive later presses. + #[default] + Select, + /// The press selects the pane and also reaches its contents. + Interact, +} + /// Where the dividers lie, as fractions of the area counted from its start edge and its top: one entry per column line /// and per row line of the layout, in order. A list that does not fit the layout (the wrong length, not ascending, or /// outside 0–1) lays out that axis in even cells. A saved value missing a field takes that field's default lines. @@ -349,9 +360,9 @@ impl Outcome for SplitViewsOutput { /// One canvas area shown as views of one document, or a grid of panes the caller fills (one document each), in the /// panes of a [`SplitLayout`]. The active pane is the app's: it routes tools and keys there. An inactive pane is a -/// Tab stop over its view: a press, Enter or Space on it reports it in [`SplitViewsOutput::activated`] and its view -/// gets no press. With [`takes_tabs`](SplitViews::takes_tabs) a document strip tab dropped on the views is reported in -/// [`SplitViewsOutput::tab_drop`]. +/// Tab stop: a press, Enter or Space reports it in [`SplitViewsOutput::activated`]. By default the first press selects +/// the pane; [`PanePress::Interact`] also sends it to the view. With [`takes_tabs`](SplitViews::takes_tabs) a document +/// strip tab dropped on the views is reported in [`SplitViewsOutput::tab_drop`]. #[derive(crate::contract::Component, crate::contract::Props)] #[component(container, probe(SplitViews<'static, ()>))] pub struct SplitViews<'a, D: Clone + Send + Sync + 'static = ()> { @@ -361,9 +372,12 @@ pub struct SplitViews<'a, D: Clone + Send + Sync + 'static = ()> { props: ContainerProps, layout: SplitLayout, at: Bind<'a, SplitAt>, - /// The active pane: the full interactive view (0 by default). The other panes are display-only until clicked. + /// The active pane: the full interactive view (0 by default). #[prop] active: usize, + /// How a press in an inactive pane selects it. + #[prop] + pane_press: PanePress, /// The documents a tile arrangement shows, one pane each (0 by default); the n-up arrangements show their own /// number of panes. [`show_panes`](Self::show_panes) gives each of them a body. #[prop] @@ -379,15 +393,18 @@ impl<'a> SplitViews<'a> { /// active until [`active`](Self::active) says otherwise. pub fn new(label: impl Into