Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(workbench): notify on _setContext only when the value changes

rokartured3b0a4f1552
diff --git a/native/crates/app/src/workbench/keyboard.rs b/native/crates/app/src/workbench/keyboard.rs
index a8462a9ec11..9c7408df930 100644
--- a/native/crates/app/src/workbench/keyboard.rs
+++ b/native/crates/app/src/workbench/keyboard.rs
@@ -689,9 +689,11 @@ impl Workbench {
Some(key) => key.to_string(),
None => return Outcome::error("setContext needs a key"),
};
- workbench.context_keys.insert(key, stringify_uris(args.next().unwrap_or(Value::Null)));
- // contextKeyService.ts fires `onDidChangeContext`: menus with `when` clauses update.
- cx.notify();
+ let value = stringify_uris(args.next().unwrap_or(Value::Null));
+ // contextKeyService.ts `setValue` fires `onDidChangeContext` only for a value not `equals` the old one: menus and views with `when` clauses update.
+ if workbench.context_keys.insert(key, value.clone()).as_ref() != Some(&value) {
+ cx.notify();
+ }
Outcome::done()
});
// contextKeyService.ts `getContextKeyInfo`: the reference's RawContextKey.all() (port/tools/ref-commands).
diff --git a/native/crates/app/src/workbench/webview_views/tests.rs b/native/crates/app/src/workbench/webview_views/tests.rs
index 75616086d61..b316bc19a0f 100644
--- a/native/crates/app/src/workbench/webview_views/tests.rs
+++ b/native/crates/app/src/workbench/webview_views/tests.rs
@@ -48,11 +48,7 @@ fn a_webview_view_shows_in_its_own_container_while_its_when_holds(cx: &mut TestA
workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_webview_views_request("$registerWebviewViewProvider", &[json!({ "id": "test.views" }), json!("test.web"), json!({})], window, cx)));
assert_eq!(focus_view(cx), Vec::<Value>::new(), "a webview view whose when is false is not shown");
- workbench.update(cx, |workbench, cx| {
- drop(workbench.context_keys.insert("test.show".into(), json!(true)));
- // As `_setContext` does: gpui-fast redraws only notified views.
- cx.notify();
- });
+ drop(workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("_setContext", vec![json!("test.show"), json!(true)], window, cx)));
draw(cx);
assert_eq!(focus_view(cx), vec![json!("test.web")]);
assert!(workbench.read_with(cx, |workbench, _| workbench.view_pane_expanded(PaneContainer::Scm, "test.web")));