Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions app/src/code/file_tree/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3089,18 +3089,26 @@ impl TypedActionView for FileTreeView {
id,
terminal_input_data,
} => {
let Some(relative_path) = self.relative_path_for_item(id) else {
let Some(root_dir) = self.root_directories.get(&id.root) else {
return;
};
let Some(item) = root_dir.items.get(id.index) else {
return;
};

// Use the absolute path (consistent with Finder drops) and route
// through the editor's DragAndDropFiles path so that image
// detection, shell escaping, and WSL path transformation all
// apply uniformly regardless of the drop source.
let path = item.path().as_str().to_string();

let weak_view_handle = terminal_input_data.weak_view_handle();
let Some(input_view) = weak_view_handle.upgrade(ctx) else {
return;
};

let file_path = relative_path.to_string_lossy();
input_view.update(ctx, |input_view, ctx| {
input_view.append_to_buffer(&file_path, ctx);
input_view.handle_drag_and_drop_files(vec![path], ctx);
});
}
FileTreeAction::ItemDroppedOnTerminal { id, terminal_view } => {
Expand All @@ -3111,15 +3119,16 @@ impl TypedActionView for FileTreeView {
return;
};

let path_str = item.path().as_str();

let Some(terminal_view) = terminal_view.upgrade(ctx) else {
return;
};

let file_path = path_str.to_string();
// Route through the terminal view's drag_and_drop_files so that
// image detection, shell escaping, WSL path conversion, and SSH
// file upload all apply consistently with Finder drops.
let path = item.path().as_str().to_string();
terminal_view.update(ctx, |view, ctx| {
view.handle_file_tree_drop_on_active_command(&file_path, ctx);
view.drag_and_drop_files(&[path], ctx);
});
}
}
Expand Down
14 changes: 13 additions & 1 deletion app/src/terminal/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ use warp_core::{
ui::theme::{color::internal_colors, AnsiColorIdentifier},
};
use warp_editor::editor::NavigationKey;
use warp_util::path::ShellFamily;
use warp_util::{path::ShellFamily, user_input::UserInput};
use warpui::{
accessibility::{AccessibilityContent, ActionAccessibilityContent, WarpA11yRole},
clipboard::{ClipboardContent, ImageData},
Expand Down Expand Up @@ -7615,6 +7615,18 @@ impl Input {
self.system_insert(content, ctx);
}

/// Handles file paths dropped from the project explorer by routing them through
/// the editor's DragAndDropFiles action. This ensures consistent behavior with
/// Finder drops: image detection, shell escaping, and path transformation all
/// apply uniformly.
pub fn handle_drag_and_drop_files(&mut self, paths: Vec<String>, ctx: &mut ViewContext<Self>) {
self.editor.update(ctx, |editor, ctx| {
let user_paths: Vec<UserInput<String>> =
paths.iter().map(|p| UserInput::new(p.as_str())).collect();
editor.handle_action(&EditorAction::DragAndDropFiles(user_paths), ctx);
});
}

pub fn insert_typeahead_text(
&mut self,
num_typeahead_chars_inserted: CharOffset,
Expand Down
2 changes: 1 addition & 1 deletion app/src/terminal/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23753,7 +23753,7 @@ impl TerminalView {
self.cursor_position_id.clone()
}

fn drag_and_drop_files(&mut self, paths: &[String], ctx: &mut ViewContext<Self>) {
pub fn drag_and_drop_files(&mut self, paths: &[String], ctx: &mut ViewContext<Self>) {
self.is_file_drop_target = false;
if paths.is_empty() {
return;
Expand Down
Loading