Open URLs with cmd-click (#7312)
Release Notes: - Added ability to cmd-click on URLs in all buffers --------- Co-authored-by: fdionisi <code@fdionisi.me>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use crate::{
|
||||
Action, AnyElement, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
|
||||
AvailableSpace, BackgroundExecutor, Bounds, ClipboardItem, Context, Entity, EventEmitter,
|
||||
ForegroundExecutor, Global, InputEvent, Keystroke, Model, ModelContext, Pixels, Platform,
|
||||
Point, Render, Result, Size, Task, TestDispatcher, TestPlatform, TestWindow, TextSystem, View,
|
||||
ViewContext, VisualContext, WindowContext, WindowHandle, WindowOptions,
|
||||
ForegroundExecutor, Global, InputEvent, Keystroke, Model, ModelContext, Modifiers,
|
||||
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
|
||||
Platform, Point, Render, Result, Size, Task, TestDispatcher, TestPlatform, TestWindow,
|
||||
TextSystem, View, ViewContext, VisualContext, WindowContext, WindowHandle, WindowOptions,
|
||||
};
|
||||
use anyhow::{anyhow, bail};
|
||||
use futures::{Stream, StreamExt};
|
||||
@@ -236,6 +237,11 @@ impl TestAppContext {
|
||||
self.test_platform.has_pending_prompt()
|
||||
}
|
||||
|
||||
/// All the urls that have been opened with cx.open_url() during this test.
|
||||
pub fn opened_url(&self) -> Option<String> {
|
||||
self.test_platform.opened_url.borrow().clone()
|
||||
}
|
||||
|
||||
/// Simulates the user resizing the window to the new size.
|
||||
pub fn simulate_window_resize(&self, window_handle: AnyWindowHandle, size: Size<Pixels>) {
|
||||
self.test_window(window_handle).simulate_resize(size);
|
||||
@@ -625,6 +631,36 @@ impl<'a> VisualTestContext {
|
||||
self.cx.simulate_input(self.window, input)
|
||||
}
|
||||
|
||||
/// Simulate a mouse move event to the given point
|
||||
pub fn simulate_mouse_move(&mut self, position: Point<Pixels>, modifiers: Modifiers) {
|
||||
self.simulate_event(MouseMoveEvent {
|
||||
position,
|
||||
modifiers,
|
||||
pressed_button: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Simulate a primary mouse click at the given point
|
||||
pub fn simulate_click(&mut self, position: Point<Pixels>, modifiers: Modifiers) {
|
||||
self.simulate_event(MouseDownEvent {
|
||||
position,
|
||||
modifiers,
|
||||
button: MouseButton::Left,
|
||||
click_count: 1,
|
||||
});
|
||||
self.simulate_event(MouseUpEvent {
|
||||
position,
|
||||
modifiers,
|
||||
button: MouseButton::Left,
|
||||
click_count: 1,
|
||||
});
|
||||
}
|
||||
|
||||
/// Simulate a modifiers changed event
|
||||
pub fn simulate_modifiers_change(&mut self, modifiers: Modifiers) {
|
||||
self.simulate_event(ModifiersChangedEvent { modifiers })
|
||||
}
|
||||
|
||||
/// Simulates the user resizing the window to the new size.
|
||||
pub fn simulate_resize(&self, size: Size<Pixels>) {
|
||||
self.simulate_window_resize(self.window, size)
|
||||
|
||||
@@ -170,4 +170,34 @@ impl Modifiers {
|
||||
pub fn modified(&self) -> bool {
|
||||
self.control || self.alt || self.shift || self.command || self.function
|
||||
}
|
||||
|
||||
/// helper method for Modifiers with no modifiers
|
||||
pub fn none() -> Modifiers {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// helper method for Modifiers with just command
|
||||
pub fn command() -> Modifiers {
|
||||
Modifiers {
|
||||
command: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// helper method for Modifiers with just shift
|
||||
pub fn shift() -> Modifiers {
|
||||
Modifiers {
|
||||
shift: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// helper method for Modifiers with command + shift
|
||||
pub fn command_shift() -> Modifiers {
|
||||
Modifiers {
|
||||
shift: true,
|
||||
command: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ pub(crate) struct TestPlatform {
|
||||
active_cursor: Mutex<CursorStyle>,
|
||||
current_clipboard_item: Mutex<Option<ClipboardItem>>,
|
||||
pub(crate) prompts: RefCell<TestPrompts>,
|
||||
pub opened_url: RefCell<Option<String>>,
|
||||
weak: Weak<Self>,
|
||||
}
|
||||
|
||||
@@ -45,6 +46,7 @@ impl TestPlatform {
|
||||
active_window: Default::default(),
|
||||
current_clipboard_item: Mutex::new(None),
|
||||
weak: weak.clone(),
|
||||
opened_url: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -188,8 +190,8 @@ impl Platform for TestPlatform {
|
||||
|
||||
fn stop_display_link(&self, _display_id: DisplayId) {}
|
||||
|
||||
fn open_url(&self, _url: &str) {
|
||||
unimplemented!()
|
||||
fn open_url(&self, url: &str) {
|
||||
*self.opened_url.borrow_mut() = Some(url.to_string())
|
||||
}
|
||||
|
||||
fn on_open_urls(&self, _callback: Box<dyn FnMut(Vec<String>)>) {
|
||||
|
||||
Reference in New Issue
Block a user