gpui: Add Global marker trait (#7095)
This should prevent a class of bugs where one queries the wrong type of global, which results in oddities at runtime. Release Notes: - N/A --------- Co-authored-by: Marshall <marshall@zed.dev> Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
7bfa584eb6
commit
e6ebe7974d
59 changed files with 449 additions and 237 deletions
|
@ -28,6 +28,8 @@ regex.workspace = true
|
|||
|
||||
collections = { path = "../collections" }
|
||||
command_palette = { path = "../command_palette" }
|
||||
# HACK: We're only depending on `copilot` here for `CommandPaletteFilter`. See the attached comment on that type.
|
||||
copilot = { path = "../copilot" }
|
||||
editor = { path = "../editor" }
|
||||
gpui = { path = "../gpui" }
|
||||
language = { path = "../language" }
|
||||
|
|
|
@ -15,11 +15,12 @@ mod utils;
|
|||
mod visual;
|
||||
|
||||
use anyhow::Result;
|
||||
use collections::{CommandPaletteFilter, HashMap};
|
||||
use collections::HashMap;
|
||||
use command_palette::CommandPaletteInterceptor;
|
||||
use copilot::CommandPaletteFilter;
|
||||
use editor::{movement, Editor, EditorEvent, EditorMode};
|
||||
use gpui::{
|
||||
actions, impl_actions, Action, AppContext, EntityId, KeyContext, Subscription, View,
|
||||
actions, impl_actions, Action, AppContext, EntityId, Global, KeyContext, Subscription, View,
|
||||
ViewContext, WeakView, WindowContext,
|
||||
};
|
||||
use language::{CursorShape, Point, Selection, SelectionGoal};
|
||||
|
@ -171,9 +172,9 @@ pub fn observe_keystrokes(cx: &mut WindowContext) {
|
|||
.detach()
|
||||
}
|
||||
|
||||
/// The state pertaining to Vim mode. Stored as a global.
|
||||
/// The state pertaining to Vim mode.
|
||||
#[derive(Default)]
|
||||
pub struct Vim {
|
||||
struct Vim {
|
||||
active_editor: Option<WeakView<Editor>>,
|
||||
editor_subscription: Option<Subscription>,
|
||||
enabled: bool,
|
||||
|
@ -182,6 +183,8 @@ pub struct Vim {
|
|||
default_state: EditorState,
|
||||
}
|
||||
|
||||
impl Global for Vim {}
|
||||
|
||||
impl Vim {
|
||||
fn read(cx: &mut AppContext) -> &Self {
|
||||
cx.global::<Self>()
|
||||
|
@ -512,7 +515,9 @@ impl Vim {
|
|||
});
|
||||
|
||||
if self.enabled {
|
||||
cx.set_global::<CommandPaletteInterceptor>(Box::new(command::command_interceptor));
|
||||
cx.set_global::<CommandPaletteInterceptor>(CommandPaletteInterceptor(Box::new(
|
||||
command::command_interceptor,
|
||||
)));
|
||||
} else if cx.has_global::<CommandPaletteInterceptor>() {
|
||||
let _ = cx.remove_global::<CommandPaletteInterceptor>();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue