aboutsummaryrefslogtreecommitdiffstats
path: root/default-plugins/strider/src/state.rs
diff options
context:
space:
mode:
authordivens <divens@users.noreply.github.com>2026-03-21 19:20:32 +0100
committerGitHub <noreply@github.com>2026-03-21 19:20:32 +0100
commit3fa7744906d5704bdec771c74829841bd06cf7fc (patch)
tree6c4f0bd64c2e6087ce069a466cca942f4669f513 /default-plugins/strider/src/state.rs
parentRelease notes and fixes (#4879) (diff)
downloadsl0ppij-3fa7744906d5704bdec771c74829841bd06cf7fc.tar.gz
sl0ppij-3fa7744906d5704bdec771c74829841bd06cf7fc.tar.xz
sl0ppij-3fa7744906d5704bdec771c74829841bd06cf7fc.zip
Add windows support in strider (#4854)
* Add Windows path support to strider plugin Strider is a WASM plugin where std::path::PathBuf uses Unix semantics, so Windows backslash paths break parent(), join(), strip_prefix(), etc. Fix by normalizing all incoming paths to forward slashes at plugin boundaries and converting back to native backslashes for display. A new platform.rs module detects the host OS at runtime from the initial_cwd format and centralizes all platform-aware logic. Also fix scan_host_folder on the server side: canonicalize plugin_host_folder so the starts_with security check works on Windows, where canonicalize() adds the \?\ prefix. * Add virtual root view for drive and WSL navigation in strider On Windows, navigating up from a drive root (e.g. C:\) now shows a "Computer" view listing all available drives and WSL distributions. Drives are enumerated via GetLogicalDriveStringsW and WSL distros via `wsl -l -q` (since read_dir on \wsl.localhost fails with OS error 64/67). Drive letters appear before WSL entries, which are displayed as "Ubuntu-24.04 (WSL)" etc. On non-Windows platforms, behavior is unchanged. * Rename ListHostEntries to ListWindowsVolumes and gate behind FullHdAccess The old name was misleading — on Unix it just returned `/`, which isn't "listing host entries." Rename to ListWindowsVolumes to make the Windows-specific intent explicit, gate behind FullHdAccess permission, and replace the Unix implementation with a log::error since the command is not meaningful on non-Windows platforms. * Replace direct array indexing with .get() in strider platform detection Use safe accessors and matches! macro instead of direct byte indexing for bounds-checked access patterns. --------- Co-authored-by: divens <divens.dev@gmail.com>
Diffstat (limited to 'default-plugins/strider/src/state.rs')
-rw-r--r--default-plugins/strider/src/state.rs156
1 files changed, 146 insertions, 10 deletions
diff --git a/default-plugins/strider/src/state.rs b/default-plugins/strider/src/state.rs
index 7932764a..a2c03a76 100644
--- a/default-plugins/strider/src/state.rs
+++ b/default-plugins/strider/src/state.rs
@@ -1,10 +1,12 @@
use crate::file_list_view::{FileListView, FsEntry};
+use crate::platform::Platform;
use crate::search_view::SearchView;
-use crate::shared::calculate_list_bounds;
+use crate::shared::{calculate_list_bounds, render_list_tip};
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};
+use unicode_width::UnicodeWidthStr;
use zellij_tile::prelude::*;
#[derive(Default)]
@@ -18,10 +20,20 @@ pub struct State {
pub is_searching: bool,
pub search_term: String,
pub close_on_selection: bool,
+ pub platform: Platform,
+ pub is_in_virtual_root: bool,
+ pub virtual_root_entries: Vec<FsEntry>,
+ pub virtual_root_selected: usize,
}
impl State {
pub fn update_search_term(&mut self, character: char) {
+ if self.is_in_virtual_root {
+ if character == '/' {
+ self.descend_to_root_path();
+ }
+ return;
+ }
self.search_term.push(character);
if &self.search_term == ".." {
self.descend_to_previous_path();
@@ -34,6 +46,9 @@ impl State {
}
}
pub fn handle_backspace(&mut self) {
+ if self.is_in_virtual_root {
+ return;
+ }
if self.search_term.is_empty() {
self.descend_to_previous_path();
} else {
@@ -52,6 +67,9 @@ impl State {
self.is_searching = false;
}
pub fn clear_search_term_or_descend(&mut self) {
+ if self.is_in_virtual_root {
+ return;
+ }
if self.search_term.is_empty() {
self.descend_to_previous_path();
} else {
@@ -62,14 +80,23 @@ impl State {
}
}
pub fn move_selection_up(&mut self) {
- if self.is_searching {
+ if self.is_in_virtual_root {
+ self.virtual_root_selected = self.virtual_root_selected.saturating_sub(1);
+ } else if self.is_searching {
self.search_view.move_selection_up();
} else {
self.file_list_view.move_selection_up();
}
}
pub fn move_selection_down(&mut self) {
- if self.is_searching {
+ if self.is_in_virtual_root {
+ if !self.virtual_root_entries.is_empty() {
+ self.virtual_root_selected = std::cmp::min(
+ self.virtual_root_selected.saturating_add(1),
+ self.virtual_root_entries.len().saturating_sub(1),
+ );
+ }
+ } else if self.is_searching {
self.search_view.move_selection_down();
} else {
self.file_list_view.move_selection_down();
@@ -78,7 +105,18 @@ impl State {
pub fn handle_left_click(&mut self, line: isize) {
if let Some(current_rows) = self.current_rows {
let rows_for_list = current_rows.saturating_sub(5);
- if self.is_searching {
+ if self.is_in_virtual_root {
+ let (start_index, _selected_index_in_range, _end_index) = calculate_list_bounds(
+ self.virtual_root_entries.len(),
+ rows_for_list,
+ Some(self.virtual_root_selected),
+ );
+ let prev_selected = self.virtual_root_selected;
+ self.virtual_root_selected = (line as usize).saturating_sub(4) + start_index;
+ if prev_selected == self.virtual_root_selected {
+ self.traverse_dir();
+ }
+ } else if self.is_searching {
let (start_index, _selected_index_in_range, _end_index) = calculate_list_bounds(
self.search_view.search_result_count(),
rows_for_list,
@@ -108,7 +146,14 @@ impl State {
pub fn handle_mouse_hover(&mut self, line: isize) {
if let Some(current_rows) = self.current_rows {
let rows_for_list = current_rows.saturating_sub(5);
- if self.is_searching {
+ if self.is_in_virtual_root {
+ let (start_index, _selected_index_in_range, _end_index) = calculate_list_bounds(
+ self.virtual_root_entries.len(),
+ rows_for_list,
+ Some(self.virtual_root_selected),
+ );
+ self.virtual_root_selected = (line as usize).saturating_sub(4) + start_index;
+ } else if self.is_searching {
let (start_index, _selected_index_in_range, _end_index) = calculate_list_bounds(
self.search_view.search_result_count(),
rows_for_list,
@@ -128,11 +173,21 @@ impl State {
}
}
pub fn descend_to_previous_path(&mut self) {
+ if self.is_in_virtual_root {
+ return;
+ }
self.search_term.clear();
self.search_view.clear_and_reset_selection();
- self.file_list_view.descend_to_previous_path();
+ if self.platform == Platform::Windows
+ && Platform::is_root(&self.file_list_view.path, self.platform)
+ {
+ self.enter_virtual_root();
+ } else {
+ self.file_list_view.descend_to_previous_path();
+ }
}
pub fn descend_to_root_path(&mut self) {
+ self.is_in_virtual_root = false;
self.search_term.clear();
self.search_view.clear_and_reset_selection();
self.file_list_view.descend_to_root_path(&self.initial_cwd);
@@ -142,6 +197,18 @@ impl State {
self.hide_hidden_files = !self.hide_hidden_files;
}
pub fn traverse_dir(&mut self) {
+ if self.is_in_virtual_root {
+ if let Some(entry) = self.virtual_root_entries.get(self.virtual_root_selected) {
+ let path = entry.get_full_pathbuf();
+ self.is_in_virtual_root = false;
+ self.file_list_view.path = path.clone();
+ self.file_list_view.path_is_dir = true;
+ self.file_list_view.files.clear();
+ self.file_list_view.clear_selected();
+ change_host_folder(path);
+ }
+ return;
+ }
let entry = if self.is_searching {
self.search_view.get_selected_entry()
} else {
@@ -174,8 +241,12 @@ impl State {
self.search_view.clear_and_reset_selection();
}
pub fn update_files(&mut self, paths: Vec<(PathBuf, Option<FileMetadata>)>) {
- self.file_list_view
- .update_files(paths, self.hide_hidden_files);
+ if self.is_in_virtual_root {
+ self.update_virtual_root_entries(paths);
+ } else {
+ self.file_list_view
+ .update_files(paths, self.hide_hidden_files);
+ }
}
pub fn open_selected_path(&mut self) {
if self.file_list_view.path_is_dir {
@@ -211,15 +282,80 @@ impl State {
}
}
}
+ pub fn enter_virtual_root(&mut self) {
+ self.is_in_virtual_root = true;
+ self.virtual_root_entries.clear();
+ self.virtual_root_selected = 0;
+ self.search_term.clear();
+ self.is_searching = false;
+ list_windows_volumes();
+ }
+ pub fn exit_virtual_root(&mut self) {
+ self.is_in_virtual_root = false;
+ refresh_directory(&self.file_list_view.path);
+ }
+ fn update_virtual_root_entries(&mut self, paths: Vec<(PathBuf, Option<FileMetadata>)>) {
+ let mut entries = vec![];
+ for (path, _metadata) in paths {
+ let path = Platform::normalize(&path);
+ entries.push(FsEntry::Dir(path));
+ }
+ // Drive letters first (e.g. "C:/"), then WSL distros (e.g. "//wsl.localhost/...")
+ entries.sort_unstable_by(|a, b| {
+ let a_is_drive = !a.get_full_pathbuf().to_string_lossy().starts_with("//");
+ let b_is_drive = !b.get_full_pathbuf().to_string_lossy().starts_with("//");
+ b_is_drive.cmp(&a_is_drive).then_with(|| a.cmp(b))
+ });
+ self.virtual_root_entries = entries;
+ if self.virtual_root_selected >= self.virtual_root_entries.len() {
+ self.virtual_root_selected = 0;
+ }
+ }
+ pub fn render_virtual_root(&self, rows: usize, cols: usize) {
+ let (start_index, selected_index_in_range, end_index) = calculate_list_bounds(
+ self.virtual_root_entries.len(),
+ rows.saturating_sub(1),
+ Some(self.virtual_root_selected),
+ );
+ render_list_tip(3, cols);
+ for i in start_index..end_index {
+ if let Some(entry) = self.virtual_root_entries.get(i) {
+ let is_selected = Some(i) == selected_index_in_range;
+ let display_name =
+ Platform::virtual_root_display_name(&entry.get_full_pathbuf(), self.platform);
+ let display_name_width = display_name.width();
+ let text = if display_name_width < cols {
+ let padding = " ".repeat(cols.saturating_sub(display_name_width));
+ format!("{}{}", display_name, padding)
+ } else {
+ display_name
+ };
+ let mut text_element = if is_selected {
+ Text::new(text).selected()
+ } else {
+ Text::new(text)
+ };
+ text_element = text_element.color_range(0, ..);
+ print_text_with_coordinates(
+ text_element,
+ 0,
+ 4 + i.saturating_sub(start_index),
+ Some(cols),
+ None,
+ );
+ }
+ }
+ }
pub fn send_filepick_response(&mut self) {
let selected_path = &self.file_list_view.path;
+ let host_path = Platform::to_host_display(selected_path, self.platform);
match &self.handling_filepick_request_from {
Some((PipeSource::Plugin(plugin_id), args)) => {
pipe_message_to_plugin(
MessageToPlugin::new("filepicker_result")
.with_destination_plugin_id(*plugin_id)
.with_args(args.clone())
- .with_payload(selected_path.display().to_string()),
+ .with_payload(host_path),
);
#[cfg(target_family = "wasm")]
close_self();
@@ -228,7 +364,7 @@ impl State {
// pipe_id is used inside #[cfg(target_family = "wasm")] blocks
Some((PipeSource::Cli(pipe_id), _args)) => {
#[cfg(target_family = "wasm")]
- cli_pipe_output(pipe_id, &selected_path.display().to_string());
+ cli_pipe_output(pipe_id, &host_path);
#[cfg(target_family = "wasm")]
unblock_cli_pipe_input(pipe_id);
#[cfg(target_family = "wasm")]