FileFinder tests
This commit is contained in:
parent
d791fc707a
commit
cebc8428c8
6 changed files with 1144 additions and 1251 deletions
|
@ -403,7 +403,7 @@ mod tests {
|
||||||
|
|
||||||
let palette = workspace.update(cx, |workspace, cx| {
|
let palette = workspace.update(cx, |workspace, cx| {
|
||||||
workspace
|
workspace
|
||||||
.current_modal::<CommandPalette>(cx)
|
.active_modal::<CommandPalette>(cx)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.picker
|
.picker
|
||||||
|
@ -426,7 +426,7 @@ mod tests {
|
||||||
cx.simulate_keystrokes("enter");
|
cx.simulate_keystrokes("enter");
|
||||||
|
|
||||||
workspace.update(cx, |workspace, cx| {
|
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")
|
assert_eq!(editor.read(cx).text(cx), "ab")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ mod tests {
|
||||||
|
|
||||||
let palette = workspace.update(cx, |workspace, cx| {
|
let palette = workspace.update(cx, |workspace, cx| {
|
||||||
workspace
|
workspace
|
||||||
.current_modal::<CommandPalette>(cx)
|
.active_modal::<CommandPalette>(cx)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.picker
|
.picker
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -225,6 +225,9 @@ impl TestAppContext {
|
||||||
self.background_executor.run_until_parked()
|
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) {
|
pub fn simulate_keystrokes(&mut self, window: AnyWindowHandle, keystrokes: &str) {
|
||||||
for keystroke in keystrokes
|
for keystroke in keystrokes
|
||||||
.split(" ")
|
.split(" ")
|
||||||
|
@ -237,6 +240,17 @@ impl TestAppContext {
|
||||||
self.background_executor.run_until_parked()
|
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(
|
pub fn dispatch_keystroke(
|
||||||
&mut self,
|
&mut self,
|
||||||
window: AnyWindowHandle,
|
window: AnyWindowHandle,
|
||||||
|
@ -455,6 +469,10 @@ impl<'a> VisualTestContext<'a> {
|
||||||
pub fn simulate_keystrokes(&mut self, keystrokes: &str) {
|
pub fn simulate_keystrokes(&mut self, keystrokes: &str) {
|
||||||
self.cx.simulate_keystrokes(self.window, keystrokes)
|
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> {
|
impl<'a> Context for VisualTestContext<'a> {
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl ModalLayer {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_modal<V>(&self) -> Option<View<V>>
|
pub fn active_modal<V>(&self) -> Option<View<V>>
|
||||||
where
|
where
|
||||||
V: 'static,
|
V: 'static,
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,8 +8,8 @@ use anyhow::Result;
|
||||||
use collections::{HashMap, HashSet, VecDeque};
|
use collections::{HashMap, HashSet, VecDeque};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, prelude::*, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
|
actions, prelude::*, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
|
||||||
EventEmitter, FocusHandle, Model, PromptLevel, Render, Task, View, ViewContext, VisualContext,
|
EventEmitter, FocusHandle, Focusable, Model, PromptLevel, Render, Task, View, ViewContext,
|
||||||
WeakView, WindowContext,
|
VisualContext, WeakView, WindowContext,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use project2::{Project, ProjectEntryId, ProjectPath};
|
use project2::{Project, ProjectEntryId, ProjectPath};
|
||||||
|
@ -1017,7 +1017,11 @@ impl Pane {
|
||||||
.unwrap_or_else(|| item_index.min(self.items.len()).saturating_sub(1));
|
.unwrap_or_else(|| item_index.min(self.items.len()).saturating_sub(1));
|
||||||
|
|
||||||
let should_activate = activate_pane || self.has_focus(cx);
|
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);
|
let item = self.items.remove(item_index);
|
||||||
|
@ -1913,11 +1917,12 @@ impl Pane {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
impl Render for 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 {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
v_stack()
|
v_stack()
|
||||||
.key_context("Pane")
|
.key_context("Pane")
|
||||||
|
.track_focus(&self.focus_handle)
|
||||||
.size_full()
|
.size_full()
|
||||||
.on_action(|pane: &mut Self, action, cx| {
|
.on_action(|pane: &mut Self, action, cx| {
|
||||||
pane.close_active_item(action, cx)
|
pane.close_active_item(action, cx)
|
||||||
|
|
|
@ -38,9 +38,9 @@ use futures::{
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, div, point, prelude::*, rems, size, Action, AnyModel, AnyView, AnyWeakView,
|
actions, div, point, prelude::*, rems, size, Action, AnyModel, AnyView, AnyWeakView,
|
||||||
AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId,
|
AppContext, AsyncAppContext, AsyncWindowContext, Bounds, Component, Div, Entity, EntityId,
|
||||||
EventEmitter, FocusHandle, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent,
|
EventEmitter, GlobalPixels, KeyContext, Model, ModelContext, ParentComponent, Point, Render,
|
||||||
Point, Render, Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds,
|
Size, Styled, Subscription, Task, View, ViewContext, WeakView, WindowBounds, WindowContext,
|
||||||
WindowContext, WindowHandle, WindowOptions,
|
WindowHandle, WindowOptions,
|
||||||
};
|
};
|
||||||
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -433,7 +433,6 @@ pub enum Event {
|
||||||
|
|
||||||
pub struct Workspace {
|
pub struct Workspace {
|
||||||
weak_self: WeakView<Self>,
|
weak_self: WeakView<Self>,
|
||||||
focus_handle: FocusHandle,
|
|
||||||
workspace_actions: Vec<Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>>,
|
workspace_actions: Vec<Box<dyn Fn(Div<Workspace>) -> Div<Workspace>>>,
|
||||||
zoomed: Option<AnyWeakView>,
|
zoomed: Option<AnyWeakView>,
|
||||||
zoomed_position: Option<DockPosition>,
|
zoomed_position: Option<DockPosition>,
|
||||||
|
@ -651,7 +650,6 @@ impl Workspace {
|
||||||
cx.defer(|this, cx| this.update_window_title(cx));
|
cx.defer(|this, cx| this.update_window_title(cx));
|
||||||
Workspace {
|
Workspace {
|
||||||
weak_self: weak_handle.clone(),
|
weak_self: weak_handle.clone(),
|
||||||
focus_handle: cx.focus_handle(),
|
|
||||||
zoomed: None,
|
zoomed: None,
|
||||||
zoomed_position: None,
|
zoomed_position: None,
|
||||||
center: PaneGroup::new(center_pane.clone()),
|
center: PaneGroup::new(center_pane.clone()),
|
||||||
|
@ -1450,6 +1448,11 @@ impl Workspace {
|
||||||
self.active_pane().read(cx).active_item()
|
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> {
|
fn active_project_path(&self, cx: &ViewContext<Self>) -> Option<ProjectPath> {
|
||||||
self.active_item(cx).and_then(|item| item.project_path(cx))
|
self.active_item(cx).and_then(|item| item.project_path(cx))
|
||||||
}
|
}
|
||||||
|
@ -1570,7 +1573,7 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
if focus_center {
|
if focus_center {
|
||||||
cx.focus(&self.focus_handle);
|
self.active_pane.update(cx, |pane, cx| pane.focus(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
@ -1704,7 +1707,7 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
if focus_center {
|
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 {
|
if self.zoomed_position != dock_to_reveal {
|
||||||
|
@ -3475,8 +3478,8 @@ impl Workspace {
|
||||||
div
|
div
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_modal<V: Modal + 'static>(&mut self, cx: &ViewContext<Self>) -> Option<View<V>> {
|
pub fn active_modal<V: Modal + 'static>(&mut self, cx: &ViewContext<Self>) -> Option<View<V>> {
|
||||||
self.modal_layer.read(cx).current_modal()
|
self.modal_layer.read(cx).active_modal()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_modal<V: Modal, B>(&mut self, cx: &mut ViewContext<Self>, build: B)
|
pub fn toggle_modal<V: Modal, B>(&mut self, cx: &mut ViewContext<Self>, build: B)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue