mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-07 18:04:37 +03:00
FileFinder tests
This commit is contained in:
parent
d791fc707a
commit
cebc8428c8
@ -403,7 +403,7 @@ mod tests {
|
||||
|
||||
let palette = workspace.update(cx, |workspace, cx| {
|
||||
workspace
|
||||
.current_modal::<CommandPalette>(cx)
|
||||
.active_modal::<CommandPalette>(cx)
|
||||
.unwrap()
|
||||
.read(cx)
|
||||
.picker
|
||||
@ -426,7 +426,7 @@ mod tests {
|
||||
cx.simulate_keystrokes("enter");
|
||||
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
assert!(workspace.current_modal::<CommandPalette>(cx).is_none());
|
||||
assert!(workspace.active_modal::<CommandPalette>(cx).is_none());
|
||||
assert_eq!(editor.read(cx).text(cx), "ab")
|
||||
});
|
||||
|
||||
@ -443,7 +443,7 @@ mod tests {
|
||||
|
||||
let palette = workspace.update(cx, |workspace, cx| {
|
||||
workspace
|
||||
.current_modal::<CommandPalette>(cx)
|
||||
.active_modal::<CommandPalette>(cx)
|
||||
.unwrap()
|
||||
.read(cx)
|
||||
.picker
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -225,6 +225,9 @@ impl TestAppContext {
|
||||
self.background_executor.run_until_parked()
|
||||
}
|
||||
|
||||
/// simulate_keystrokes takes a space-separated list of keys to type.
|
||||
/// cx.simulate_keystrokes("cmd-shift-p b k s p enter")
|
||||
/// will run backspace on the current editor through the command palette.
|
||||
pub fn simulate_keystrokes(&mut self, window: AnyWindowHandle, keystrokes: &str) {
|
||||
for keystroke in keystrokes
|
||||
.split(" ")
|
||||
@ -237,6 +240,17 @@ impl TestAppContext {
|
||||
self.background_executor.run_until_parked()
|
||||
}
|
||||
|
||||
/// simulate_input takes a string of text to type.
|
||||
/// cx.simulate_input("abc")
|
||||
/// will type abc into your current editor.
|
||||
pub fn simulate_input(&mut self, window: AnyWindowHandle, input: &str) {
|
||||
for keystroke in input.split("").map(Keystroke::parse).map(Result::unwrap) {
|
||||
self.dispatch_keystroke(window, keystroke.into(), false);
|
||||
}
|
||||
|
||||
self.background_executor.run_until_parked()
|
||||
}
|
||||
|
||||
pub fn dispatch_keystroke(
|
||||
&mut self,
|
||||
window: AnyWindowHandle,
|
||||
@ -455,6 +469,10 @@ impl<'a> VisualTestContext<'a> {
|
||||
pub fn simulate_keystrokes(&mut self, keystrokes: &str) {
|
||||
self.cx.simulate_keystrokes(self.window, keystrokes)
|
||||
}
|
||||
|
||||
pub fn simulate_input(&mut self, input: &str) {
|
||||
self.cx.simulate_input(self.window, input)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Context for VisualTestContext<'a> {
|
||||
|
@ -72,7 +72,7 @@ impl ModalLayer {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn current_modal<V>(&self) -> Option<View<V>>
|
||||
pub fn active_modal<V>(&self) -> Option<View<V>>
|
||||
where
|
||||
V: 'static,
|
||||
{
|
||||
|
@ -8,8 +8,8 @@ use anyhow::Result;
|
||||
use collections::{HashMap, HashSet, VecDeque};
|
||||
use gpui::{
|
||||
actions, prelude::*, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
|
||||
EventEmitter, FocusHandle, Model, PromptLevel, Render, Task, View, ViewContext, VisualContext,
|
||||
WeakView, WindowContext,
|
||||
EventEmitter, FocusHandle, Focusable, Model, PromptLevel, Render, Task, View, ViewContext,
|
||||
VisualContext, WeakView, WindowContext,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||
@ -1017,7 +1017,11 @@ impl Pane {
|
||||
.unwrap_or_else(|| item_index.min(self.items.len()).saturating_sub(1));
|
||||
|
||||
let should_activate = activate_pane || self.has_focus(cx);
|
||||
self.activate_item(index_to_activate, should_activate, should_activate, cx);
|
||||
if self.items.len() == 1 && should_activate {
|
||||
self.focus_handle.focus(cx);
|
||||
} else {
|
||||
self.activate_item(index_to_activate, should_activate, should_activate, cx);
|
||||
}
|
||||
}
|
||||
|
||||
let item = self.items.remove(item_index);
|
||||
@ -1913,11 +1917,12 @@ impl Pane {
|
||||
// }
|
||||
|
||||
impl Render for Pane {
|
||||
type Element = Div<Self>;
|
||||
type Element = Focusable<Self, Div<Self>>;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
v_stack()
|
||||
.key_context("Pane")
|
||||
.track_focus(&self.focus_handle)
|
||||
.size_full()
|
||||
.on_action(|pane: &mut Self, action, cx| {
|
||||
pane.close_active_item(action, cx)
|
||||
|
@ -38,9 +38,9 @@ use futures::{
|
||||
use gpui::{
|
||||
actions, div, point, prelude::*, rems, size, Action, AnyModel, AnyView, AnyWeakView,
|
||||
AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId,
|
||||
EventEmitter, FocusHandle, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent,
|
||||
Point, Render, Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds,
|
||||
WindowContext, WindowHandle, WindowOptions,
|
||||
EventEmitter, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent, Point, Render,
|
||||
Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds, WindowContext,
|
||||
WindowHandle, WindowOptions,
|
||||
};
|
||||
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
||||
use itertools::Itertools;
|
||||
@ -433,7 +433,6 @@ pub enum Event {
|
||||
|
||||
pub struct Workspace {
|
||||
weak_self: WeakView<Self>,
|
||||
focus_handle: FocusHandle,
|
||||
workspace_actions: Vec<Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>>,
|
||||
zoomed: Option<AnyWeakView>,
|
||||
zoomed_position: Option<DockPosition>,
|
||||
@ -651,7 +650,6 @@ impl Workspace {
|
||||
cx.defer(|this, cx| this.update_window_title(cx));
|
||||
Workspace {
|
||||
weak_self: weak_handle.clone(),
|
||||
focus_handle: cx.focus_handle(),
|
||||
zoomed: None,
|
||||
zoomed_position: None,
|
||||
center: PaneGroup::new(center_pane.clone()),
|
||||
@ -1450,6 +1448,11 @@ impl Workspace {
|
||||
self.active_pane().read(cx).active_item()
|
||||
}
|
||||
|
||||
pub fn active_item_as<I: 'static>(&self, cx: &AppContext) -> Option<View<I>> {
|
||||
let item = self.active_item(cx)?;
|
||||
item.to_any().downcast::<I>().ok()
|
||||
}
|
||||
|
||||
fn active_project_path(&self, cx: &ViewContext<Self>) -> Option<ProjectPath> {
|
||||
self.active_item(cx).and_then(|item| item.project_path(cx))
|
||||
}
|
||||
@ -1570,7 +1573,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
if focus_center {
|
||||
cx.focus(&self.focus_handle);
|
||||
self.active_pane.update(cx, |pane, cx| pane.focus(cx))
|
||||
}
|
||||
|
||||
cx.notify();
|
||||
@ -1704,7 +1707,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
if focus_center {
|
||||
cx.focus(&self.focus_handle);
|
||||
self.active_pane.update(cx, |pane, cx| pane.focus(cx))
|
||||
}
|
||||
|
||||
if self.zoomed_position != dock_to_reveal {
|
||||
@ -3475,8 +3478,8 @@ impl Workspace {
|
||||
div
|
||||
}
|
||||
|
||||
pub fn current_modal<V: Modal + 'static>(&mut self, cx: &ViewContext<Self>) -> Option<View<V>> {
|
||||
self.modal_layer.read(cx).current_modal()
|
||||
pub fn active_modal<V: Modal + 'static>(&mut self, cx: &ViewContext<Self>) -> Option<View<V>> {
|
||||
self.modal_layer.read(cx).active_modal()
|
||||
}
|
||||
|
||||
pub fn toggle_modal<V: Modal, B>(&mut self, cx: &mut ViewContext<Self>, build: B)
|
||||
|
Loading…
Reference in New Issue
Block a user