T21a round 2 fixes
- a field notes its selection when a key goes down, so undo of typing selects what the typing replaced - reading order skips table cells merged away, so Up and Down across blocks land on cells that show
This commit is contained in:
1 parent
f3e2c6c27f
commit
187f54253e
6 files changed
+68
-3
No files matched your search
@@ -162,14 +162,26 @@ impl BlockEditor {
|
||||
/// Records what changed as one undo step, a burst of typing as one, and tells the owner.
|
||||
pub(super) fn settle(&mut self, typing: bool, cx: &mut Context<Self>) {
|
||||
let now = self.snapshot(cx);
|
||||
let typed_from = self.typed_from.take();
|
||||
if now.blocks != self.current.blocks {
|
||||
let before = std::mem::replace(&mut self.current, now);
|
||||
let mut before = std::mem::replace(&mut self.current, now);
|
||||
if typed_from.is_some() {
|
||||
before.caret = typed_from;
|
||||
}
|
||||
self.history.record(before, typing);
|
||||
cx.emit(BlockEvent::Changed);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a key went down, before the field acts on it: the start a typing burst's undo goes back to.
|
||||
pub(crate) fn note_key(&mut self, key: u64, field: usize, cx: &Context<Self>) {
|
||||
let selection = self.blocks[self.index(key)].fields[field]
|
||||
.read(cx)
|
||||
.selection();
|
||||
self.typed_from = Some((key, field, selection));
|
||||
}
|
||||
|
||||
/// Records the document before a change to its blocks.
|
||||
pub(crate) fn before_change(&mut self, cx: &mut Context<Self>) {
|
||||
self.settle(true, cx);
|
||||
|
||||
@@ -18,7 +18,16 @@ impl BlockEditor {
|
||||
BlockKind::Toggle(false) => 1,
|
||||
_ => block.fields.len(),
|
||||
};
|
||||
(0..shown).map(move |field| (block.key, field))
|
||||
let hidden: Vec<usize> = match &block.kind {
|
||||
BlockKind::Table { columns, merged } => merged
|
||||
.iter()
|
||||
.map(|(row, column)| row * columns + column)
|
||||
.collect(),
|
||||
_ => Vec::new(),
|
||||
};
|
||||
(0..shown)
|
||||
.filter(move |field| !hidden.contains(field))
|
||||
.map(move |field| (block.key, field))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ pub struct BlockEditor {
|
||||
current: Snapshot,
|
||||
/// The field that last held focus, as block and field.
|
||||
caret: Option<(u64, usize)>,
|
||||
/// The selection a key went down on, before its field changed.
|
||||
typed_from: Option<(u64, usize, std::ops::Range<usize>)>,
|
||||
pub(crate) people: Vec<SharedString>,
|
||||
pub(crate) diagram: Option<RenderDiagram>,
|
||||
_synced: Subscription,
|
||||
@@ -95,6 +97,7 @@ impl BlockEditor {
|
||||
caret: None,
|
||||
},
|
||||
caret: None,
|
||||
typed_from: None,
|
||||
people: Vec::new(),
|
||||
diagram: None,
|
||||
_synced: synced,
|
||||
|
||||
@@ -114,6 +114,7 @@ impl BlockEditor {
|
||||
cx.stop_propagation();
|
||||
editor.on_submit(key, window, cx);
|
||||
}))
|
||||
.capture_key_down(cx.listener(move |editor, _, _, cx| editor.note_key(key, ix, cx)))
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.child(field.clone());
|
||||
let slash = move |query: &str, at: usize, caret: usize| -> (Vec<Choice>, Pick) {
|
||||
|
||||
Reference in new issue
Block a user