Compare commits

..
5 Commits
Author SHA1 Message Date
TomZz 690d7418f4 feat: Save 'show hidden files' toggle state to settings 2026-06-12 20:25:29 +08:00
TomZz aca03c924f fix: Cache text metrics for terminal IME bounds to prevent blocking during composition 2026-06-12 20:20:49 +08:00
TomZz 8c24eb885c fix: Optimize terminal rendering cell width calculation and line height 2026-06-12 12:44:35 +08:00
TomZz 2afcd1ea90 feat: Add SFTP directory batch delete and create folder features, fix auto refresh bug 2026-06-12 07:54:10 +08:00
TomZz 68439bc599 feat: support editing remote text files with local system editor
- Add right-click 'Edit' context menu option for common text formats.

- Automatically download file to a temporary directory and open in default editor.

- Background daemon listens for save events and auto-uploads changes quietly.

- Isolate auto-sync from transfer history UI.

- Clear legacy session config tmp files on application startup.
2026-06-12 07:14:55 +08:00
9 changed files with 951 additions and 76 deletions
Generated
+93 -4
View File
@@ -299,6 +299,8 @@ dependencies = [
"gpui_platform",
"image",
"menu",
"notify 6.1.1",
"open",
"portable-pty",
"rfd",
"russh",
@@ -1414,6 +1416,15 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.6"
@@ -2696,7 +2707,7 @@ dependencies = [
"lsp-types",
"markdown",
"markup5ever_rcdom",
"notify",
"notify 7.0.0",
"num-traits",
"once_cell",
"paste",
@@ -3458,6 +3469,17 @@ dependencies = [
"serde_core",
]
[[package]]
name = "inotify"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
dependencies = [
"bitflags 1.3.2",
"inotify-sys",
"libc",
]
[[package]]
name = "inotify"
version = "0.10.2"
@@ -3547,6 +3569,25 @@ version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2"
[[package]]
name = "is-docker"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
dependencies = [
"once_cell",
]
[[package]]
name = "is-wsl"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
dependencies = [
"is-docker",
"once_cell",
]
[[package]]
name = "itertools"
version = "0.11.0"
@@ -4109,6 +4150,18 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "mio"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
dependencies = [
"libc",
"log",
"wasi",
"windows-sys 0.48.0",
]
[[package]]
name = "mio"
version = "1.2.1"
@@ -4270,6 +4323,25 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "notify"
version = "6.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
dependencies = [
"bitflags 2.12.1",
"crossbeam-channel",
"filetime",
"fsevent-sys",
"inotify 0.9.6",
"kqueue",
"libc",
"log",
"mio 0.8.11",
"walkdir",
"windows-sys 0.48.0",
]
[[package]]
name = "notify"
version = "7.0.0"
@@ -4279,11 +4351,11 @@ dependencies = [
"bitflags 2.12.1",
"filetime",
"fsevent-sys",
"inotify",
"inotify 0.10.2",
"kqueue",
"libc",
"log",
"mio",
"mio 1.2.1",
"notify-types",
"walkdir",
"windows-sys 0.52.0",
@@ -4707,6 +4779,17 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "open"
version = "5.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fbaa89d2ddc8473c78a3adf69eea8cffa28c483b8e02a971ef31527cd0fc92c"
dependencies = [
"is-wsl",
"libc",
"pathdiff",
]
[[package]]
name = "openssl-probe"
version = "0.2.1"
@@ -4832,6 +4915,12 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35fb2e5f958ec131621fdd531e9fc186ed768cbe395337403ae56c17a74c68ec"
[[package]]
name = "pathdiff"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
[[package]]
name = "pathfinder_geometry"
version = "0.5.1"
@@ -7418,7 +7507,7 @@ checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe"
dependencies = [
"bytes",
"libc",
"mio",
"mio 1.2.1",
"pin-project-lite",
"socket2",
"tokio-macros",
+2
View File
@@ -40,6 +40,8 @@ walkdir = "2"
zip = { version = "2", default-features = false, features = ["deflate"] }
image = { version = "0.25.9", default-features = false, features = ["png"] }
futures = "0.3.32"
notify = "6.1.1"
open = "5.1"
[profile.release]
opt-level = 3
+15 -1
View File
@@ -6,12 +6,23 @@ upload_file: "Upload File"
upload_folder: "Upload Folder"
hidden: "Hidden"
download: "Download"
download_folder: "Download Folder"
download_count: "Download (%{count})"
name: "NAME"
size: "SIZE"
modified: "MODIFIED"
new_ssh_connection: "New SSH Connection"
create_or_edit_ssh_session: "Create or edit an SSH session"
new_folder: "New Folder"
create_folder_success: "Created folder: %{name}"
create_folder_failed: "Failed to create folder: %{err}"
delete_selected: "Delete"
confirm_delete: "Confirm Delete"
confirm_delete_desc: "Are you sure you want to delete the selected %{count} items? This action cannot be undone."
system_path_warning: "WARNING: You are attempting to delete critical system paths! This may cause system corruption!"
delete_success: "Successfully deleted %{count} items"
delete_failed: "Failed to delete: %{err}"
deleting_paths: "Deleting %{count} items..."
local_terminal: "Local Terminal"
open_local_shell_tab: "Open a new local shell tab"
connect: "Connect"
@@ -94,4 +105,7 @@ session: "Session"
software_builtin: "Built-in"
retry: "Retry"
right_click_copy_paste: "Right-click Copy/Paste"
copy_paste_hint: "Tip: Regardless of this switch, you can always use %{key} + C/V to copy/paste."
copy_paste_hint: "Tip: Regardless of this switch, you can always use %{key} + C/V to copy/paste."
edit_file: "Edit File"
edit_file_tooltip: "Download to temporary directory, open in default editor, and auto upload on save."
auto_saved_and_uploaded: "Auto-saved & uploaded: %{base}"
+17 -1
View File
@@ -6,12 +6,25 @@ upload_file: "上传文件"
upload_folder: "上传文件夹"
hidden: "显示隐藏文件"
download: "下载"
download_folder: "下载文件夹"
download_count: "下载 (%{count})"
name: "名称"
size: "大小"
modified: "修改时间"
new_ssh_connection: "新建 SSH 连接"
create_or_edit_ssh_session: "创建或编辑一个 SSH 会话"
new_folder: "新建文件夹"
create_folder_success: "成功创建文件夹: %{name}"
create_folder_failed: "创建文件夹失败: %{err}"
delete_selected: "删除"
confirm_delete: "确认删除"
confirm_delete_desc: "确定要删除以下选中的 %{count} 个项吗?此操作无法撤销。"
system_path_warning: "警告:您即将删除系统关键路径!这可能会导致系统损坏!"
delete_success: "成功删除 %{count} 个项"
delete_failed: "删除失败: %{err}"
deleting_paths: "正在删除 %{count} 个项..."
cancel: "取消"
confirm: "确认"
local_terminal: "本地终端"
open_local_shell_tab: "打开一个新的本地终端页面"
connect: "连接"
@@ -94,4 +107,7 @@ session: "会话"
software_builtin: "软件内置"
retry: "重试"
right_click_copy_paste: "右键复制/粘贴"
copy_paste_hint: "提示:不管是否开启此开关,都可以使用 %{key} + C/V 快捷键进行复制和粘贴。"
copy_paste_hint: "提示:不管是否开启此开关,都可以使用 %{key} + C/V 快捷键进行复制和粘贴。"
edit_file: "编辑文件"
edit_file_tooltip: "下载到临时目录,使用默认编辑器打开,并在保存后自动上传。"
auto_saved_and_uploaded: "已自动保存并上传: %{base}"
+17
View File
@@ -125,6 +125,8 @@ pub struct ConfigFile {
pub body_panels: Option<Vec<f32>>,
#[serde(default)]
pub transfers: Vec<crate::terminal::Transfer>,
#[serde(default)]
pub show_hidden_files: bool,
}
fn default_locale() -> String {
@@ -160,6 +162,9 @@ impl ConfigStore {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)
.with_context(|| format!("failed to create config dir {}", parent.display()))?;
let tmp_dir = parent.join("tmp");
let _ = fs::remove_dir_all(&tmp_dir);
let _ = fs::create_dir_all(&tmp_dir);
}
let cache = if path.exists() {
@@ -193,6 +198,10 @@ impl ConfigStore {
&self.cache.sessions
}
pub fn tmp_dir(&self) -> Option<PathBuf> {
self.path.parent().map(|p| p.join("tmp"))
}
pub fn follow_system_theme(&self) -> bool {
self.cache.follow_system_theme
}
@@ -324,6 +333,14 @@ impl ConfigStore {
self.cache.terminal_font_family = family.to_string();
}
pub fn show_hidden_files(&self) -> bool {
self.cache.show_hidden_files
}
pub fn set_show_hidden_files(&mut self, val: bool) {
self.cache.show_hidden_files = val;
}
pub fn get(&self, id: &str) -> Option<&Session> {
self.cache.sessions.iter().find(|s| s.id == id)
}
+367 -31
View File
@@ -171,6 +171,9 @@ struct Ashell {
connection_progress: Option<ConnectionProgress>,
pending_sftp_path_sync: Option<String>,
sftp_context_menu: Option<SftpContextMenuState>,
sftp_creating_folder: bool,
sftp_new_folder_input: Entity<InputState>,
sftp_delete_scroll_handle: gpui::ScrollHandle,
show_hidden_files: bool,
transfers: Vec<crate::terminal::Transfer>,
show_transfers_dialog: bool,
@@ -235,6 +238,7 @@ impl Ashell {
.placeholder("-----BEGIN OPENSSH PRIVATE KEY-----")
});
let sftp_path_input = cx.new(|cx| InputState::new(window, cx).default_value("/"));
let sftp_new_folder_input = cx.new(|cx| InputState::new(window, cx).placeholder(t!("new_folder").to_string()));
let _subscriptions = vec![
cx.subscribe_in(&host_input, window, Self::on_input_event),
@@ -245,6 +249,7 @@ impl Ashell {
cx.subscribe_in(&key_path_input, window, Self::on_input_event),
cx.subscribe_in(&key_inline_input, window, Self::on_input_event),
cx.subscribe_in(&sftp_path_input, window, Self::on_input_event),
cx.subscribe_in(&sftp_new_folder_input, window, Self::on_input_event),
];
let (events_tx, events_rx) = mpsc::channel();
@@ -330,7 +335,10 @@ impl Ashell {
connection_progress: None,
pending_sftp_path_sync: Some("/".into()),
sftp_context_menu: None,
show_hidden_files: false,
sftp_creating_folder: false,
sftp_new_folder_input,
sftp_delete_scroll_handle: gpui::ScrollHandle::new(),
show_hidden_files: config.show_hidden_files(),
transfers: config.transfers(),
show_transfers_dialog: false,
system_status: None,
@@ -377,6 +385,28 @@ impl Ashell {
window.prevent_default();
cx.stop_propagation();
}
} else if input == &self.sftp_new_folder_input {
match event {
InputEvent::PressEnter { .. } => {
let name = self.sftp_new_folder_input.read(cx).text().to_string();
if !name.is_empty() {
let base_path = self.sftp_path_input.read(cx).text().to_string();
let path = crate::sftp::join_remote(&base_path, &name);
if let Some(id) = self.active_tab.clone() {
if let Some(handle) = self.sftp_handles.get(&id) {
let _ = handle.commands.send(crate::sftp::SftpCommand::CreateDir(path));
}
}
}
self.sftp_creating_folder = false;
window.prevent_default();
cx.stop_propagation();
}
InputEvent::Blur => {
self.sftp_creating_folder = false;
}
_ => {}
}
}
cx.notify();
}
@@ -517,6 +547,13 @@ impl Ashell {
}
self.status = reason.into();
}
BackendEvent::SftpHome { tab_id, home } => {
if let Some(tab) = self.tabs.iter_mut().find(|t| t.id == tab_id) {
if let Some(sftp) = tab.sftp.as_mut() {
sftp.home_dir = home;
}
}
}
BackendEvent::TerminalTitleChanged { tab_id, title } => {
if let Some(tab) = self.tabs.iter_mut().find(|t| t.id == tab_id) {
if let Some(sftp) = &tab.sftp {
@@ -527,7 +564,14 @@ impl Ashell {
};
if potential_path.starts_with('/') || potential_path.starts_with('~') {
let path_to_sync = potential_path.to_string();
let path_to_sync = if potential_path == "~" {
sftp.home_dir.clone()
} else if let Some(rest) = potential_path.strip_prefix("~/") {
crate::sftp::join_remote(&sftp.home_dir, rest)
} else {
potential_path.to_string()
};
if path_to_sync != sftp.current_path {
if let Some(handle) = self.sftp_handles.get(&tab_id) {
handle.list_dir(path_to_sync);
@@ -775,12 +819,21 @@ impl Ashell {
self.show_ssh_dialog(window, cx);
}
fn terminal_cell_width(&self) -> f32 {
(self.terminal_font_size * 0.646).max(6.0)
fn terminal_cell_width(&self, window: &Window) -> f32 {
let font_id = window.text_system().resolve_font(&gpui::Font {
family: self.terminal_font_family.clone(),
..gpui::Font::default()
});
window
.text_system()
.advance(font_id, px(self.terminal_font_size), 'm')
.map(|a| a.width.as_f32())
.unwrap_or(self.terminal_font_size * 0.646)
.max(6.0)
}
fn terminal_line_height(&self) -> f32 {
(self.terminal_font_size * 1.385).max(self.terminal_font_size + 2.0)
(self.terminal_font_size * 1.3).max(self.terminal_font_size + 2.0)
}
fn change_terminal_font_size(&mut self, delta: f32, cx: &mut Context<Self>) {
@@ -1385,6 +1438,177 @@ impl Ashell {
});
}
fn show_delete_confirm_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let view = cx.entity();
let selected_entries = self.active_sftp().map(|s| s.selected_entries.clone()).unwrap_or_default();
if selected_entries.is_empty() {
return;
}
let has_system_path = selected_entries.iter().any(|path| {
let p = path.as_str();
p.starts_with("/bin/") || p == "/bin" ||
p.starts_with("/etc/") || p == "/etc" ||
p.starts_with("/usr/") || p == "/usr" ||
p.starts_with("/var/") || p == "/var" ||
p.starts_with("/sys/") || p == "/sys" ||
p.starts_with("/dev/") || p == "/dev" ||
p.starts_with("/boot/") || p == "/boot" ||
p.starts_with("/lib/") || p == "/lib" ||
p.starts_with("/opt/") || p == "/opt" ||
p.starts_with("/run/") || p == "/run" ||
p.starts_with("/sbin/") || p == "/sbin"
});
window.open_dialog(cx, move |dialog: Dialog, _window, _| {
dialog
.title(t!("confirm_delete").to_string())
.w(px(500.))
.keyboard(false)
.on_ok({
let view = view.clone();
let paths_to_delete: Vec<String> = selected_entries.clone().into_iter().collect();
move |_, window, cx| {
view.update(cx, |this, cx| {
if let Some(id) = this.active_tab.clone() {
if let Some(handle) = this.sftp_handles.get(&id) {
let _ = handle.commands.send(crate::sftp::SftpCommand::DeletePaths(paths_to_delete.clone()));
}
if let Some(tab) = this.tabs.iter_mut().find(|t| t.id == id) {
if let Some(sftp) = tab.sftp.as_mut() {
sftp.selected_entries.clear();
}
}
}
cx.notify();
});
window.close_dialog(cx);
true
}
})
.content({
let view = view.clone();
move |content, _window, cx| {
let scroll_handle = view.read(cx).sftp_delete_scroll_handle.clone();
let selected_paths: Vec<String> = view.read(cx)
.active_sftp()
.map(|s| s.selected_entries.clone().into_iter().collect())
.unwrap_or_default();
let warning_block = if has_system_path {
Some(
div()
.w_full()
.p_3()
.mb_3()
.rounded_md()
.bg(gpui::rgba(0xff00001a))
.border_1()
.border_color(gpui::rgba(0xff000080))
.child(
div()
.text_color(gpui::rgba(0xff0000ff))
.font_weight(FontWeight::BOLD)
.child(t!("system_path_warning").to_string())
)
)
} else {
None
};
let paths_list = div()
.relative()
.max_h(px(200.))
.w_full()
.border_1()
.border_color(cx.theme().border)
.bg(cx.theme().background)
.rounded_md()
.child(
v_flex()
.id("delete-scroll-view")
.size_full()
.track_scroll(&scroll_handle)
.overflow_y_scroll()
.p_2()
.gap_1()
.children(selected_paths.into_iter().map(|path| {
div()
.text_size(rems(0.917))
.text_color(cx.theme().muted_foreground)
.child(path)
}))
)
.child(
div()
.absolute()
.top_0()
.bottom_0()
.right_0()
.child(
gpui_component::scroll::Scrollbar::vertical(&scroll_handle)
.scrollbar_show(gpui_component::scroll::ScrollbarShow::Always)
)
);
content.child(
v_flex()
.w_full()
.gap_2()
.children(warning_block)
.child(
div()
.text_size(rems(1.0))
.mb_2()
.child(t!("confirm_delete_desc", count = view.read(cx).active_sftp().map(|s| s.selected_entries.len()).unwrap_or(0)).to_string())
)
.child(paths_list)
)
}
})
.footer({
let view = view.clone();
let paths_to_delete: Vec<String> = selected_entries.clone().into_iter().collect();
h_flex()
.w_full()
.justify_end()
.gap_2()
.child(
Button::new("cancel")
.ghost()
.label(t!("cancel").to_string())
.on_click(move |_, window, cx| {
window.close_dialog(cx);
}),
)
.child(
Button::new("confirm")
.danger()
.label(t!("confirm").to_string())
.on_click({
let view = view.clone();
move |_, window, cx| {
view.update(cx, |this, cx| {
if let Some(id) = this.active_tab.clone() {
if let Some(handle) = this.sftp_handles.get(&id) {
let _ = handle.commands.send(crate::sftp::SftpCommand::DeletePaths(paths_to_delete.clone()));
}
if let Some(tab) = this.tabs.iter_mut().find(|t| t.id == id) {
if let Some(sftp) = tab.sftp.as_mut() {
sftp.selected_entries.clear();
}
}
}
cx.notify();
});
window.close_dialog(cx);
}
}),
)
})
});
}
fn show_settings_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let view = cx.entity();
window.open_dialog(cx, move |dialog: Dialog, _window, _| {
@@ -2154,6 +2378,18 @@ impl Ashell {
cx.notify();
}
fn trigger_sftp_context_edit(&mut self, cx: &mut Context<Self>) {
let Some(menu) = self.sftp_context_menu.take() else {
return;
};
if let Some(id) = self.active_tab.clone() {
if let Some(handle) = self.sftp_handles.get(&id) {
handle.edit_file(menu.remote_path);
}
}
cx.notify();
}
fn download_sftp_entry(
&mut self,
remote_path: String,
@@ -2556,18 +2792,20 @@ impl Ashell {
&self,
range_utf16: Range<usize>,
element_bounds: Bounds<Pixels>,
cell_width: f32,
line_height: f32,
) -> Option<Bounds<Pixels>> {
let snapshot = self.active_snapshot()?;
let cursor = snapshot.cursor?;
let x = element_bounds.origin.x
+ px(self.terminal_cell_width()) * cursor.col as f32
+ px(self.terminal_cell_width()) * range_utf16.start as f32;
let y = element_bounds.origin.y + px(self.terminal_line_height()) * cursor.row as f32;
+ px(cell_width) * cursor.col as f32
+ px(cell_width) * range_utf16.start as f32;
let y = element_bounds.origin.y + px(line_height) * cursor.row as f32;
Some(Bounds::new(
point(x, y),
size(
px(self.terminal_cell_width()),
px(self.terminal_line_height()),
px(cell_width),
px(line_height),
),
))
}
@@ -2580,7 +2818,7 @@ impl Ashell {
) {
self.focus_handle.focus(window, cx);
if event.button == MouseButton::Left {
self.begin_terminal_selection(event, cx);
self.begin_terminal_selection(event, window, cx);
}
cx.notify();
}
@@ -2622,7 +2860,7 @@ impl Ashell {
}
}
fn begin_terminal_selection(&mut self, event: &MouseDownEvent, cx: &mut Context<Self>) {
fn begin_terminal_selection(&mut self, event: &MouseDownEvent, window: &Window, cx: &mut Context<Self>) {
let click_count = event.click_count.max(1);
let selection_type = match click_count {
1 => SelectionType::Simple,
@@ -2630,7 +2868,7 @@ impl Ashell {
3 => SelectionType::Lines,
_ => SelectionType::Simple,
};
let Some((row, col, side)) = self.terminal_grid_point_and_side(event.position) else {
let Some((row, col, side)) = self.terminal_grid_point_and_side(event.position, window) else {
return;
};
let Some(active_id) = self.active_tab.clone() else {
@@ -2646,13 +2884,13 @@ impl Ashell {
fn on_terminal_mouse_move(
&mut self,
event: &MouseMoveEvent,
_window: &mut Window,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.terminal_selecting || event.pressed_button != Some(MouseButton::Left) {
return;
}
let Some((row, col, side)) = self.terminal_grid_point_and_side(event.position) else {
let Some((row, col, side)) = self.terminal_grid_point_and_side(event.position, window) else {
return;
};
let Some(active_id) = self.active_tab.clone() else {
@@ -2667,7 +2905,7 @@ impl Ashell {
fn on_terminal_mouse_up(
&mut self,
_event: &MouseUpEvent,
_window: &mut Window,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.terminal_selecting = false;
@@ -2677,6 +2915,7 @@ impl Ashell {
fn terminal_grid_point_and_side(
&self,
position: Point<Pixels>,
window: &Window,
) -> Option<(usize, usize, Side)> {
let bounds = self.terminal_bounds?;
if !bounds.contains(&position) {
@@ -2684,7 +2923,7 @@ impl Ashell {
}
let local_x = (position.x - bounds.origin.x).max(px(0.));
let local_y = (position.y - bounds.origin.y).max(px(0.));
let cell_width = px(self.terminal_cell_width());
let cell_width = px(self.terminal_cell_width(window));
let line_height = px(self.terminal_line_height());
let snapshot = self.active_snapshot()?;
let max_col = snapshot.cols.saturating_sub(1);
@@ -2857,9 +3096,9 @@ impl Ashell {
.map(|size| size.as_f32())
.unwrap_or(viewport.height.as_f32() - TAB_BAR_HEIGHT - 248.0);
let width = (viewport.width.as_f32() - sidebar_width - TERMINAL_PADDING_X - 8.0)
.max(self.terminal_cell_width());
.max(self.terminal_cell_width(window));
let height = (terminal_height - TERMINAL_PADDING_Y).max(self.terminal_line_height());
let cols = (width / self.terminal_cell_width()).floor().max(1.0) as u16;
let cols = (width / self.terminal_cell_width(window)).floor().max(1.0) as u16;
let rows = (height / self.terminal_line_height()).floor().max(1.0) as u16;
for tab in &mut self.tabs {
@@ -3242,6 +3481,36 @@ impl Ashell {
.label(t!("refresh").to_string())
.on_click(cx.listener(|this, _, _, cx| this.refresh_sftp(cx))),
)
.child(
Button::new("sftp-new-folder")
.ghost()
.small()
.icon(IconName::Folder)
.label(t!("new_folder").to_string())
.on_click(cx.listener(|this, _, window, cx| {
this.sftp_creating_folder = true;
this.sftp_new_folder_input.update(cx, |input, cx| {
input.set_value("", window, cx);
input.focus_handle(cx).focus(window, cx);
});
cx.notify();
})),
)
.child(
Button::new("sftp-delete-selected")
.ghost()
.small()
.icon(IconName::Close)
.label(if selected_entries.is_empty() {
t!("delete_selected").to_string()
} else {
format!("{} ({})", t!("delete_selected").to_string(), selected_entries.len())
})
.disabled(selected_entries.is_empty())
.on_click(cx.listener(|this, _, window, cx| {
this.show_delete_confirm_dialog(window, cx);
})),
)
.child(
Button::new("sftp-upload-file")
.ghost()
@@ -3285,6 +3554,8 @@ impl Ashell {
.tab_stop(false)
.on_click(cx.listener(|this, checked, _, cx| {
this.show_hidden_files = *checked;
this.config.set_show_hidden_files(*checked);
let _ = this.config.save();
cx.notify();
})),
)
@@ -3442,14 +3713,48 @@ impl Ashell {
.w_full()
.relative()
.child(
uniform_list("remote-files-list", entries.len(), {
uniform_list("remote-files-list", entries.len() + if self.sftp_creating_folder { 1 } else { 0 }, {
let entries = entries.clone();
let selected_path = selected_path.clone();
let view = view.clone();
let creating_folder = self.sftp_creating_folder;
let new_folder_input = self.sftp_new_folder_input.clone();
move |visible_range, window, cx| {
visible_range
.map(|ix| {
let entry = entries[ix].clone();
if creating_folder && ix == 0 {
return h_flex()
.w_full()
.h(px(28.))
.items_center()
.gap_2()
.px_3()
.bg(cx.theme().tab_active)
.border_b_1()
.border_color(cx.theme().border.opacity(0.35))
.child(
h_flex()
.w(px(24.))
.flex_none()
.items_center()
.justify_center(),
)
.child(
div()
.w(px(24.))
.flex_none()
.text_size(rems(1.0))
.child("📁"),
)
.child(
gpui_component::input::Input::new(&new_folder_input)
.flex_1()
)
.into_any_element();
}
let actual_ix = if creating_folder { ix - 1 } else { ix };
let entry = entries[actual_ix].clone();
let left_row = entry.clone();
let right_row = entry.clone();
let remote_path = entry.full_path.clone();
@@ -4093,7 +4398,7 @@ impl Render for Ashell {
self.terminal_font_family.clone(),
px(self.terminal_font_size),
px(self.terminal_line_height()),
px(self.terminal_cell_width()),
px(self.terminal_cell_width(window)),
),
)
.vertical_scrollbar(&self.terminal_scrollbar)
@@ -4118,9 +4423,9 @@ impl Render for Ashell {
.children(Root::render_sheet_layer(window, cx))
.when_some(self.sftp_context_menu.clone(), |this, menu| {
let label = if menu.is_dir {
"Download Folder"
t!("download_folder").to_string()
} else {
"Download"
t!("download").to_string()
};
this.child(
div()
@@ -4156,14 +4461,31 @@ impl Render for Ashell {
cx.stop_propagation();
})
.child(
Button::new("sftp-context-download")
.ghost()
v_flex()
.w_full()
.justify_start()
.label(label)
.on_click(cx.listener(|this, _, window, cx| {
this.trigger_sftp_context_download(window, cx);
})),
.child(
Button::new("sftp-context-download")
.ghost()
.w_full()
.justify_start()
.label(label)
.on_click(cx.listener(|this, _, window, cx| {
this.trigger_sftp_context_download(window, cx);
})),
)
.when(!menu.is_dir && is_editable_text_file(&menu.remote_path), |this| {
this.child(
Button::new("sftp-context-edit")
.ghost()
.w_full()
.justify_start()
.label(t!("edit_file"))
.tooltip(t!("edit_file_tooltip").to_string())
.on_click(cx.listener(|this, _, _, cx| {
this.trigger_sftp_context_edit(cx);
}))
)
}),
),
),
)
@@ -4471,3 +4793,17 @@ fn main() {
open_main_window(cx);
});
}
fn is_editable_text_file(filename: &str) -> bool {
let lower = filename.to_lowercase();
let ext = std::path::Path::new(&lower).extension().and_then(|s| s.to_str()).unwrap_or("");
let known_exts = ["txt", "conf", "json", "yaml", "yml", "xml", "ini", "sh", "py", "rs", "js", "ts", "html", "css", "md", "toml", "csv", "log", "cfg"];
if known_exts.contains(&ext) {
return true;
}
let known_names = ["dockerfile", "makefile", ".gitignore", ".env"];
if known_names.contains(&lower.as_str()) {
return true;
}
false
}
+429 -38
View File
@@ -58,6 +58,15 @@ pub enum SftpCommand {
remote: String,
local_dir: String,
},
EditFile {
remote_path: String,
},
CreateDir(String),
DeletePaths(Vec<String>),
UploadEditedFile {
local_path: String,
remote_path: String,
},
UploadPaths {
locals: Vec<String>,
remote_dir: String,
@@ -77,11 +86,17 @@ impl TransferStateFlag {
pub fn new() -> Self {
Self(Arc::new(AtomicU8::new(0)))
}
pub fn pause(&self) { self.0.store(1, Ordering::SeqCst); }
pub fn resume(&self) { self.0.store(0, Ordering::SeqCst); }
pub fn cancel(&self) { self.0.store(2, Ordering::SeqCst); }
pub fn pause(&self) {
self.0.store(1, Ordering::SeqCst);
}
pub fn resume(&self) {
self.0.store(0, Ordering::SeqCst);
}
pub fn cancel(&self) {
self.0.store(2, Ordering::SeqCst);
}
pub async fn yield_if_paused(
&self,
events: &std::sync::mpsc::Sender<crate::terminal::BackendEvent>,
@@ -161,6 +176,10 @@ impl SftpHandle {
.send(SftpCommand::UploadPaths { locals, remote_dir });
}
pub fn edit_file(&self, remote_path: String) {
let _ = self.commands.send(SftpCommand::EditFile { remote_path });
}
pub fn close(&self) {
let _ = self.commands.send(SftpCommand::Close);
}
@@ -187,7 +206,15 @@ pub fn spawn_sftp(
let (cmd_tx, cmd_rx) = mpsc::unbounded_channel();
let cmd_tx_clone = cmd_tx.clone();
let join = runtime.spawn(async move {
if let Err(err) = run_sftp(tab_id.clone(), session, cmd_rx, cmd_tx_clone, events.clone()).await {
if let Err(err) = run_sftp(
tab_id.clone(),
session,
cmd_rx,
cmd_tx_clone,
events.clone(),
)
.await
{
let _ = events.send(BackendEvent::SftpStatus {
tab_id,
text: format!("sftp error: {err:#}"),
@@ -229,9 +256,16 @@ async fn run_sftp(
.canonicalize(".")
.await
.unwrap_or_else(|_| "/".to_string());
let _ = events.send(BackendEvent::SftpHome {
tab_id: tab_id.clone(),
home: home.clone(),
});
emit_entries(&events, &tab_id, &sftp, &home).await?;
let mut active_transfers: std::collections::HashMap<String, TransferStateFlag> = std::collections::HashMap::new();
let mut active_transfers: std::collections::HashMap<String, TransferStateFlag> =
std::collections::HashMap::new();
while let Some(command) = commands.recv().await {
match command {
@@ -308,16 +342,33 @@ async fn run_sftp(
let commands_tx_clone = commands_tx.clone();
tokio::spawn(async move {
let Ok(channel) = handle_clone.channel_open_session().await else { return };
let Ok(_) = channel.request_subsystem(true, "sftp").await else { return };
let Ok(sftp_session) = SftpSession::new(channel.into_stream()).await else { return };
let Ok(channel) = handle_clone.channel_open_session().await else {
return;
};
let Ok(_) = channel.request_subsystem(true, "sftp").await else {
return;
};
let Ok(sftp_session) = SftpSession::new(channel.into_stream()).await else {
return;
};
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone.clone(),
text: t!("downloading_file", base = base_name(&remote)).to_string(),
});
match download_path_impl(&handle_clone, &sftp_session, &remote, Path::new(&local_dir), flag, &events_clone, &tab_id_clone, &id).await {
match download_path_impl(
&handle_clone,
&sftp_session,
&remote,
Path::new(&local_dir),
flag,
&events_clone,
&tab_id_clone,
&id,
)
.await
{
Ok(summary) => {
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone,
@@ -364,7 +415,12 @@ async fn run_sftp(
} else if file_count == 0 && folder_count > 0 {
t!("n_folders", folders = folder_count).to_string()
} else {
t!("n_files_and_folders", files = file_count, folders = folder_count).to_string()
t!(
"n_files_and_folders",
files = file_count,
folders = folder_count
)
.to_string()
}
};
@@ -387,16 +443,32 @@ async fn run_sftp(
let commands_tx_clone = commands_tx.clone();
tokio::spawn(async move {
let Ok(channel) = handle_clone.channel_open_session().await else { return };
let Ok(_) = channel.request_subsystem(true, "sftp").await else { return };
let Ok(sftp_session) = SftpSession::new(channel.into_stream()).await else { return };
let Ok(channel) = handle_clone.channel_open_session().await else {
return;
};
let Ok(_) = channel.request_subsystem(true, "sftp").await else {
return;
};
let Ok(sftp_session) = SftpSession::new(channel.into_stream()).await else {
return;
};
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone.clone(),
text: t!("uploading").to_string(),
});
match upload_paths_impl(&sftp_session, &locals, &remote_dir, flag, &events_clone, &tab_id_clone, &id).await {
match upload_paths_impl(
&sftp_session,
&locals,
&remote_dir,
flag,
&events_clone,
&tab_id_clone,
&id,
)
.await
{
Ok(summary) => {
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone.clone(),
@@ -422,6 +494,223 @@ async fn run_sftp(
let _ = commands_tx_clone.send(SftpCommand::TransferFinished(id));
});
}
SftpCommand::EditFile { remote_path } => {
let id = uuid::Uuid::new_v4().to_string();
let config = crate::config::ConfigStore::load().unwrap();
let tmp_dir = config.tmp_dir().unwrap_or_else(|| PathBuf::from("/tmp"));
let base = base_name(&remote_path);
let local_path = tmp_dir.join(format!("{}-{}", id, base));
let handle_clone = handle.clone();
let commands_tx_clone = commands_tx.clone();
let events_clone = events.clone();
let tab_id_clone = tab_id.clone();
tokio::spawn(async move {
let flag = TransferStateFlag::new();
let Ok(channel) = handle_clone.channel_open_session().await else {
return;
};
let Ok(_) = channel.request_subsystem(true, "sftp").await else {
return;
};
let Ok(sftp_session) = SftpSession::new(channel.into_stream()).await else {
return;
};
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone.clone(),
text: t!("downloading_file", base = base).to_string(),
});
if let Err(err) = download_file_impl(
&sftp_session,
&remote_path,
&local_path,
&flag,
&events_clone,
&tab_id_clone,
"edit-download",
)
.await
{
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone.clone(),
text: format!("Edit download failed: {err:#}"),
});
return;
}
if let Err(err) = open::that(&local_path) {
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone.clone(),
text: format!("Failed to open editor: {err:#}"),
});
return;
}
use notify::Watcher;
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
let mut watcher = match notify::recommended_watcher(
move |res: notify::Result<notify::Event>| {
if let Ok(event) = res {
if event.kind.is_modify() {
let _ = tx.send(());
}
}
},
) {
Ok(w) => w,
Err(_) => return,
};
if let Err(_) = watcher.watch(&local_path, notify::RecursiveMode::NonRecursive)
{
return;
}
while let Some(_) = rx.recv().await {
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
while let Ok(_) = rx.try_recv() {} // drain pending
if commands_tx_clone.send(SftpCommand::UploadEditedFile {
local_path: local_path.to_string_lossy().to_string(),
remote_path: remote_path.clone(),
}).is_err() {
break;
}
}
});
}
SftpCommand::UploadEditedFile {
local_path,
remote_path,
} => {
let handle_clone = handle.clone();
let events_clone = events.clone();
let tab_id_clone = tab_id.clone();
tokio::spawn(async move {
let flag = TransferStateFlag::new();
let Ok(channel) = handle_clone.channel_open_session().await else {
return;
};
let Ok(_) = channel.request_subsystem(true, "sftp").await else {
return;
};
let Ok(sftp_session) = SftpSession::new(channel.into_stream()).await else {
return;
};
let transferred = Arc::new(AtomicU64::new(0));
match upload_file_impl(
&sftp_session,
Path::new(&local_path),
&remote_path,
&flag,
&events_clone,
&tab_id_clone,
"edit-upload",
transferred,
None,
)
.await
{
Ok(_) => {
let now = chrono::Local::now().format("%H:%M:%S");
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone.clone(),
text: format!("{} ({})", t!("auto_saved_and_uploaded", base = base_name(&remote_path)), now),
});
}
Err(err) => {
let _ = events_clone.send(BackendEvent::SftpStatus {
tab_id: tab_id_clone.clone(),
text: format!("Auto-upload failed: {err:#}"),
});
}
}
});
}
SftpCommand::CreateDir(path) => {
let actual_path = if path == "~" {
home.clone()
} else if let Some(rest) = path.strip_prefix("~/") {
crate::sftp::join_remote(&home, rest)
} else {
path.clone()
};
match sftp.create_dir(&actual_path).await {
Ok(_) => {
let _ = events.send(BackendEvent::SftpStatus {
tab_id: tab_id.clone(),
text: t!("create_folder_success", name = base_name(&actual_path)).to_string(),
});
// Re-fetch the parent directory to show the newly created folder
if let Some(parent) = parent_dir(&actual_path) {
let _ = commands_tx.send(SftpCommand::ListDir(parent));
} else {
let _ = commands_tx.send(SftpCommand::ListDir("/".to_string()));
}
}
Err(err) => {
let _ = events.send(BackendEvent::SftpStatus {
tab_id: tab_id.clone(),
text: t!("create_folder_failed", err = format!("{err:#}")).to_string(),
});
}
}
}
SftpCommand::DeletePaths(paths) => {
let _ = events.send(BackendEvent::SftpStatus {
tab_id: tab_id.clone(),
text: t!("deleting_paths", count = paths.len()).to_string(),
});
let mut errors = Vec::new();
for path in paths.clone() {
let actual_path = if path == "~" {
home.clone()
} else if let Some(rest) = path.strip_prefix("~/") {
crate::sftp::join_remote(&home, rest)
} else {
path.clone()
};
if let Err(e) = recursive_delete(&sftp, actual_path).await {
errors.push(format!("{path}: {e:#}"));
}
}
if errors.is_empty() {
let _ = events.send(BackendEvent::SftpStatus {
tab_id: tab_id.clone(),
text: t!("delete_success", count = paths.len()).to_string(),
});
} else {
let _ = events.send(BackendEvent::SftpStatus {
tab_id: tab_id.clone(),
text: t!("delete_failed", err = errors.join(", ")).to_string(),
});
}
if let Some(first) = paths.first() {
let actual_path = if first == "~" {
home.clone()
} else if let Some(rest) = first.strip_prefix("~/") {
crate::sftp::join_remote(&home, rest)
} else {
first.clone()
};
if let Some(parent) = parent_dir(&actual_path) {
let _ = commands_tx.send(SftpCommand::ListDir(parent));
} else {
let _ = commands_tx.send(SftpCommand::ListDir("/".to_string()));
}
}
}
}
}
@@ -431,6 +720,43 @@ async fn run_sftp(
Ok(())
}
use std::future::Future;
use std::pin::Pin;
fn recursive_delete<'a>(
sftp: &'a SftpSession,
path: String,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> {
Box::pin(async move {
match sftp.read_dir(&path).await {
Ok(entries) => {
for entry in entries {
let name = entry.file_name();
if name == "." || name == ".." {
continue;
}
let child_path = crate::sftp::join_remote(&path, &name);
let meta = entry.metadata();
let permissions = meta.permissions.unwrap_or(0);
let is_dir = (permissions & 0o170_000) == 0o040_000;
if is_dir {
recursive_delete(sftp, child_path).await?;
} else {
sftp.remove_file(&child_path).await.with_context(|| format!("Failed to delete file {child_path}"))?;
}
}
sftp.remove_dir(&path).await.with_context(|| format!("Failed to delete dir {path}"))?;
}
Err(_) => {
sftp.remove_file(&path).await.with_context(|| format!("Failed to delete {path}"))?;
}
}
Ok(())
})
}
async fn emit_entries(
events: &std::sync::mpsc::Sender<BackendEvent>,
tab_id: &str,
@@ -571,7 +897,23 @@ fn base_name(path: &str) -> String {
.to_string()
}
fn join_remote(parent: &str, child: &str) -> String {
pub(crate) fn parent_dir(path: &str) -> Option<String> {
if path == "/" || path.is_empty() {
return None;
}
let trimmed = path.trim_end_matches('/');
if let Some(idx) = trimmed.rfind('/') {
if idx == 0 {
Some("/".to_string())
} else {
Some(trimmed[..idx].to_string())
}
} else {
Some("/".to_string())
}
}
pub(crate) fn join_remote(parent: &str, child: &str) -> String {
if parent == "/" {
format!("/{child}")
} else {
@@ -736,8 +1078,17 @@ async fn download_path_impl(
base_name(remote),
Uuid::new_v4()
));
let extracted_to =
download_remote_directory_archive(handle, sftp, remote, &local_archive, &flag, events, tab_id, id).await?;
let extracted_to = download_remote_directory_archive(
handle,
sftp,
remote,
&local_archive,
&flag,
events,
tab_id,
id,
)
.await?;
return Ok(t!("downloaded_folder", path = extracted_to.display()).to_string());
}
@@ -763,9 +1114,27 @@ async fn download_dir_recursive(
for entry in entries {
let local_path = local_dir.join(&entry.name);
if entry.is_dir {
Box::pin(download_dir_recursive(sftp, &entry.full_path, &local_path, flag, events, tab_id, id)).await?;
Box::pin(download_dir_recursive(
sftp,
&entry.full_path,
&local_path,
flag,
events,
tab_id,
id,
))
.await?;
} else {
download_file_impl(sftp, &entry.full_path, &local_path, flag, events, tab_id, id).await?;
download_file_impl(
sftp,
&entry.full_path,
&local_path,
flag,
events,
tab_id,
id,
)
.await?;
let _ = maybe_extract_archive(&local_path).await;
}
}
@@ -794,7 +1163,16 @@ async fn download_remote_directory_archive(
.join(base_name(remote_dir));
let archive_download = async {
download_file_impl(sftp, &remote_archive, local_archive, flag, events, tab_id, id).await?;
download_file_impl(
sftp,
&remote_archive,
local_archive,
flag,
events,
tab_id,
id,
)
.await?;
extract_archive_to(
local_archive,
local_archive.parent().unwrap_or_else(|| Path::new(".")),
@@ -839,7 +1217,8 @@ async fn download_file_impl(
let mut buffer = vec![0u8; 128 * 1024];
loop {
flag.yield_if_paused(events, tab_id, id, transferred, total).await?;
flag.yield_if_paused(events, tab_id, id, transferred, total)
.await?;
let read = remote_file
.read(&mut buffer)
.await
@@ -851,7 +1230,7 @@ async fn download_file_impl(
.write_all(&buffer[..read])
.await
.with_context(|| format!("write {}", local.display()))?;
transferred += read as u64;
let _ = events.send(BackendEvent::TransferProgress {
tab_id: tab_id.to_string(),
@@ -862,7 +1241,7 @@ async fn download_file_impl(
});
}
local_file.flush().await.context("flush local file")?;
let _ = events.send(BackendEvent::TransferProgress {
tab_id: tab_id.to_string(),
id: id.to_string(),
@@ -870,7 +1249,7 @@ async fn download_file_impl(
total,
state: crate::terminal::TransferState::Completed,
});
Ok(())
}
@@ -886,7 +1265,7 @@ async fn upload_paths_impl(
create_remote_dir_all(sftp, remote_dir).await?;
let mut file_count = 0usize;
let mut folder_count = 0usize;
let mut total_bytes = 0u64;
let mut files_to_upload = Vec::new();
let mut dirs_to_create = Vec::new();
@@ -902,14 +1281,20 @@ async fn upload_paths_impl(
for entry in WalkDir::new(&p) {
let entry = entry?;
let path = entry.path();
if path == p { continue; }
if path == p {
continue;
}
if let Ok(meta) = tokio::fs::metadata(&path).await {
let relative = path.strip_prefix(&p)?;
let remote_path = if relative.as_os_str().is_empty() {
remote_root.clone()
} else {
let rel = relative.components().map(|c| c.as_os_str().to_string_lossy().to_string()).collect::<Vec<_>>().join("/");
let rel = relative
.components()
.map(|c| c.as_os_str().to_string_lossy().to_string())
.collect::<Vec<_>>()
.join("/");
join_remote(&remote_root, &rel)
};
@@ -955,7 +1340,8 @@ async fn upload_paths_impl(
&id_clone,
transferred_clone,
Some(total_bytes),
).await
)
.await
});
}
@@ -964,7 +1350,7 @@ async fn upload_paths_impl(
while let Some(res) = stream.next().await {
res?;
}
let _ = events.send(BackendEvent::TransferProgress {
tab_id: tab_id.to_string(),
id: id.to_string(),
@@ -972,7 +1358,7 @@ async fn upload_paths_impl(
total: Some(total_bytes),
state: crate::terminal::TransferState::Completed,
});
let summary = if file_count == 1 && folder_count == 0 {
t!("uploaded_file").to_string()
} else if file_count == 0 && folder_count == 1 {
@@ -982,14 +1368,19 @@ async fn upload_paths_impl(
} else if file_count == 0 && folder_count > 0 {
t!("uploaded_n_folders", folders = folder_count).to_string()
} else {
t!("uploaded_files_and_folders", files = file_count, folders = folder_count).to_string()
t!(
"uploaded_files_and_folders",
files = file_count,
folders = folder_count
)
.to_string()
};
Ok(summary)
}
async fn upload_file_impl(
sftp: &SftpSession,
local_file: &Path,
sftp: &SftpSession,
local_file: &Path,
remote_path: &str,
flag: &TransferStateFlag,
events: &std::sync::mpsc::Sender<BackendEvent>,
@@ -1018,7 +1409,7 @@ async fn upload_file_impl(
.write_all(&buffer[..read])
.await
.with_context(|| format!("write remote {remote_path}"))?;
let new_cur = transferred.fetch_add(read as u64, Ordering::Relaxed) + read as u64;
let _ = events.send(BackendEvent::TransferProgress {
tab_id: tab_id.to_string(),
+6
View File
@@ -61,6 +61,10 @@ pub enum BackendEvent {
tab_id: String,
reason: String,
},
SftpHome {
tab_id: String,
home: String,
},
TransferProgress {
#[allow(dead_code)]
tab_id: String,
@@ -159,6 +163,7 @@ pub struct SftpUiState {
pub selected_path: Option<String>,
pub preview: Option<PreviewData>,
pub selected_entries: std::collections::HashSet<String>,
pub home_dir: String,
}
impl TerminalTab {
@@ -204,6 +209,7 @@ impl TerminalTab {
selected_path: None,
preview: None,
selected_entries: std::collections::HashSet::new(),
home_dir: "/".into(),
});
tab
}
+5 -1
View File
@@ -144,6 +144,8 @@ pub struct PrepaintState {
struct TerminalInputHandler {
view: Entity<Ashell>,
element_bounds: Bounds<Pixels>,
cell_width: f32,
line_height: f32,
}
impl InputHandler for TerminalInputHandler {
@@ -219,7 +221,7 @@ impl InputHandler for TerminalInputHandler {
) -> Option<Bounds<Pixels>> {
self.view
.read(cx)
.terminal_ime_bounds_for_range(range_utf16, self.element_bounds)
.terminal_ime_bounds_for_range(range_utf16, self.element_bounds, self.cell_width, self.line_height)
}
fn character_index_for_point(
@@ -492,6 +494,8 @@ impl Element for TerminalElement {
TerminalInputHandler {
view: self.view.clone(),
element_bounds: prepaint.bounds,
cell_width: prepaint.metrics.cell_width.as_f32(),
line_height: prepaint.metrics.line_height.as_f32(),
},
cx,
);