T66: files dropped on the terminal type their paths, which a user asked for after 0.1.6, as macOS Terminal does: each escaped for the shell, or quoted on Windows when it holds a space, followed by a space, sent as a paste; a path not in UTF-8 or holding a control character stops the drop; the font code moves from view.rs to fonts.rs, which view.rs needed room for; shot plays a drop with drop@x,y
This commit is contained in:
10 files changed
+227
-76
No files matched your search
@@ -69,6 +69,20 @@ fn main() {
|
||||
aim = settings.expect("a settings window");
|
||||
capture::front(number(aim, cx)).expect("the window on screen");
|
||||
}
|
||||
spec if spec.starts_with("drop@") => {
|
||||
let paths =
|
||||
std::env::var("SHOT_DROP").expect("SHOT_DROP names the paths");
|
||||
let event = typing::drop(&spec[5..], &paths).expect("a drop");
|
||||
// A drag moves over frames before it lands.
|
||||
for step in event {
|
||||
aim.update(cx, |_, window, cx| window.dispatch_event(step, cx))
|
||||
.expect("the window lives");
|
||||
cx.background_executor()
|
||||
.timer(Duration::from_millis(120))
|
||||
.await;
|
||||
}
|
||||
log::info!("shot: dropped {paths:?} at {}", &spec[5..]);
|
||||
}
|
||||
spec => typing::post(spec, number(aim, cx)).expect("a key event"),
|
||||
}
|
||||
if spec.starts_with("to:") {
|
||||
|
||||
@@ -314,3 +314,20 @@ fn key(spec: &str, number: u32, kinds: &[u64]) -> anyhow::Result<()> {
|
||||
log::info!("shot: typed {spec}, the app {state}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A file drop of `paths`, one a line, at `at`, `x,y` from the content's top-left, as gpui's AppKit view sends it.
|
||||
pub fn drop(at: &str, paths: &str) -> anyhow::Result<[gpui::PlatformInput; 4]> {
|
||||
use gpui::{ExternalPaths, FileDropEvent, PlatformInput, point, px};
|
||||
let (x, y) = at
|
||||
.split_once(',')
|
||||
.with_context(|| format!("a point in {at}"))?;
|
||||
let position = point(px(x.parse()?), px(y.parse()?));
|
||||
let paths = ExternalPaths(paths.lines().map(Into::into).collect());
|
||||
Ok([
|
||||
FileDropEvent::Entered { position, paths },
|
||||
FileDropEvent::Pending { position },
|
||||
FileDropEvent::Submit { position },
|
||||
FileDropEvent::Ended,
|
||||
]
|
||||
.map(PlatformInput::FileDrop))
|
||||
}
|
||||
Reference in new issue
Block a user