Don't update active completion for editors that are not focused (cherry-pick #9904) (#9907)

gcp-cherry-pick-bot[bot] and Antonio Scandurra created

Cherry-picked Don't update active completion for editors that are not
focused (#9904)

Release Notes:

- N/A

Co-authored-by: Antonio Scandurra <me@as-cii.com>

Change summary

crates/copilot_ui/src/copilot_completion_provider.rs | 1 +
crates/editor/src/editor.rs                          | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)

Detailed changes

crates/copilot_ui/src/copilot_completion_provider.rs 🔗

@@ -764,6 +764,7 @@ mod tests {
             multibuffer
         });
         let editor = cx.add_window(|cx| Editor::for_multibuffer(multibuffer, None, cx));
+        editor.update(cx, |editor, cx| editor.focus(cx)).unwrap();
         let copilot_provider = cx.new_model(|_| CopilotCompletionProvider::new(copilot));
         editor
             .update(cx, |editor, cx| {

crates/editor/src/editor.rs 🔗

@@ -1676,7 +1676,9 @@ impl Editor {
     ) {
         self.inline_completion_provider = Some(RegisteredInlineCompletionProvider {
             _subscription: cx.observe(&provider, |this, _, cx| {
-                this.update_visible_inline_completion(cx);
+                if this.focus_handle.is_focused(cx) {
+                    this.update_visible_inline_completion(cx);
+                }
             }),
             provider: Arc::new(provider),
         });