Fix context_stack race in KeyContextView (#29324)
cc @notpeter Before this change we used our own copy of `cx.key_context()` when matching. This led to races where the context queried could be either before (or after) the context used in dispatching. To avoid the race, gpui now passes out the context stack actually used instead. Release Notes: - Fixed a bug where the Key Context View could show the incorrect context, causing confusing results.
This commit is contained in:
parent
9d10489607
commit
c0f8e0f605
5 changed files with 52 additions and 23 deletions
|
@ -41,17 +41,17 @@ struct KeyContextView {
|
|||
|
||||
impl KeyContextView {
|
||||
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let sub1 = cx.observe_keystrokes(|this, e, window, cx| {
|
||||
let sub1 = cx.observe_keystrokes(|this, e, _, cx| {
|
||||
let mut pending = this.pending_keystrokes.take().unwrap_or_default();
|
||||
pending.push(e.keystroke.clone());
|
||||
let mut possibilities = cx.all_bindings_for_input(&pending);
|
||||
possibilities.reverse();
|
||||
this.context_stack = window.context_stack();
|
||||
this.last_keystrokes = Some(
|
||||
json!(pending.iter().map(|p| p.unparse()).join(" "))
|
||||
.to_string()
|
||||
.into(),
|
||||
);
|
||||
this.context_stack = e.context_stack.clone();
|
||||
this.last_possibilities = possibilities
|
||||
.into_iter()
|
||||
.map(|binding| {
|
||||
|
@ -89,6 +89,7 @@ impl KeyContextView {
|
|||
)
|
||||
})
|
||||
.collect();
|
||||
cx.notify();
|
||||
});
|
||||
let sub2 = cx.observe_pending_input(window, |this, window, cx| {
|
||||
this.pending_keystrokes = window
|
||||
|
@ -237,7 +238,7 @@ impl Render for KeyContextView {
|
|||
.mt_8(),
|
||||
)
|
||||
.children({
|
||||
window.context_stack().into_iter().enumerate().map(|(i, context)| {
|
||||
self.context_stack.iter().enumerate().map(|(i, context)| {
|
||||
let primary = context.primary().map(|e| e.key.clone()).unwrap_or_default();
|
||||
let secondary = context
|
||||
.secondary()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue