Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -8,8 +8,7 @@ use crate::{
|
|||
Vim,
|
||||
};
|
||||
use editor::Editor;
|
||||
use gpui::{actions, Action, ViewContext, WindowContext};
|
||||
use util::ResultExt;
|
||||
use gpui::{actions, Action, App, Context, Window};
|
||||
use workspace::Workspace;
|
||||
|
||||
actions!(vim, [Repeat, EndRepeat, ToggleRecord, ReplayLastRecording]);
|
||||
|
@ -45,28 +44,30 @@ fn repeatable_insert(action: &ReplayableAction) -> Option<Box<dyn Action>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
|
||||
Vim::action(editor, cx, |vim, _: &EndRepeat, cx| {
|
||||
pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
|
||||
Vim::action(editor, cx, |vim, _: &EndRepeat, window, cx| {
|
||||
Vim::globals(cx).dot_replaying = false;
|
||||
vim.switch_mode(Mode::Normal, false, cx)
|
||||
vim.switch_mode(Mode::Normal, false, window, cx)
|
||||
});
|
||||
|
||||
Vim::action(editor, cx, |vim, _: &Repeat, cx| vim.repeat(false, cx));
|
||||
Vim::action(editor, cx, |vim, _: &Repeat, window, cx| {
|
||||
vim.repeat(false, window, cx)
|
||||
});
|
||||
|
||||
Vim::action(editor, cx, |vim, _: &ToggleRecord, cx| {
|
||||
Vim::action(editor, cx, |vim, _: &ToggleRecord, window, cx| {
|
||||
let globals = Vim::globals(cx);
|
||||
if let Some(char) = globals.recording_register.take() {
|
||||
globals.last_recorded_register = Some(char)
|
||||
} else {
|
||||
vim.push_operator(Operator::RecordRegister, cx);
|
||||
vim.push_operator(Operator::RecordRegister, window, cx);
|
||||
}
|
||||
});
|
||||
|
||||
Vim::action(editor, cx, |vim, _: &ReplayLastRecording, cx| {
|
||||
Vim::action(editor, cx, |vim, _: &ReplayLastRecording, window, cx| {
|
||||
let Some(register) = Vim::globals(cx).last_recorded_register else {
|
||||
return;
|
||||
};
|
||||
vim.replay_register(register, cx)
|
||||
vim.replay_register(register, window, cx)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -88,7 +89,7 @@ impl Replayer {
|
|||
})))
|
||||
}
|
||||
|
||||
pub fn replay(&mut self, actions: Vec<ReplayableAction>, cx: &mut WindowContext) {
|
||||
pub fn replay(&mut self, actions: Vec<ReplayableAction>, window: &mut Window, cx: &mut App) {
|
||||
let mut lock = self.0.borrow_mut();
|
||||
let range = lock.ix..lock.ix;
|
||||
lock.actions.splice(range, actions);
|
||||
|
@ -97,14 +98,14 @@ impl Replayer {
|
|||
}
|
||||
lock.running = true;
|
||||
let this = self.clone();
|
||||
cx.defer(move |cx| this.next(cx))
|
||||
window.defer(cx, move |window, cx| this.next(window, cx))
|
||||
}
|
||||
|
||||
pub fn stop(self) {
|
||||
self.0.borrow_mut().actions.clear()
|
||||
}
|
||||
|
||||
pub fn next(self, cx: &mut WindowContext) {
|
||||
pub fn next(self, window: &mut Window, cx: &mut App) {
|
||||
let mut lock = self.0.borrow_mut();
|
||||
let action = if lock.ix < 10000 {
|
||||
lock.actions.get(lock.ix).cloned()
|
||||
|
@ -121,7 +122,7 @@ impl Replayer {
|
|||
match action {
|
||||
ReplayableAction::Action(action) => {
|
||||
if should_replay(&*action) {
|
||||
cx.dispatch_action(action.boxed_clone());
|
||||
window.dispatch_action(action.boxed_clone(), cx);
|
||||
cx.defer(move |cx| Vim::globals(cx).observe_action(action.boxed_clone()));
|
||||
}
|
||||
}
|
||||
|
@ -129,41 +130,47 @@ impl Replayer {
|
|||
text,
|
||||
utf16_range_to_replace,
|
||||
} => {
|
||||
cx.window_handle()
|
||||
.update(cx, |handle, cx| {
|
||||
let Ok(workspace) = handle.downcast::<Workspace>() else {
|
||||
return;
|
||||
};
|
||||
let Some(editor) = workspace
|
||||
.read(cx)
|
||||
.active_item(cx)
|
||||
.and_then(|item| item.act_as::<Editor>(cx))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
editor.update(cx, |editor, cx| {
|
||||
editor.replay_insert_event(&text, utf16_range_to_replace.clone(), cx)
|
||||
})
|
||||
})
|
||||
.log_err();
|
||||
let Some(Some(workspace)) = window.root_model::<Workspace>() else {
|
||||
return;
|
||||
};
|
||||
let Some(editor) = workspace
|
||||
.read(cx)
|
||||
.active_item(cx)
|
||||
.and_then(|item| item.act_as::<Editor>(cx))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
editor.update(cx, |editor, cx| {
|
||||
editor.replay_insert_event(&text, utf16_range_to_replace.clone(), window, cx)
|
||||
})
|
||||
}
|
||||
}
|
||||
cx.defer(move |cx| self.next(cx));
|
||||
window.defer(cx, move |window, cx| self.next(window, cx));
|
||||
}
|
||||
}
|
||||
|
||||
impl Vim {
|
||||
pub(crate) fn record_register(&mut self, register: char, cx: &mut ViewContext<Self>) {
|
||||
pub(crate) fn record_register(
|
||||
&mut self,
|
||||
register: char,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let globals = Vim::globals(cx);
|
||||
globals.recording_register = Some(register);
|
||||
globals.recordings.remove(®ister);
|
||||
globals.ignore_current_insertion = true;
|
||||
self.clear_operator(cx)
|
||||
self.clear_operator(window, cx)
|
||||
}
|
||||
|
||||
pub(crate) fn replay_register(&mut self, mut register: char, cx: &mut ViewContext<Self>) {
|
||||
pub(crate) fn replay_register(
|
||||
&mut self,
|
||||
mut register: char,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let mut count = Vim::take_count(cx).unwrap_or(1);
|
||||
self.clear_operator(cx);
|
||||
self.clear_operator(window, cx);
|
||||
|
||||
let globals = Vim::globals(cx);
|
||||
if register == '@' {
|
||||
|
@ -184,11 +191,17 @@ impl Vim {
|
|||
|
||||
globals.last_replayed_register = Some(register);
|
||||
let mut replayer = globals.replayer.get_or_insert_with(Replayer::new).clone();
|
||||
replayer.replay(repeated_actions, cx);
|
||||
replayer.replay(repeated_actions, window, cx);
|
||||
}
|
||||
|
||||
pub(crate) fn repeat(&mut self, from_insert_mode: bool, cx: &mut ViewContext<Self>) {
|
||||
pub(crate) fn repeat(
|
||||
&mut self,
|
||||
from_insert_mode: bool,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let count = Vim::take_count(cx);
|
||||
|
||||
let Some((mut actions, selection, mode)) = Vim::update_globals(cx, |globals, _| {
|
||||
let actions = globals.recorded_actions.clone();
|
||||
if actions.is_empty() {
|
||||
|
@ -231,13 +244,13 @@ impl Vim {
|
|||
return;
|
||||
};
|
||||
if let Some(mode) = mode {
|
||||
self.switch_mode(mode, false, cx)
|
||||
self.switch_mode(mode, false, window, cx)
|
||||
}
|
||||
|
||||
match selection {
|
||||
RecordedSelection::SingleLine { cols } => {
|
||||
if cols > 1 {
|
||||
self.visual_motion(Motion::Right, Some(cols as usize - 1), cx)
|
||||
self.visual_motion(Motion::Right, Some(cols as usize - 1), window, cx)
|
||||
}
|
||||
}
|
||||
RecordedSelection::Visual { rows, cols } => {
|
||||
|
@ -246,6 +259,7 @@ impl Vim {
|
|||
display_lines: false,
|
||||
},
|
||||
Some(rows as usize),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
self.visual_motion(
|
||||
|
@ -253,10 +267,11 @@ impl Vim {
|
|||
display_lines: false,
|
||||
},
|
||||
None,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
if cols > 1 {
|
||||
self.visual_motion(Motion::Right, Some(cols as usize - 1), cx)
|
||||
self.visual_motion(Motion::Right, Some(cols as usize - 1), window, cx)
|
||||
}
|
||||
}
|
||||
RecordedSelection::VisualBlock { rows, cols } => {
|
||||
|
@ -265,10 +280,11 @@ impl Vim {
|
|||
display_lines: false,
|
||||
},
|
||||
Some(rows as usize),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
if cols > 1 {
|
||||
self.visual_motion(Motion::Right, Some(cols as usize - 1), cx);
|
||||
self.visual_motion(Motion::Right, Some(cols as usize - 1), window, cx);
|
||||
}
|
||||
}
|
||||
RecordedSelection::VisualLine { rows } => {
|
||||
|
@ -277,6 +293,7 @@ impl Vim {
|
|||
display_lines: false,
|
||||
},
|
||||
Some(rows as usize),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
@ -321,7 +338,8 @@ impl Vim {
|
|||
let globals = Vim::globals(cx);
|
||||
globals.dot_replaying = true;
|
||||
let mut replayer = globals.replayer.get_or_insert_with(Replayer::new).clone();
|
||||
replayer.replay(actions, cx);
|
||||
|
||||
replayer.replay(actions, window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,9 +398,9 @@ mod test {
|
|||
cx.simulate_keystrokes("i");
|
||||
|
||||
// simulate brazilian input for ä.
|
||||
cx.update_editor(|editor, cx| {
|
||||
editor.replace_and_mark_text_in_range(None, "\"", Some(1..1), cx);
|
||||
editor.replace_text_in_range(None, "ä", cx);
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
editor.replace_and_mark_text_in_range(None, "\"", Some(1..1), window, cx);
|
||||
editor.replace_text_in_range(None, "ä", window, cx);
|
||||
});
|
||||
cx.simulate_keystrokes("escape");
|
||||
cx.assert_state("hˇällo", Mode::Normal);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue