Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

feat(import): add projects from VS Code and the editors built on it

RoversX10a9f2978a91
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index d2ca94ba..0b751026 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -698,6 +698,8 @@ onboarding-found-sessions-running = { $count ->
onboarding-found-wezterm = Eine Konfigurationsdatei
onboarding-found-import = Importieren
onboarding-found-import-settings = Einstellungen importieren
+onboarding-found-editors = Geöffnete Ordner
+onboarding-found-choose-projects = Projekte auswählen
# Agent-Statuserkennung + Agents-Panel
settings-agent-panel-description = Erkennt Coding-Agents (Claude Code, Codex, …), die in Panes laufen, und zeigt sie in der rechten Seitenleiste.
@@ -1107,6 +1109,28 @@ session-import-project-meta = { $threads } Thread · { $tabs } Haupttabs · { $p
session-import-terminal-untitled = Terminal { $number }
settings-import-description = Wähle eine Quelle, um die importierbaren Inhalte zu sehen.
settings-import-wezterm-description = Einstellungen und Tastenkürzel
+settings-import-editors = Code-Editoren
+settings-import-editors-description = Projektordner
+settings-import-editors-title = Projekte zum Hinzufügen auswählen
+settings-import-editors-subtitle = Ordner, die du in VS Code und darauf aufbauenden Editoren geöffnet hast. Nur die Pfade werden übernommen; der Inhalt der Ordner wird nicht gelesen.
+settings-import-editors-all = Alle
+settings-import-editors-in-sidebar = Bereits in der Seitenleiste
+settings-import-editors-add-to = Hinzufügen zu
+settings-import-editors-add-to-description = Jeder Ordner wird ein Projekt mit einem Thread.
+settings-import-editors-remote = { $count ->
+ [one] 1 über SSH, in WSL oder in einem Container geöffneter Ordner kann noch nicht hinzugefügt werden.
+ *[other] { $count } über SSH, in WSL oder in Containern geöffnete Ordner können noch nicht hinzugefügt werden.
+ }
+settings-import-editors-reading = Die in den Editoren geöffneten Ordner werden gelesen…
+settings-import-editors-empty = Es wurden keine Ordner zum Hinzufügen gefunden.
+settings-import-editors-add = { $count ->
+ [one] 1 Projekt hinzufügen
+ *[other] { $count } Projekte hinzufügen
+ }
+settings-import-editors-done = { $count ->
+ [one] 1 Projekt zu { $space } hinzugefügt.
+ *[other] { $count } Projekte zu { $space } hinzugefügt.
+ }
settings-import-session-description = Sitzungen und Layouts
settings-import-wezterm-title = Aus WezTerm importieren
settings-import-open = Öffnen
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index 280a715f..01d32891 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -698,6 +698,8 @@ onboarding-found-sessions-running = { $count ->
onboarding-found-wezterm = A configuration file
onboarding-found-import = Import
onboarding-found-import-settings = Import settings
+onboarding-found-editors = Folders you opened
+onboarding-found-choose-projects = Choose projects
# Agent status detection + Agents panel
settings-agent-panel-description = Detect coding agents (Claude Code, Codex, …) running in panes and show them in the right sidebar.
@@ -1107,6 +1109,28 @@ session-import-project-meta = { $threads } Thread · { $tabs } primary tabs · {
session-import-terminal-untitled = Terminal { $number }
settings-import-description = Choose a source to see what you can import.
settings-import-wezterm-description = Settings and shortcuts
+settings-import-editors = Code editors
+settings-import-editors-description = Project folders
+settings-import-editors-title = Choose projects to add
+settings-import-editors-subtitle = Folders you opened in VS Code and the editors built on it. Only the paths come over; nothing inside the folders is read.
+settings-import-editors-all = All
+settings-import-editors-in-sidebar = Already in the sidebar
+settings-import-editors-add-to = Add to
+settings-import-editors-add-to-description = Each folder becomes a project with one thread.
+settings-import-editors-remote = { $count ->
+ [one] 1 folder opened over SSH, in WSL or in a container can't be added yet.
+ *[other] { $count } folders opened over SSH, in WSL or in containers can't be added yet.
+ }
+settings-import-editors-reading = Reading the folders your editors opened…
+settings-import-editors-empty = No folders to add were found.
+settings-import-editors-add = { $count ->
+ [one] Add 1 project
+ *[other] Add { $count } projects
+ }
+settings-import-editors-done = { $count ->
+ [one] Added 1 project to { $space }.
+ *[other] Added { $count } projects to { $space }.
+ }
settings-import-session-description = Sessions and layouts
settings-import-wezterm-title = Import from WezTerm
settings-import-open = Open
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index 77ae1074..2fdbe512 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -698,6 +698,8 @@ onboarding-found-sessions-running = { $count ->
onboarding-found-wezterm = Un fichier de configuration
onboarding-found-import = Importer
onboarding-found-import-settings = Importer les réglages
+onboarding-found-editors = Dossiers ouverts
+onboarding-found-choose-projects = Choisir les projets
# Détection d'état des agents + panneau Agents
settings-agent-panel-description = Détecter les agents de codage (Claude Code, Codex, …) dans les panneaux et les afficher dans la barre latérale droite.
@@ -1104,6 +1106,28 @@ session-import-project-meta = { $threads } fil · { $tabs } onglets principaux
session-import-terminal-untitled = Terminal { $number }
settings-import-description = Choisissez une source pour voir ce que vous pouvez importer.
settings-import-wezterm-description = Réglages et raccourcis
+settings-import-editors = Éditeurs de code
+settings-import-editors-description = Dossiers de projet
+settings-import-editors-title = Choisir les projets à ajouter
+settings-import-editors-subtitle = Les dossiers ouverts dans VS Code et les éditeurs qui en dérivent. Seuls les chemins sont repris ; le contenu des dossiers n'est pas lu.
+settings-import-editors-all = Tous
+settings-import-editors-in-sidebar = Déjà dans la barre latérale
+settings-import-editors-add-to = Ajouter à
+settings-import-editors-add-to-description = Chaque dossier devient un projet avec une session.
+settings-import-editors-remote = { $count ->
+ [one] 1 dossier ouvert via SSH, dans WSL ou dans un conteneur ne peut pas encore être ajouté.
+ *[other] { $count } dossiers ouverts via SSH, dans WSL ou dans des conteneurs ne peuvent pas encore être ajoutés.
+ }
+settings-import-editors-reading = Lecture des dossiers ouverts dans vos éditeurs…
+settings-import-editors-empty = Aucun dossier à ajouter n'a été trouvé.
+settings-import-editors-add = { $count ->
+ [one] Ajouter 1 projet
+ *[other] Ajouter { $count } projets
+ }
+settings-import-editors-done = { $count ->
+ [one] 1 projet ajouté à { $space }.
+ *[other] { $count } projets ajoutés à { $space }.
+ }
settings-import-session-description = Sessions et dispositions
settings-import-wezterm-title = Importer depuis WezTerm
settings-import-open = Ouvrir
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index cf568546..f9cd423d 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -683,6 +683,8 @@ onboarding-found-sessions-running = { $count } 個のセッション({ $runnin
onboarding-found-wezterm = 設定ファイルがあります
onboarding-found-import = インポート
onboarding-found-import-settings = 設定をインポート
+onboarding-found-editors = 開いたフォルダ
+onboarding-found-choose-projects = プロジェクトを選択
# エージェント状態検出 + Agents パネル
settings-agent-panel-description = ペインで動作するコーディングエージェント(Claude Code、Codex など)を検出し、右サイドバーに表示します。
@@ -1079,6 +1081,19 @@ session-import-project-meta = { $threads } スレッド · 第1階層タブ { $t
session-import-terminal-untitled = ターミナル { $number }
settings-import-description = インポート元を選んで、取り込める内容を確認します。
settings-import-wezterm-description = 設定とショートカット
+settings-import-editors = コードエディタ
+settings-import-editors-description = プロジェクトフォルダ
+settings-import-editors-title = 追加するプロジェクトを選択
+settings-import-editors-subtitle = VS Code とその派生エディタで開いたフォルダです。 パスだけを取り込み、フォルダの中身は読み取りません。
+settings-import-editors-all = すべて
+settings-import-editors-in-sidebar = サイドバーにあります
+settings-import-editors-add-to = 追加先
+settings-import-editors-add-to-description = 各フォルダはセッションを 1 つ持つプロジェクトになります。
+settings-import-editors-remote = SSH、WSL、コンテナで開いたフォルダ { $count } 件は、まだ追加できません。
+settings-import-editors-reading = エディタで開いたフォルダを読み込んでいます…
+settings-import-editors-empty = 追加できるフォルダは見つかりませんでした。
+settings-import-editors-add = { $count } 件のプロジェクトを追加
+settings-import-editors-done = { $space } に { $count } 件のプロジェクトを追加しました。
settings-import-session-description = セッションとレイアウト
settings-import-wezterm-title = WezTerm からインポート
settings-import-open = 開く
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index b948b1e7..80cc876d 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -683,6 +683,8 @@ onboarding-found-sessions-running = { $count } 个会话,{ $running } 个在
onboarding-found-wezterm = 找到配置文件
onboarding-found-import = 导入
onboarding-found-import-settings = 导入设置
+onboarding-found-editors = 打开过的文件夹
+onboarding-found-choose-projects = 选择项目
# Agent 状态检测 + Agents 面板
settings-agent-panel-description = 检测 pane 中运行的编码 Agent(Claude Code、Codex 等)并显示在右侧栏。
@@ -1079,6 +1081,19 @@ session-import-project-meta = { $threads } 个 Thread · { $tabs } 个一级标
session-import-terminal-untitled = 终端 { $number }
settings-import-description = 选择一个来源,查看可导入的内容。
settings-import-wezterm-description = 配置与快捷键
+settings-import-editors = 代码编辑器
+settings-import-editors-description = 项目文件夹
+settings-import-editors-title = 选择要添加的项目
+settings-import-editors-subtitle = 你在 VS Code 及其衍生编辑器里打开过的文件夹。 只导入路径,不会读取文件夹里的内容。
+settings-import-editors-all = 全部
+settings-import-editors-in-sidebar = 已在侧栏
+settings-import-editors-add-to = 添加到
+settings-import-editors-add-to-description = 每个文件夹会成为一个项目,带一个会话。
+settings-import-editors-remote = 另有 { $count } 个通过 SSH、WSL 或容器打开的文件夹,暂时不能添加。
+settings-import-editors-reading = 正在读取编辑器打开过的文件夹…
+settings-import-editors-empty = 没有找到可以添加的文件夹。
+settings-import-editors-add = 添加 { $count } 个项目
+settings-import-editors-done = 已把 { $count } 个项目添加到 { $space }。
settings-import-session-description = 会话与布局
settings-import-wezterm-title = 从 WezTerm 导入
settings-import-open = 打开
diff --git a/wezterm-gui/src/editor_projects.rs b/wezterm-gui/src/editor_projects.rs
new file mode 100644
index 00000000..28c4ee49
--- /dev/null
+++ b/wezterm-gui/src/editor_projects.rs
@@ -0,0 +1,560 @@
+//! The folders VS Code and the editors built from it have opened, for the
+//! Import page and first-run setup to offer as projects.
+//!
+//! Each of these editors keeps a directory per opened folder under
+//! `<user data>/User/workspaceStorage`, holding a `workspace.json` that
+//! names the folder by URI, and the directory's last change says when the
+//! folder was last used. Whether a folder is still there is the caller's to
+//! ask: on macOS, looking at one in Documents or on the Desktop can put a
+//! permission prompt in front of someone who has not asked to import.
+
+use crate::quad::TripleLayerQuadAllocator;
+use crate::termwindow::ui::icons::{BrandIcon, SvgIcon};
+use crate::ui::draw::DrawContext;
+use std::collections::{HashMap, HashSet};
+use std::path::{Path, PathBuf};
+use std::time::{Duration, SystemTime};
+use window::color::LinearRgba;
+
+/// Editors known by their user-data directory, with what to call them.
+/// Only these directories are looked in: on macOS, looking inside another
+/// app's can ask the user for that app's data -- their contacts, say.
+const KNOWN: &[(&str, &str, EditorKind)] = &[
+ ("Code", "VS Code", EditorKind::VsCode),
+ ("Code - Insiders", "VS Code Insiders", EditorKind::VsCode),
+ ("Code - OSS", "Code - OSS", EditorKind::Other),
+ ("VSCodium", "VSCodium", EditorKind::VsCodium),
+ ("VSCodium - Insiders", "VSCodium Insiders", EditorKind::VsCodium),
+ ("Cursor", "Cursor", EditorKind::Cursor),
+ ("Windsurf", "Windsurf", EditorKind::Windsurf),
+ ("Antigravity", "Antigravity", EditorKind::Other),
+ ("Kiro", "Kiro", EditorKind::Other),
+ ("Positron", "Positron", EditorKind::Other),
+ ("Trae", "Trae", EditorKind::Other),
+ ("Void", "Void", EditorKind::Other),
+];
+
+/// Opened folders read per editor, newest first: an install keeps one
+/// directory per folder it ever opened, and only the recent ones matter.
+const PER_EDITOR: usize = 400;
+
+/// A `workspace.json` larger than this is not one; it is not read.
+const MAX_WORKSPACE_JSON: u64 = 64 * 1024;
+
+/// How recent a folder's last use has to be for its box to start ticked.
+pub(crate) const RECENT: Duration = Duration::from_secs(30 * 24 * 60 * 60);
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum EditorKind {
+ VsCode,
+ VsCodium,
+ Cursor,
+ Windsurf,
+ Other,
+}
+
+impl EditorKind {
+ /// Its own mark, where it has one in colour.
+ fn brand(self) -> Option<BrandIcon> {
+ match self {
+ Self::Cursor => Some(BrandIcon::Cursor),
+ Self::Windsurf => Some(BrandIcon::Windsurf),
+ Self::VsCodium => Some(BrandIcon::VSCodium),
+ Self::VsCode | Self::Other => None,
+ }
+ }
+
+ /// The glyph drawn white where it has no mark in colour.
+ fn glyph(self) -> SvgIcon {
+ match self {
+ Self::VsCode => SvgIcon::VsCode,
+ _ => SvgIcon::CodeXml,
+ }
+ }
+
+ /// The colour of the tile its mark sits on.
+ fn tile(self) -> LinearRgba {
+ let (r, g, b) = match self {
+ Self::VsCode => (0x00, 0x7A, 0xCC),
+ Self::VsCodium => (0x1B, 0x2B, 0x44),
+ Self::Cursor => (0x14, 0x14, 0x14),
+ Self::Windsurf => (0x0B, 0x10, 0x0F),
+ Self::Other => (0x48, 0x48, 0x4A),
+ };
+ LinearRgba::with_srgba(r, g, b, 0xFF)
+ }
+}
+
+/// How far each tile in [`draw_stack`] starts after the one before, as a
+/// share of its side.
+const STACK_STEP: f32 = 0.7;
+
+/// The kinds a stack shows: each once, in the order given, at most three.
+pub(crate) fn stack_kinds(kinds: impl IntoIterator<Item = EditorKind>) -> Vec<EditorKind> {
+ let mut stack = Vec::new();
+ for kind in kinds {
+ if stack.len() == 3 {
+ break;
+ }
+ if !stack.contains(&kind) {
+ stack.push(kind);
+ }
+ }
+ stack
+}
+
+/// How wide [`draw_stack`] draws `count` tiles of side `tile`.
+pub(crate) fn stack_width(count: usize, tile: f32) -> f32 {
+ let tile = tile.round();
+ tile + (tile * STACK_STEP).round() * count.saturating_sub(1) as f32
+}
+
+/// Editors' marks on tiles of side `tile`, from `x` rightwards, the first
+/// in front and each ringed with `ground` -- what they sit on -- so the
+/// ones behind show where they are cut. The tiles are lit as Settings
+/// lights the squares heading its rows; `dark` is the chrome's appearance.
+/// All on the top layer, where the marks are, so a tile in front hides the
+/// mark behind it.
+#[allow(clippy::too_many_arguments)]
+pub(crate) fn draw_stack(
+ ctx: &DrawContext,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ kinds: &[EditorKind],
+ x: f32,
+ y: f32,
+ tile: f32,
+ ground: LinearRgba,
+ dark: bool,
+) -> anyhow::Result<()> {
+ // Whole pixels, so the marks come out sharp.
+ let (x, y, tile) = (x.round(), y.round(), tile.round());
+ let step = (tile * STACK_STEP).round();
+ let ring = (tile * 0.05).round().max(1.0);
+ let radius = tile * 0.27;
+ let mark = (tile * 0.56).round();
+ for (index, kind) in kinds.iter().enumerate().rev() {
+ let tile_x = x + step * index as f32;
+ ctx.draw_rounded_rect(
+ layers,
+ 2,
+ tile_x - ring,
+ y - ring,
+ tile + ring * 2.0,
+ tile + ring * 2.0,
+ ground,
+ radius + ring,
+ )?;
+ crate::ui::tile::draw_tile(
+ ctx,
+ layers,
+ 2,
+ tile_x,
+ y,
+ tile,
+ radius,
+ kind.tile(),
+ dark,
+ &crate::settings_window::ROW_TILE,
+ )?;
+ let mark_x = tile_x + (tile - mark) / 2.0;
+ let mark_y = y + (tile - mark) / 2.0;
+ match kind.brand() {
+ Some(brand) => ctx.draw_brand_icon(layers, brand, mark_x, mark_y, mark)?,
+ None => ctx.draw_svg_icon(
+ layers,
+ kind.glyph(),
+ mark_x,
+ mark_y,
+ mark,
+ LinearRgba::with_srgba(0xFF, 0xFF, 0xFF, 0xFF),
+ )?,
+ }
+ }
+ Ok(())
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub(crate) struct Editor {
+ pub name: String,
+ pub kind: EditorKind,
+}
+
+#[derive(Debug, Clone, PartialEq)]
+pub(crate) struct Folder {
+ pub path: PathBuf,
+ pub name: String,
+ /// Every editor that opened it, by index into `Scan::editors`, the most
+ /// recent first.
+ pub editors: Vec<usize>,
+ pub last_used: SystemTime,
+}
+
+#[derive(Debug, Clone, Default, PartialEq)]
+pub(crate) struct Scan {
+ /// The editors with a folder here to offer, in the order found.
+ pub editors: Vec<Editor>,
+ /// One per folder, the most recently used first.
+ pub folders: Vec<Folder>,
+ /// Folders the editors opened on another machine -- over SSH, in WSL or
+ /// a container -- which are not offered yet.
+ pub remote: usize,
+}
+
+impl Scan {
+ pub fn folders_in(&self, editor: Option<usize>) -> impl Iterator<Item = (usize, &Folder)> {
+ self.folders
+ .iter()
+ .enumerate()
+ .filter(move |(_, folder)| editor.map_or(true, |e| folder.editors.contains(&e)))
+ }
+}
+
+/// The kinds of editor this machine has, each once, looked up the first
+/// time they are asked for: the Import page offers its card only when
+/// there is one. Nothing an editor opened is read for this.
+pub(crate) fn installed() -> &'static [EditorKind] {
+ static INSTALLED: std::sync::OnceLock<Vec<EditorKind>> = std::sync::OnceLock::new();
+ INSTALLED.get_or_init(|| {
+ let mut kinds = Vec::new();
+ if let Some(root) = user_data_root() {
+ for (_, kind, _) in editor_storages(&root) {
+ if !kinds.contains(&kind) {
+ kinds.push(kind);
+ }
+ }
+ }
+ kinds
+ })
+}
+
+/// What this machine's editors have opened, each folder as `resolve` names
+/// it: two it names alike are one folder, and one it names None -- no
+/// longer there, say -- is left out.
+pub(crate) fn scan(resolve: &dyn Fn(&Path) -> Option<PathBuf>) -> Scan {
+ match user_data_root() {
+ Some(root) => scan_root(&root, resolve),
+ None => Scan::default(),
+ }
+}
+
+/// Where the editors keep their user data.
+fn user_data_root() -> Option<PathBuf> {
+ if cfg!(target_os = "macos") {
+ Some(config::HOME_DIR.join("Library").join("Application Support"))
+ } else if cfg!(windows) {
+ std::env::var_os("APPDATA").map(PathBuf::from)
+ } else {
+ std::env::var_os("XDG_CONFIG_HOME")
+ .map(PathBuf::from)
+ .filter(|dir| dir.is_absolute())
+ .or_else(|| Some(config::HOME_DIR.join(".config")))
+ }
+}
+
+/// One opened folder as an editor recorded it.
+struct Opened {
+ editor: usize,
+ last_used: SystemTime,
+ uri: String,
+}
+
+/// The editors under `root`, and what they opened, as for [`scan`].
+fn scan_root(root: &Path, resolve: &dyn Fn(&Path) -> Option<PathBuf>) -> Scan {
+ let mut editors = Vec::new();
+ let mut opened = Vec::new();
+ for (name, kind, storage) in editor_storages(root) {
+ let index = editors.len();
+ editors.push(Editor { name, kind });
+ for (workspace_json, last_used) in newest_entries(&storage) {
+ if let Some(uri) = read_folder_uri(&workspace_json) {
+ opened.push(Opened {
+ editor: index,
+ last_used,
+ uri,
+ });
+ }
+ }
+ }
+ merge(editors, opened, resolve)
+}
+
+/// Each known editor's `workspaceStorage` under `root`, where it has one.
+fn editor_storages(root: &Path) -> Vec<(String, EditorKind, PathBuf)> {
+ KNOWN
+ .iter()
+ .map(|(dir, name, kind)| {
+ let storage = root.join(dir).join("User").join("workspaceStorage");
+ (name.to_string(), *kind, storage)
+ })
+ .filter(|(.., storage)| storage.is_dir())
+ .collect()
+}
+
+/// The `workspace.json` of the most recently used entries in `storage`,
+/// with when each was last used: the later of its directory's change and
+/// its state database's, which the editor writes as the folder is used.
+fn newest_entries(storage: &Path) -> Vec<(PathBuf, SystemTime)> {
+ let modified = |path: &Path| path.metadata().and_then(|m| m.modified()).ok();
+ let mut entries: Vec<(PathBuf, SystemTime)> = std::fs::read_dir(storage)
+ .into_iter()
+ .flatten()
+ .flatten()
+ .filter_map(|entry| {
+ let dir = entry.path();
+ let last_used = modified(&dir)?.max(
+ modified(&dir.join("state.vscdb")).unwrap_or(SystemTime::UNIX_EPOCH),
+ );
+ Some((dir.join("workspace.json"), last_used))
+ })
+ .collect();
+ entries.sort_by(|a, b| b.1.cmp(&a.1));
+ entries.truncate(PER_EDITOR);
+ entries
+}
+
+/// The folder a `workspace.json` names, as the URI it gives. A multi-root
+/// workspace names a `.code-workspace` file instead and is skipped.
+fn read_folder_uri(workspace_json: &Path) -> Option<String> {
+ if workspace_json.metadata().ok()?.len() > MAX_WORKSPACE_JSON {
+ return None;
+ }
+ let text = std::fs::read(workspace_json).ok()?;
+ let value: serde_json::Value = serde_json::from_slice(&text).ok()?;
+ value.get("folder")?.as_str().map(str::to_string)
+}
+
+/// One folder per path `resolve` names, the most recent use deciding its
+/// time and the order its editors are listed in. Editors with nothing left
+/// to offer are dropped, and the indexes renumbered.
+fn merge(
+ editors: Vec<Editor>,
+ mut opened: Vec<Opened>,
+ resolve: &dyn Fn(&Path) -> Option<PathBuf>,
+) -> Scan {
+ opened.sort_by(|a, b| b.last_used.cmp(&a.last_used));
+ let mut remote = HashSet::new();
+ let mut folders: Vec<Folder> = Vec::new();
+ let mut by_path: HashMap<PathBuf, usize> = HashMap::new();
+ // Each path resolved once, however many editors opened it.
+ let mut resolved: HashMap<PathBuf, Option<PathBuf>> = HashMap::new();
+ for item in opened {
+ let Some(local) = local_path(&item.uri) else {
+ // Opened on another machine: an SSH host, WSL, a container.
+ if item.uri.contains("://") {
+ remote.insert(item.uri);
+ }
+ continue;
+ };
+ let Some(path) = resolved
+ .entry(local)
+ .or_insert_with_key(|local| resolve(local))
+ .clone()
+ else {
+ continue;
+ };
+ if let Some(&index) = by_path.get(&path) {
+ let folder = &mut folders[index];
+ if !folder.editors.contains(&item.editor) {
+ folder.editors.push(item.editor);
+ }
+ continue;
+ }
+ let name = path
+ .file_name()
+ .map(|name| name.to_string_lossy().into_owned())
+ .unwrap_or_else(|| path.display().to_string());
+ by_path.insert(path.clone(), folders.len());
+ folders.push(Folder {
+ path,
+ name,
+ editors: vec![item.editor],
+ last_used: item.last_used,
+ });
+ }
+
+ let mut renumber = HashMap::new();
+ let mut kept = Vec::new();
+ for (index, editor) in editors.into_iter().enumerate() {
+ if folders.iter().any(|folder| folder.editors.contains(&index)) {
+ renumber.insert(index, kept.len());
+ kept.push(editor);
+ }
+ }
+ for folder in &mut folders {
+ for editor in &mut folder.editors {
+ *editor = renumber[editor];
+ }
+ }
+ Scan {
+ editors: kept,
+ folders,
+ remote: remote.len(),
+ }
+}
+
+/// A `file:` URI as the path it names on this machine. One naming another
+/// machine -- `file://wsl.localhost/...` -- is not this machine's.
+fn local_path(uri: &str) -> Option<PathBuf> {
+ let url = url::Url::parse(uri).ok()?;
+ if url.scheme() != "file" || url.host_str().is_some_and(|host| !host.is_empty()) {
+ return None;
+ }
+ url.to_file_path().ok()
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn at(days_ago: u64) -> SystemTime {
+ SystemTime::now() - Duration::from_secs(days_ago * 24 * 60 * 60)
+ }
+
+ fn opened(editor: usize, days_ago: u64, path: &Path) -> Opened {
+ Opened {
+ editor,
+ last_used: at(days_ago),
+ uri: url::Url::from_directory_path(path).unwrap().to_string(),
+ }
+ }
+
+ fn editor(name: &str) -> Editor {
+ Editor {
+ name: name.to_string(),
+ kind: EditorKind::Other,
+ }
+ }
+
+ fn as_given(path: &Path) -> Option<PathBuf> {
+ Some(path.to_path_buf())
+ }
+
+ #[test]
+ fn a_folder_opened_in_two_editors_is_offered_once_newest_first() {
+ let root = tempfile::tempdir().unwrap();
+ let api = root.path().join("api");
+ let web = root.path().join("web");
+ let scan = merge(
+ vec![editor("VS Code"), editor("Cursor")],
+ vec![
+ opened(0, 9, &api),
+ opened(1, 2, &api),
+ opened(0, 1, &web),
+ ],
+ &as_given,
+ );
+ let paths: Vec<_> = scan.folders.iter().map(|f| f.path.clone()).collect();
+ assert_eq!(paths, [web, api]);
+ // Cursor opened it last, so it is named first.
+ assert_eq!(scan.folders[1].editors, [1, 0]);
+ assert_eq!(scan.folders[1].name, "api");
+ assert_eq!(scan.folders_in(Some(1)).count(), 1);
+ assert_eq!(scan.folders_in(None).count(), 2);
+ }
+
+ #[test]
+ fn removed_and_remote_folders_are_not_offered() {
+ let root = tempfile::tempdir().unwrap();
+ let gone = root.path().join("gone");
+ let here = root.path().join("here");
+ let scan = merge(
+ vec![editor("VS Code"), editor("Windsurf")],
+ vec![
+ opened(0, 1, &gone),
+ opened(0, 2, &here),
+ Opened {
+ editor: 1,
+ last_used: at(3),
+ uri: "vscode-remote://ssh-remote%2Bserver-a/home/user/app".into(),
+ },
+ Opened {
+ editor: 1,
+ last_used: at(4),
+ uri: "vscode-remote://ssh-remote%2Bserver-a/home/user/app".into(),
+ },
+ ],
+ &|path| (path != gone).then(|| path.to_path_buf()),
+ );
+ assert_eq!(scan.folders.len(), 1);
+ assert_eq!(scan.remote, 1, "the same remote folder counts once");
+ // Windsurf had only the remote folder: no pill for it.
+ assert_eq!(scan.editors, [editor("VS Code")]);
+ assert_eq!(scan.folders[0].editors, [0]);
+ }
+
+ #[test]
+ fn editors_are_found_by_their_storage_and_read_from_workspace_json() {
+ let root = tempfile::tempdir().unwrap();
+ let project = tempfile::tempdir().unwrap();
+ let write = |dir: &str, entry: &str, json: String| {
+ let storage = root.path().join(dir).join("User").join("workspaceStorage").join(entry);
+ std::fs::create_dir_all(&storage).unwrap();
+ std::fs::write(storage.join("workspace.json"), json).unwrap();
+ };
+ let uri = url::Url::from_directory_path(project.path()).unwrap();
+ write("Cursor", "a", format!(r#"{{"folder":"{uri}"}}"#));
+ write("Trae", "b", format!(r#"{{"folder":"{uri}"}}"#));
+ write("Code", "c", r#"{"workspace":"file:///code/team.code-workspace"}"#.into());
+ // Laid out like an editor but not a known one: not looked in.
+ write("Some Fork", "d", format!(r#"{{"folder":"{uri}"}}"#));
+
+ let scan = scan_root(root.path(), &|path: &Path| {
+ path.is_dir().then(|| path.to_path_buf())
+ });
+ let names: Vec<_> = scan.editors.iter().map(|e| e.name.as_str()).collect();
+ // VS Code opened only a multi-root workspace, which is skipped.
+ assert_eq!(names, ["Cursor", "Trae"]);
+ assert_eq!(scan.editors[0].kind, EditorKind::Cursor);
+ assert_eq!(scan.folders.len(), 1);
+ assert_eq!(scan.folders[0].editors.len(), 2);
+ }
+
+ #[test]
+ fn two_spellings_of_one_folder_are_offered_once() {
+ let root = tempfile::tempdir().unwrap();
+ let alias = root.path().join("alias");
+ let canonical = root.path().join("canonical");
+ let resolve = |path: &Path| {
+ Some(match path.strip_prefix(&alias) {
+ Ok(rest) => canonical.join(rest),
+ Err(_) => path.to_path_buf(),
+ })
+ };
+ let scan = merge(
+ vec![editor("VS Code"), editor("Cursor")],
+ vec![
+ opened(0, 1, &alias.join("demo")),
+ opened(1, 2, &canonical.join("demo")),
+ ],
+ &resolve,
+ );
+ assert_eq!(scan.folders.len(), 1);
+ assert_eq!(scan.folders[0].path, canonical.join("demo"));
+ assert_eq!(scan.folders[0].editors, [0, 1]);
+ }
+
+ #[test]
+ fn a_file_uri_naming_another_machine_is_not_a_local_folder() {
+ let scan = merge(
+ vec![editor("VS Code")],
+ vec![Opened {
+ editor: 0,
+ last_used: at(1),
+ uri: "file://wsl.localhost/Alpine/home/user/app".into(),
+ }],
+ &as_given,
+ );
+ assert!(scan.folders.is_empty());
+ assert_eq!(scan.remote, 1);
+ }
+
+ #[cfg(windows)]
+ #[test]
+ fn a_windows_drive_is_read_with_its_colon_escaped() {
+ // VS Code writes the drive's colon as %3A.
+ assert_eq!(
+ local_path("file:///c%3A/Users/user/app"),
+ Some(PathBuf::from(r"c:\Users\user\app"))
+ );
+ }
+}
diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs
index dfa1e679..8811c734 100644
--- a/wezterm-gui/src/main.rs
+++ b/wezterm-gui/src/main.rs
@@ -42,6 +42,7 @@ mod colorease;
mod commands;
mod customglyph;
mod download;
+mod editor_projects;
mod framedump;
mod frontend;
mod glyphcache;
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 1d789703..2e8b171d 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -50,8 +50,10 @@ use fluent_bundle::FluentArgs;
#[cfg(unix)]
mod session_import;
+mod editor_import;
mod import;
mod keymap;
+pub(crate) use import::EDITORS_SOURCE;
use import::{ImportButton, ImportSource, ImportStep};
// All chrome geometry below is authored in 2x macOS backing pixels.
@@ -142,7 +144,7 @@ const HINT_ICON_SIDE: f32 = 20.0;
const HINT_ICON_GAP: f32 = 8.0;
/// How a row's square is lit: more gently than a tab icon, with a faint
/// light rim and a plain dark shadow, as System Settings draws its own.
-const ROW_TILE: crate::ui::tile::TileStyle = crate::ui::tile::TileStyle {
+pub(crate) const ROW_TILE: crate::ui::tile::TileStyle = crate::ui::tile::TileStyle {
fill_top_lighten: 0.16,
fill_bottom_darken: 0.10,
rim_top_lighten: 0.30,
@@ -725,7 +727,7 @@ fn initial_section() -> SettingsSection {
"archived" => SettingsSection::Archived,
"keymap" => SettingsSection::Keymap,
"commandpalette" => SettingsSection::CommandPalette,
- "import" | "compatibility" => SettingsSection::Import,
+ "import" | "compatibility" | EDITORS_SOURCE => SettingsSection::Import,
"developer" => SettingsSection::Developer,
"uikit" => SettingsSection::UiKit,
"memory" => SettingsSection::Memory,
@@ -1554,6 +1556,7 @@ enum SettingsAction {
TabIconSearchInput,
KeymapSearchInput,
Keymap(keymap::KeymapAction),
+ EditorImport(editor_import::EditorImportAction),
ClearTabIconSearch,
}
@@ -1605,6 +1608,8 @@ enum SettingsDropdown {
DefaultShell,
CommandPaletteHotkey,
WebLinkTtl,
+ /// The Space the Import page adds editors' folders to.
+ EditorImportSpace,
/// How long an installed plugin runs unused, keyed as TogglePlugin: its
/// row is where the list put it, so the menu opens under the pill last
/// painted for it.
@@ -2156,6 +2161,7 @@ struct SettingsUiState {
/// What the cards are narrowed to, by name or program.
tab_icon_search: TextInputState,
keymap: keymap::KeymapUi,
+ editor_import: editor_import::EditorImportUi,
/// The cards as last painted, so a click acts on the card that was
/// under the pointer.
tab_icon_cards: Vec<String>,
@@ -2247,6 +2253,7 @@ impl SettingsUiState {
tab_icon_selected: None,
tab_icon_search: TextInputState::new(),
keymap: keymap::KeymapUi::default(),
+ editor_import: editor_import::EditorImportUi::default(),
tab_icon_cards: Vec::new(),
tab_icon_programs: Vec::new(),
tab_icon_drop_rects: Vec::new(),
@@ -3685,6 +3692,10 @@ impl SettingsWindow {
| SettingsAction::SetWebLinkTtl(_)
| SettingsAction::TogglePluginBackgroundMenu(_)
| SettingsAction::SetPluginBackground(..)
+ | SettingsAction::EditorImport(
+ editor_import::EditorImportAction::SpaceMenu
+ | editor_import::EditorImportAction::Space(_),
+ )
| SettingsAction::DropdownMenuBackdrop,
) => {
self.set_focused_input(None);
@@ -5280,6 +5291,14 @@ impl SettingsWindow {
crate::web_settings::hide_qr();
// The keyboard is built for its page and let go when another shows.
self.ui.keymap.enter(section == SettingsSection::Keymap);
+ // So is what the editors opened, read as the Import page reviews it;
+ // back on that page, it starts again from choosing a source.
+ if section != SettingsSection::Import {
+ self.ui.editor_import.release();
+ if self.ui.import_source == ImportSource::Editors {
+ self.ui.import_step = ImportStep::Source;
+ }
+ }
if section == SettingsSection::Agents {
// Probe PATH on entry so painting never touches the filesystem.
crate::agent_status::refresh_path_probe();
@@ -6099,6 +6118,7 @@ impl SettingsWindow {
// Focused on press; there is nothing more to do on release.
}
SettingsAction::Keymap(action) => self.perform_keymap_action(action),
+ SettingsAction::EditorImport(action) => self.perform_editor_import_action(action),
SettingsAction::ClearTabIconSearch => {
self.ui.tab_icon_search.clear();
self.set_focused_input(Some(SettingsAction::TabIconSearchInput));
@@ -17007,6 +17027,12 @@ impl SettingsWindow {
control_y + self.ui_px(CONTROL_HEIGHT) + self.ui_px(8.0),
control_width,
),
+ SettingsDropdown::EditorImportSpace => self.paint_editor_space_menu(
+ layers,
+ control_x,
+ control_y + self.ui_px(CONTROL_HEIGHT) + self.ui_px(8.0),
+ control_width,
+ ),
// Painted under its pill, above.
SettingsDropdown::PluginBackground(_) => Ok(()),
}
diff --git a/wezterm-gui/src/settings_window/editor_import.rs b/wezterm-gui/src/settings_window/editor_import.rs
new file mode 100644
index 00000000..41fd9abf
--- /dev/null
+++ b/wezterm-gui/src/settings_window/editor_import.rs
@@ -0,0 +1,808 @@
+//! Settings → Import from code editors: the folders VS Code and the editors
+//! built from it opened, ticked, and added as projects to a local Space.
+//! What the editors opened is read as the review step opens, on a thread of
+//! its own -- each folder is looked up on disk, and one on a network share
+//! that has gone away can take seconds -- and let go when the page is left.
+
+use super::*;
+use crate::editor_projects::{self, EditorKind, Scan};
+use crate::workspace_threads::ResolvedProjects;
+use std::collections::{HashMap, HashSet};
+use std::path::PathBuf;
+use std::time::SystemTime;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(super) enum EditorImportAction {
+ /// Show one editor's folders, or with `None` every editor's.
+ Filter(Option<u8>),
+ /// Tick or untick a row, by its place in the list.
+ Toggle(u16),
+ SelectAll,
+ Clear,
+ SpaceMenu,
+ /// Add to a local Space, by its place in the menu.
+ Space(u8),
+ Add,
+}
+
+/// What the read found: what the editors opened, and each local Space's
+/// projects resolved the same way, so choosing a Space or adding to it asks
+/// the file system nothing more.
+#[derive(Debug, Default)]
+struct Found {
+ scan: Scan,
+ known: HashMap<String, ResolvedProjects>,
+}
+
+/// The read itself, off the UI thread.
+fn read(spaces: Vec<String>) -> Found {
+ let scan = editor_projects::scan(&crate::workspace_threads::project_path_key);
+ let known = spaces
+ .into_iter()
+ .map(|id| {
+ let projects = crate::workspace_threads::resolved_projects(&id);
+ (id, projects)
+ })
+ .collect();
+ Found { scan, known }
+}
+
+#[derive(Debug, Clone, Default)]
+pub(super) struct EditorImportUi {
+ /// Whether the read is still out.
+ loading: bool,
+ /// Which read is wanted: one that comes back after another was asked
+ /// for, or after the page was left, is dropped.
+ generation: u64,
+ /// Each folder resolved as the sidebar keeps a project's path.
+ scan: Scan,
+ /// Each local Space's projects, by its id, resolved the same way.
+ known: HashMap<String, ResolvedProjects>,
+ filter: Option<usize>,
+ /// Ticked folders, by index into `scan.folders`.
+ selected: HashSet<usize>,
+ /// The local Spaces, by id and name.
+ spaces: Vec<(String, String)>,
+ space: Option<String>,
+ /// The folder each painted row stands for.
+ rows: Vec<usize>,
+ /// How many were added, and to which Space, once they have been.
+ added: Option<(usize, String)>,
+}
+
+impl EditorImportUi {
+ /// Start a read, aimed at `space` when it is local and the first local
+ /// Space otherwise. Its number, and the Spaces it is to resolve.
+ fn begin(&mut self, space: Option<String>) -> (u64, Vec<String>) {
+ let spaces = crate::workspace_threads::local_spaces();
+ let space = space
+ .filter(|id| spaces.iter().any(|(local, _)| local == id))
+ .or_else(|| spaces.first().map(|(id, _)| id.clone()));
+ let ids = spaces.iter().map(|(id, _)| id.clone()).collect();
+ *self = Self {
+ loading: true,
+ generation: self.generation + 1,
+ spaces,
+ space,
+ ..Self::default()
+ };
+ (self.generation, ids)
+ }
+
+ /// What read `generation` found, if it is still the one wanted.
+ fn finish(&mut self, generation: u64, found: Found) {
+ if !self.loading || generation != self.generation {
+ return;
+ }
+ self.loading = false;
+ self.scan = found.scan;
+ self.known = found.known;
+ self.retarget(self.space.clone());
+ }
+
+ /// Let go of what was read, and of a read still out: the page was left.
+ pub(super) fn release(&mut self) {
+ *self = Self {
+ generation: self.generation,
+ ..Self::default()
+ };
+ }
+
+ /// Aim at `space`, ticking what was used lately and it has not got.
+ fn retarget(&mut self, space: Option<String>) {
+ self.space = space;
+ let now = SystemTime::now();
+ self.selected = (0..self.scan.folders.len())
+ .filter(|&index| {
+ self.importable(index)
+ && now
+ .duration_since(self.scan.folders[index].last_used)
+ .map_or(true, |age| age <= editor_projects::RECENT)
+ })
+ .collect();
+ }
+
+ /// Whether a folder is not among the chosen Space's projects yet. One
+ /// it has archived is: adding it brings it back.
+ fn importable(&self, index: usize) -> bool {
+ let path = &self.scan.folders[index].path;
+ !self
+ .space
+ .as_ref()
+ .and_then(|space| self.known.get(space))
+ .and_then(|projects| projects.get(path))
+ .is_some_and(|(_, archived)| !archived)
+ }
+
+ fn visible(&self) -> Vec<usize> {
+ self.scan
+ .folders_in(self.filter)
+ .map(|(index, _)| index)
+ .collect()
+ }
+
+ /// The ticked folders on show: what Add adds. One ticked under another
+ /// editor's filter is not, so the count on the button is what happens.
+ fn chosen(&self) -> Vec<usize> {
+ self.visible()
+ .into_iter()
+ .filter(|index| self.selected.contains(index))
+ .collect()
+ }
+
+ fn space_name(&self) -> String {
+ self.spaces
+ .iter()
+ .find(|(id, _)| Some(id) == self.space.as_ref())
+ .map(|(_, name)| name.clone())
+ .unwrap_or_default()
+ }
+
+ /// The editors the review step's heading shows: those with folders to
+ /// offer, or every one this machine has when none has.
+ pub(super) fn kinds(&self) -> Vec<EditorKind> {
+ if self.scan.editors.is_empty() {
+ editor_projects::stack_kinds(editor_projects::installed().iter().copied())
+ } else {
+ editor_projects::stack_kinds(self.scan.editors.iter().map(|editor| editor.kind))
+ }
+ }
+}
+
+/// When a folder was last used, in the Archived page's words.
+fn last_used_label(when: SystemTime) -> String {
+ let seconds = when
+ .duration_since(SystemTime::UNIX_EPOCH)
+ .map_or(0, |since| since.as_secs() as i64);
+ format_archived_when(seconds)
+}
+
+impl SettingsWindow {
+ pub(super) fn paint_editor_import(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ x: f32,
+ y: f32,
+ width: f32,
+ ) -> anyhow::Result<f32> {
+ let palette = self.palette();
+ let mut bottom = self.paint_import_source_heading(
+ layers,
+ x,
+ y,
+ width,
+ &crate::i18n::tr("settings-import-editors-title"),
+ &crate::i18n::tr("settings-import-editors-subtitle"),
+ )?;
+ bottom += self.ui_px(28.0);
+ if self.ui.editor_import.loading || self.ui.editor_import.scan.folders.is_empty() {
+ let notice = if self.ui.editor_import.loading {
+ "settings-import-editors-reading"
+ } else {
+ "settings-import-editors-empty"
+ };
+ bottom = self.paint_import_notice(
+ layers,
+ x,
+ bottom,
+ width,
+ &crate::i18n::tr(notice),
+ false,
+ )?;
+ return self.paint_import_footer(
+ layers,
+ x,
+ bottom + self.ui_px(32.0),
+ width,
+ Some(SettingsAction::ImportBack),
+ &[],
+ );
+ }
+
+ if self.ui.editor_import.scan.editors.len() > 1 {
+ bottom = self.paint_editor_filters(layers, x, bottom, width)? + self.ui_px(28.0);
+ }
+
+ let visible = self.ui.editor_import.visible();
+ let importable = visible
+ .iter()
+ .filter(|&&index| self.ui.editor_import.importable(index))
+ .count();
+ let selected = self.ui.editor_import.chosen().len();
+ let mut args = FluentArgs::new();
+ args.set("selected", selected);
+ args.set("total", importable);
+ bottom = self.paint_import_copy(
+ layers,
+ x,
+ bottom,
+ width,
+ &crate::i18n::tr_args("settings-fields-selected", &args),
+ palette.secondary_text,
+ )?;
+ bottom = self.paint_import_actions(
+ layers,
+ x,
+ bottom + self.ui_px(12.0),
+ width,
+ &[
+ ImportButton {
+ label: crate::i18n::tr("common-select-all"),
+ action: SettingsAction::EditorImport(EditorImportAction::SelectAll),
+ enabled: importable > 0,
+ primary: false,
+ },
+ ImportButton {
+ label: crate::i18n::tr("common-clear"),
+ action: SettingsAction::EditorImport(EditorImportAction::Clear),
+ enabled: selected > 0,
+ primary: false,
+ },
+ ],
+ )?;
+
+ // Rows off the page are only counted: a long-lived editor can list
+ // hundreds of folders, and every row is the same height.
+ let mut rows = RowCursor::new(bottom + self.ui_px(36.0), self);
+ let visual = self.settings_row_visual_height();
+ let page_bottom = self.content_bottom();
+ self.ui.editor_import.rows.clear();
+ for (place, index) in visible.iter().copied().enumerate() {
+ self.ui.editor_import.rows.push(index);
+ if rows.y + visual > 0.0 && rows.y - visual < page_bottom {
+ self.paint_editor_folder_row(layers, x, rows.y, width, place, index, rows.rule())?;
+ }
+ rows.add(0.0);
+ }
+ bottom = rows.bottom + self.ui_px(36.0);
+
+ bottom = self.paint_editor_destination(layers, x, bottom, width)?;
+ let remote = self.ui.editor_import.scan.remote;
+ if remote > 0 {
+ let mut args = FluentArgs::new();
+ args.set("count", remote);
+ bottom = self.paint_import_copy(
+ layers,
+ x,
+ bottom + self.ui_px(20.0),
+ width,
+ &crate::i18n::tr_args("settings-import-editors-remote", &args),
+ palette.muted_text,
+ )?;
+ }
+
+ let chosen = selected;
+ let mut args = FluentArgs::new();
+ args.set("count", chosen);
+ self.paint_import_footer(
+ layers,
+ x,
+ bottom + self.ui_px(32.0),
+ width,
+ Some(SettingsAction::ImportBack),
+ &[ImportButton {
+ label: crate::i18n::tr_args("settings-import-editors-add", &args),
+ action: SettingsAction::EditorImport(EditorImportAction::Add),
+ enabled: chosen > 0 && self.ui.editor_import.space.is_some(),
+ primary: true,
+ }],
+ )
+ }
+
+ /// All, then each editor, with how many folders each has: pills, like
+ /// the Keymap page's switches.
+ fn paint_editor_filters(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ x: f32,
+ y: f32,
+ width: f32,
+ ) -> anyhow::Result<f32> {
+ let palette = self.palette();
+ let accent = self.chrome_palette.accent;
+ let font = Rc::clone(&self.ui_font);
+ let height = self.ui_px(CONTROL_HEIGHT);
+ let gap = self.ui_px(12.0);
+ let pad = self.ui_px(22.0);
+ let scan = &self.ui.editor_import.scan;
+ let mut pills = vec![(
+ format!(
+ "{} {}",
+ crate::i18n::tr("settings-import-editors-all"),
+ scan.folders.len()
+ ),
+ None,
+ )];
+ for (index, editor) in scan.editors.iter().enumerate() {
+ let count = scan.folders_in(Some(index)).count();
+ pills.push((format!("{} {count}", editor.name), Some(index as u8)));
+ }
+ let filter = self.ui.editor_import.filter;
+ let (mut pill_x, mut pill_y) = (x, y);
+ for (label, editor) in pills {
+ let pill_width = self.measure_text_width(&font, &label) + pad * 2.0;
+ if pill_x > x && pill_x + pill_width > x + width {
+ pill_x = x;
+ pill_y += height + gap;
+ }
+ let action = SettingsAction::EditorImport(EditorImportAction::Filter(editor));
+ let on = filter.map(|index| index as u8) == editor;
+ let hovered = self.ui.interaction.hovered == Some(action);
+ let (fill, border, text) = if on {
+ (accent, accent, palette.on_accent)
+ } else if hovered {
+ (palette.control_hover_bg, palette.control_border, palette.text)
+ } else {
+ (palette.control_bg, palette.control_border, palette.text)
+ };
+ self.draw_rounded_frame(
+ layers,
+ 0,
+ pill_x,
+ pill_y,
+ pill_width,
+ height,
+ fill,
+ border,
+ height / 2.0,
+ )?;
+ let text_y = self.control_text_y(pill_y, height);
+ self.draw_text(layers, &font, pill_x + pad, text_y, &label, text, pill_width)?;
+ self.ui_context.push(
+ rect(pill_x, pill_y, pill_width, height),
+ WidgetKind::Button,
+ action,
+ );
+ pill_x += pill_width + gap;
+ }
+ Ok(pill_y + height)
+ }
+
+ /// A folder: its box, its name over its path, and which editor last
+ /// opened it and when -- or that the Space has it already.
+ #[allow(clippy::too_many_arguments)]
+ fn paint_editor_folder_row(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ x: f32,
+ y: f32,
+ width: f32,
+ place: usize,
+ index: usize,
+ draw_top_rule: bool,
+ ) -> anyhow::Result<()> {
+ let palette = self.palette();
+ let ui_font = Rc::clone(&self.ui_font);
+ let body_font = Rc::clone(&self.body_font);
+ let editor_import = &self.ui.editor_import;
+ let folder = editor_import.scan.folders[index].clone();
+ let editor = editor_import
+ .scan
+ .editors
+ .get(folder.editors[0])
+ .map(|editor| editor.name.clone())
+ .unwrap_or_default();
+ let importable = editor_import.importable(index);
+ let selected = importable && editor_import.selected.contains(&index);
+ let action = SettingsAction::EditorImport(EditorImportAction::Toggle(place as u16));
+ let hovered = importable && self.ui.interaction.hovered == Some(action);
+ let pressed = importable && self.ui.interaction.pressed == Some(action);
+
+ if draw_top_rule {
+ self.paint_separator(layers, x, y - self.ui_px(28.0), width)?;
+ }
+ let row_rect = rect(
+ x - self.ui_px(14.0),
+ y - self.ui_px(18.0),
+ width + self.ui_px(28.0),
+ self.settings_row_visual_height() + self.ui_px(18.0),
+ );
+ if importable {
+ self.ui_context.push(row_rect, WidgetKind::Button, action);
+ }
+ if hovered || pressed {
+ self.draw_rounded_rect(
+ layers,
+ 0,
+ row_rect.origin.x,
+ row_rect.origin.y,
+ row_rect.size.width,
+ row_rect.size.height,
+ if pressed {
+ palette.control_pressed_bg
+ } else {
+ palette.control_hover_bg
+ },
+ self.ui_px(16.0),
+ )?;
+ }
+
+ let checkbox = self.ui_px(28.0);
+ let checkbox_y = y + self.ui_px(6.0);
+ let (fill, border) = if selected {
+ (self.chrome_palette.accent, self.chrome_palette.accent)
+ } else if !importable {
+ (
+ palette.control_bg.mul_alpha(0.5),
+ palette.control_border.mul_alpha(0.5),
+ )
+ } else if hovered {
+ (palette.control_hover_bg, self.chrome_palette.accent)
+ } else {
+ (palette.control_bg, palette.control_border)
+ };
+ self.draw_rounded_frame(
+ layers,
+ 0,
+ x,
+ checkbox_y,
+ checkbox,
+ checkbox,
+ fill,
+ border,
+ self.ui_px(8.0),
+ )?;
+ if selected {
+ self.draw_svg_icon(
+ layers,
+ SvgIcon::Check,
+ x + self.ui_px(5.0),
+ checkbox_y + self.ui_px(5.0),
+ checkbox - self.ui_px(10.0),
+ palette.on_accent,
+ )?;
+ }
+
+ let meta = if importable {
+ format!("{editor} · {}", last_used_label(folder.last_used))
+ } else {
+ crate::i18n::tr("settings-import-editors-in-sidebar")
+ };
+ let meta_width = self.measure_text_width(&body_font, &meta).min(width * 0.4);
+ let meta_x = x + width - meta_width;
+ self.draw_text(
+ layers,
+ &body_font,
+ meta_x,
+ y,
+ &meta,
+ palette.muted_text,
+ meta_width + 1.0,
+ )?;
+
+ let label_x = x + checkbox + self.ui_px(18.0);
+ let (name_color, path_color) = if importable {
+ (palette.text, palette.secondary_text)
+ } else {
+ (palette.muted_text, palette.muted_text)
+ };
+ self.draw_text(
+ layers,
+ &ui_font,
+ label_x,
+ y,
+ &folder.name,
+ name_color,
+ (meta_x - label_x - self.ui_px(24.0)).max(0.0),
+ )?;
+ self.draw_text(
+ layers,
+ &body_font,
+ label_x,
+ self.settings_row_description_y(y),
+ &crate::ui::home_relative(&folder.path),
+ path_color,
+ (x + width - label_x).max(0.0),
+ )?;
+ Ok(())
+ }
+
+ /// Which local Space the projects go to, as a row with a menu.
+ fn paint_editor_destination(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ x: f32,
+ y: f32,
+ width: f32,
+ ) -> anyhow::Result<f32> {
+ let palette = self.palette();
+ let ui_font = Rc::clone(&self.ui_font);
+ self.paint_separator(layers, x, y - self.ui_px(28.0), width)?;
+ let (control_x, control_y, control_width) = self.dropdown_control_geometry(x, y, width);
+ self.note_dropdown_anchor(
+ SettingsDropdown::EditorImportSpace,
+ (control_x, control_y, control_width),
+ );
+ let text_width = (control_x - x - self.ui_px(24.0)).max(width * 0.45);
+ let action = SettingsAction::EditorImport(EditorImportAction::SpaceMenu);
+ let label = self.ui.editor_import.space_name();
+ let pill = self.dropdown_pill_rect(control_x, control_y, control_width, &label);
+ let open = self.ui.open_dropdown == Some(SettingsDropdown::EditorImportSpace);
+ let hovered = self.ui.interaction.hovered == Some(action);
+ let pressed = self.ui.interaction.pressed == Some(action);
+ let bg = if pressed || hovered {
+ palette.control_hover_bg
+ } else {
+ palette.control_bg
+ };
+ let border = if open {
+ palette.nav_selected_bg
+ } else if hovered || pressed {
+ palette.separator
+ } else {
+ palette.control_border
+ };
+ self.ui_context.push(pill, WidgetKind::Button, action);
+ self.draw_text(
+ layers,
+ &ui_font,
+ x,
+ y,
+ &crate::i18n::tr("settings-import-editors-add-to"),
+ palette.text,
+ text_width,
+ )?;
+ let extra = self.draw_row_description(
+ layers,
+ x,
+ y,
+ &crate::i18n::tr("settings-import-editors-add-to-description"),
+ text_width,
+ )?;
+ self.paint_dropdown_pill(layers, pill, &label, bg, border)?;
+ Ok(y + self.settings_row_visual_height() + extra)
+ }
+
+ pub(super) fn paint_editor_space_menu(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ x: f32,
+ y: f32,
+ width: f32,
+ ) -> anyhow::Result<()> {
+ let chosen = self.ui.editor_import.space.clone();
+ let options: Vec<_> = self
+ .ui
+ .editor_import
+ .spaces
+ .iter()
+ .enumerate()
+ .map(|(index, (id, name))| {
+ (
+ name.clone(),
+ SettingsAction::EditorImport(EditorImportAction::Space(index as u8)),
+ Some(id) == chosen.as_ref(),
+ )
+ })
+ .collect();
+ self.paint_dropdown_menu(layers, x, y, width, &options)
+ }
+
+ pub(super) fn paint_editor_result(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ x: f32,
+ top: f32,
+ width: f32,
+ ) -> anyhow::Result<f32> {
+ let (count, space) = self.ui.editor_import.added.clone().unwrap_or_default();
+ let mut args = FluentArgs::new();
+ args.set("count", count);
+ args.set("space", space);
+ let message = crate::i18n::tr_args("settings-import-editors-done", &args);
+ let bottom = self.paint_import_result(layers, x, top + self.ui_px(64.0), width, &message)?;
+ self.paint_import_footer(
+ layers,
+ x,
+ bottom + self.ui_px(40.0),
+ width,
+ Some(SettingsAction::ImportStartOver),
+ &[],
+ )
+ }
+
+ /// Editors' marks on overlapping tiles of side `tile`, from `x`.
+ pub(super) fn paint_editor_stack(
+ &self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ kinds: &[EditorKind],
+ x: f32,
+ y: f32,
+ tile: f32,
+ ground: LinearRgba,
+ ) -> anyhow::Result<()> {
+ let ctx = crate::ui::draw::DrawContext::new(
+ self.render_state.as_ref().unwrap(),
+ self.dimensions,
+ &self.metrics,
+ );
+ let dark = self.chrome_palette.is_dark();
+ editor_projects::draw_stack(&ctx, layers, kinds, x, y, tile, ground, dark)
+ }
+
+ /// Read what the editors opened on a thread of its own, aimed at `space`,
+ /// and show it when it comes back.
+ pub(super) fn start_editor_import(&mut self, space: Option<String>) {
+ let (generation, spaces) = self.ui.editor_import.begin(space);
+ let instance_id = self.instance_id;
+ promise::spawn::spawn(async move {
+ let found = promise::spawn::spawn_into_new_thread(move || {
+ Ok::<_, anyhow::Error>(read(spaces))
+ })
+ .await
+ .unwrap_or_else(|err| {
+ log::warn!("reading the folders code editors opened failed: {err:#}");
+ Found::default()
+ });
+ promise::spawn::spawn_into_main_thread(async move {
+ let Some(settings) = settings_window_for_instance(instance_id) else {
+ return;
+ };
+ let mut settings = settings.borrow_mut();
+ settings.ui.editor_import.finish(generation, found);
+ if let Some(window) = &settings.window {
+ window.invalidate();
+ }
+ })
+ .detach();
+ })
+ .detach();
+ }
+
+ pub(super) fn perform_editor_import_action(&mut self, action: EditorImportAction) {
+ match action {
+ EditorImportAction::Filter(editor) => {
+ let editors = self.ui.editor_import.scan.editors.len();
+ self.ui.editor_import.filter =
+ editor.map(usize::from).filter(|&index| index < editors);
+ }
+ EditorImportAction::Toggle(place) => {
+ let editor_import = &mut self.ui.editor_import;
+ let Some(&index) = editor_import.rows.get(place as usize) else {
+ return;
+ };
+ if !editor_import.importable(index) {
+ return;
+ }
+ if !editor_import.selected.remove(&index) {
+ editor_import.selected.insert(index);
+ }
+ }
+ EditorImportAction::SelectAll => {
+ let editor_import = &mut self.ui.editor_import;
+ for index in editor_import.visible() {
+ if editor_import.importable(index) {
+ editor_import.selected.insert(index);
+ }
+ }
+ }
+ EditorImportAction::Clear => {
+ let editor_import = &mut self.ui.editor_import;
+ for index in editor_import.visible() {
+ editor_import.selected.remove(&index);
+ }
+ }
+ EditorImportAction::SpaceMenu => {
+ self.ui.open_dropdown =
+ if self.ui.open_dropdown == Some(SettingsDropdown::EditorImportSpace) {
+ None
+ } else {
+ Some(SettingsDropdown::EditorImportSpace)
+ };
+ }
+ EditorImportAction::Space(place) => {
+ self.ui.open_dropdown = None;
+ let Some((id, _)) = self.ui.editor_import.spaces.get(place as usize).cloned()
+ else {
+ return;
+ };
+ self.ui.editor_import.retarget(Some(id));
+ }
+ EditorImportAction::Add => {
+ let editor_import = &self.ui.editor_import;
+ let Some(space) = editor_import.space.clone() else {
+ return;
+ };
+ let paths: Vec<PathBuf> = editor_import
+ .chosen()
+ .into_iter()
+ .map(|index| editor_import.scan.folders[index].path.clone())
+ .collect();
+ let none = ResolvedProjects::default();
+ let known = editor_import.known.get(&space).unwrap_or(&none);
+ let added = crate::workspace_threads::add_projects(&space, &paths, known);
+ let name = editor_import.space_name();
+ self.ui.editor_import.added = Some((added, name));
+ self.ui.import_step = ImportStep::Result;
+ self.ui.content_scroll.reset();
+ if let Some(front_end) = crate::frontend::try_front_end() {
+ front_end.invalidate_all_windows();
+ }
+ }
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn found(path: &str) -> Found {
+ Found {
+ scan: Scan {
+ editors: Vec::new(),
+ folders: vec![editor_projects::Folder {
+ path: PathBuf::from(path),
+ name: "app".to_string(),
+ editors: vec![0],
+ last_used: SystemTime::now(),
+ }],
+ remote: 0,
+ },
+ known: HashMap::new(),
+ }
+ }
+
+ fn reading(generation: u64) -> EditorImportUi {
+ EditorImportUi {
+ loading: true,
+ generation,
+ space: Some("space-a".to_string()),
+ ..EditorImportUi::default()
+ }
+ }
+
+ #[test]
+ fn a_read_that_is_no_longer_wanted_is_dropped() {
+ let mut ui = reading(2);
+ ui.finish(1, found("/code/old"));
+ assert!(ui.loading && ui.scan.folders.is_empty());
+
+ ui.release();
+ ui.finish(2, found("/code/app"));
+ assert!(!ui.loading && ui.scan.folders.is_empty(), "the page was left");
+
+ let mut ui = reading(3);
+ ui.finish(3, found("/code/app"));
+ assert!(!ui.loading);
+ // Used just now and not in the Space: ticked.
+ assert!(ui.selected.contains(&0));
+ }
+
+ #[test]
+ fn a_folder_the_space_has_archived_can_be_added_again() {
+ let mut ui = reading(1);
+ let mut read = found("/code/app");
+ let project = |archived| {
+ HashMap::from([(
+ PathBuf::from("/code/app"),
+ ("project-a".to_string(), archived),
+ )])
+ };
+ read.known.insert("space-a".to_string(), project(true));
+ ui.finish(1, read);
+ assert!(ui.importable(0));
+ ui.known.insert("space-a".to_string(), project(false));
+ assert!(!ui.importable(0));
+ }
+}
diff --git a/wezterm-gui/src/settings_window/import.rs b/wezterm-gui/src/settings_window/import.rs
index ed56101c..2240d1ee 100644
--- a/wezterm-gui/src/settings_window/import.rs
+++ b/wezterm-gui/src/settings_window/import.rs
@@ -10,13 +10,21 @@ pub(super) enum ImportStep {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum ImportSource {
WezTerm,
+ /// The folders VS Code and the editors built from it have opened.
+ Editors,
#[cfg(unix)]
Session(&'static str),
}
+/// What first-run setup and the Import page call the editors' source.
+pub(crate) const EDITORS_SOURCE: &str = "editors";
+
impl ImportSource {
pub(super) fn all() -> Vec<Self> {
let mut sources = vec![Self::WezTerm];
+ if !crate::editor_projects::installed().is_empty() {
+ sources.push(Self::Editors);
+ }
#[cfg(unix)]
sources.extend(
thinkterm_import::sources()
@@ -31,6 +39,7 @@ impl ImportSource {
pub(super) fn named(id: Option<&str>) -> Option<Self> {
match id {
None => Some(Self::WezTerm),
+ Some(EDITORS_SOURCE) => Some(Self::Editors),
#[cfg(unix)]
Some(id) => thinkterm_import::sources()
.into_iter()
@@ -46,8 +55,12 @@ impl ImportSource {
if let Some(source) = session_import::remembered_source() {
return source;
}
+ let selected = std::env::var("THINKTERM_SETTINGS_SECTION").ok();
+ if selected.as_deref() == Some(EDITORS_SOURCE) {
+ return Self::Editors;
+ }
#[cfg(unix)]
- if let Ok(selected) = std::env::var("THINKTERM_SETTINGS_SECTION") {
+ if let Some(selected) = selected {
if let Some(source) = thinkterm_import::sources()
.into_iter()
.find(|s| s.id.eq_ignore_ascii_case(&selected))
@@ -62,25 +75,28 @@ impl ImportSource {
/// is new enough to carry a Beta badge.
fn is_beta(self) -> bool {
match self {
- Self::WezTerm => false,
+ Self::WezTerm | Self::Editors => false,
#[cfg(unix)]
Self::Session(_) => true,
}
}
- pub(super) fn label(self) -> &'static str {
+ pub(super) fn label(self) -> String {
match self {
- Self::WezTerm => "WezTerm",
+ Self::WezTerm => "WezTerm".to_string(),
+ Self::Editors => crate::i18n::tr("settings-import-editors"),
#[cfg(unix)]
Self::Session(id) => thinkterm_import::source(id)
.map(|s| s.info().name)
- .unwrap_or(id),
+ .unwrap_or(id)
+ .to_string(),
}
}
fn description(self) -> String {
crate::i18n::tr(match self {
Self::WezTerm => "settings-import-wezterm-description",
+ Self::Editors => "settings-import-editors-description",
#[cfg(unix)]
Self::Session(_) => "settings-import-session-description",
})
@@ -89,6 +105,8 @@ impl ImportSource {
fn icon(self) -> Option<BrandIcon> {
match self {
Self::WezTerm => Some(BrandIcon::WezTerm),
+ // Drawn as its editors' marks, see `paint_editor_stack`.
+ Self::Editors => None,
#[cfg(unix)]
Self::Session(id) => {
BrandIcon::for_import_source(thinkterm_import::source(id).ok()?.info().icon)
@@ -101,6 +119,7 @@ impl ImportSource {
match self {
Self::Session(id) => thinkterm_import::source(id),
Self::WezTerm => anyhow::bail!("The selected source imports settings, not sessions"),
+ Self::Editors => anyhow::bail!("The selected source imports folders, not sessions"),
}
}
@@ -113,7 +132,8 @@ impl ImportSource {
for (name, value) in values {
args.set(*name, value.as_str());
}
- args.set("source", self.label());
+ let label = self.label();
+ args.set("source", label.as_str());
crate::i18n::tr_args(key, &args)
}
}
@@ -166,6 +186,10 @@ impl SettingsWindow {
ImportSource::WezTerm => {
self.perform_action(SettingsAction::LoadWezTermSource, window)
}
+ ImportSource::Editors => {
+ let space = OPENED_FROM_SPACE.with(|slot| slot.borrow().clone());
+ self.start_editor_import(space);
+ }
#[cfg(unix)]
ImportSource::Session(_) => {
self.perform_session_import_action(SettingsAction::SessionImportDetect)
@@ -186,6 +210,7 @@ impl SettingsWindow {
SettingsAction::ImportStartOver => {
self.ui.import_step = ImportStep::Source;
self.ui.import_result = None;
+ self.ui.editor_import.release();
#[cfg(unix)]
{
self.ui.session_import.abandon();
@@ -250,6 +275,7 @@ impl SettingsWindow {
}
ImportStep::Review => match self.ui.import_source {
ImportSource::WezTerm => self.paint_wezterm_import(layers, x, top, width)?,
+ ImportSource::Editors => self.paint_editor_import(layers, x, top, width)?,
#[cfg(unix)]
ImportSource::Session(_) => self.paint_session_import(layers, x, top, width)?,
},
@@ -277,6 +303,7 @@ impl SettingsWindow {
}],
)?
}
+ ImportSource::Editors => self.paint_editor_result(layers, x, top, width)?,
#[cfg(unix)]
ImportSource::Session(_) => self.paint_session_result(layers, x, top, width)?,
},
@@ -572,9 +599,16 @@ impl SettingsWindow {
description: &str,
) -> anyhow::Result<f32> {
let mark = self.ui_px(88.0).min(width * 0.2);
+ // The editors stand side by side, each on a tile as big as another
+ // source's mark.
+ let editors = (self.ui.import_source == ImportSource::Editors)
+ .then(|| self.ui.editor_import.kinds());
+ let mark_width = editors.as_ref().map_or(mark, |kinds| {
+ crate::editor_projects::stack_width(kinds.len(), mark)
+ });
let gap = self.ui_px(24.0);
- let left = x + mark + gap;
- let inner = (width - mark - gap).max(1.0);
+ let left = x + mark_width + gap;
+ let inner = (width - mark_width - gap).max(1.0);
let title_font = Rc::clone(&self.title_font);
let body_font = Rc::clone(&self.import_body_font);
let title_lines = self.wrap_settings_text(&title_font, title, inner);
@@ -593,14 +627,17 @@ impl SettingsWindow {
+ self.ui_px(4.0)
+ body_height * body_lines.len() as f32;
let height = mark.max(text_height);
- if let Some(icon) = self.ui.import_source.icon() {
- self.draw_brand_icon(layers, icon, x, y + (height - mark) / 2.0, mark)?;
+ let mark_y = y + (height - mark) / 2.0;
+ if let Some(kinds) = &editors {
+ self.paint_editor_stack(layers, kinds, x, mark_y, mark, self.palette().window_bg)?;
+ } else if let Some(icon) = self.ui.import_source.icon() {
+ self.draw_brand_icon(layers, icon, x, mark_y, mark)?;
} else {
self.draw_svg_icon(
layers,
SvgIcon::Terminal,
x,
- y + (height - mark) / 2.0,
+ mark_y,
mark,
self.palette().text,
)?;
@@ -816,7 +853,21 @@ impl SettingsWindow {
},
self.ui_px(32.0),
)?;
- if let Some(brand) = source.icon() {
+ if *source == ImportSource::Editors {
+ let kinds = crate::editor_projects::stack_kinds(
+ crate::editor_projects::installed().iter().copied(),
+ );
+ let tile = (icon * 0.6).round();
+ let span = crate::editor_projects::stack_width(kinds.len(), tile);
+ self.paint_editor_stack(
+ layers,
+ &kinds,
+ left + (card_width - span) / 2.0,
+ top + pad + (icon - tile) / 2.0,
+ tile,
+ ground,
+ )?;
+ } else if let Some(brand) = source.icon() {
self.draw_brand_icon(
layers,
brand,
@@ -835,7 +886,8 @@ impl SettingsWindow {
)?;
}
let title_y = top + pad + icon + self.ui_px(24.0);
- let title_width = self.measure_text_width(&heading, source.label());
+ let label = source.label();
+ let title_width = self.measure_text_width(&heading, &label);
// The title and its badge are centered as one line.
let badge_gap = self.ui_px(14.0);
let badge_width = if source.is_beta() {
@@ -849,7 +901,7 @@ impl SettingsWindow {
&heading,
title_x,
title_y,
- source.label(),
+ &label,
palette.title,
text_width,
)?;
diff --git a/wezterm-gui/src/settings_window/session_import.rs b/wezterm-gui/src/settings_window/session_import.rs
index dd486d1e..ba6d8913 100644
--- a/wezterm-gui/src/settings_window/session_import.rs
+++ b/wezterm-gui/src/settings_window/session_import.rs
@@ -262,7 +262,7 @@ fn host_connected(name: &str) -> bool {
fn source_id(source: ImportSource) -> Option<&'static str> {
match source {
ImportSource::Session(id) => Some(id),
- ImportSource::WezTerm => None,
+ ImportSource::WezTerm | ImportSource::Editors => None,
}
}
diff --git a/wezterm-gui/src/termwindow/onboarding.rs b/wezterm-gui/src/termwindow/onboarding.rs
index bd04dbee..11479ef1 100644
--- a/wezterm-gui/src/termwindow/onboarding.rs
+++ b/wezterm-gui/src/termwindow/onboarding.rs
@@ -218,11 +218,24 @@ fn focus_order(found: &found::Found) -> Vec<OnboardingAction> {
if found.wezterm_config {
order.push(OnboardingAction::Import(None));
}
+ if found.editors.is_some() {
+ order.push(OnboardingAction::Import(Some(
+ crate::settings_window::EDITORS_SOURCE,
+ )));
+ }
order.push(OnboardingAction::Skip);
order.push(OnboardingAction::Start);
order
}
+/// What heads a row of the found card.
+enum FoundMark {
+ /// A program's own mark, or a terminal where it has none.
+ Program(Option<BrandIcon>),
+ /// Editors' marks on overlapping tiles.
+ Editors(Vec<crate::editor_projects::EditorKind>),
+}
+
/// SplitMix64 over a pair: the curtain's fixed pattern.
fn curtain_hash(a: u64, b: u64) -> u64 {
let mut z = a.wrapping_mul(0x9E37_79B9_7F4A_7C15) ^ b.wrapping_add(0xBF58_476D_1CE4_E5B9);
@@ -825,8 +838,7 @@ impl OnboardingView {
};
let show_found = !self.found.is_empty();
- let found_rows =
- (self.found.sessions.len() + usize::from(self.found.wezterm_config)) as f32;
+ let found_rows = self.found.rows() as f32;
let privacy = crate::i18n::tr("onboarding-privacy");
let start_label = crate::i18n::tr("onboarding-start");
@@ -1366,7 +1378,7 @@ impl OnboardingView {
fx(FOUND_RADIUS),
)?;
- let mut rows: Vec<(Option<BrandIcon>, String, String, String, OnboardingAction)> = self
+ let mut rows: Vec<(FoundMark, String, String, String, OnboardingAction)> = self
.found
.sessions
.iter()
@@ -1381,7 +1393,7 @@ impl OnboardingView {
_ => crate::i18n::tr_args("onboarding-found-sessions", &args),
};
(
- sessions.icon,
+ FoundMark::Program(sessions.icon),
sessions.name.to_string(),
detail,
crate::i18n::tr("onboarding-found-import"),
@@ -1391,17 +1403,36 @@ impl OnboardingView {
.collect();
if self.found.wezterm_config {
rows.push((
- Some(BrandIcon::WezTerm),
+ FoundMark::Program(Some(BrandIcon::WezTerm)),
"WezTerm".to_string(),
crate::i18n::tr("onboarding-found-wezterm"),
crate::i18n::tr("onboarding-found-import-settings"),
OnboardingAction::Import(None),
));
}
+ if let Some(editors) = &self.found.editors {
+ rows.push((
+ FoundMark::Editors(editors.kinds.clone()),
+ editors.names.clone(),
+ crate::i18n::tr("onboarding-found-editors"),
+ crate::i18n::tr("onboarding-found-choose-projects"),
+ OnboardingAction::Import(Some(crate::settings_window::EDITORS_SOURCE)),
+ ));
+ }
let pad_x = fx(FOUND_PAD_X);
let icon = fx(FOUND_ICON);
- for (index, (brand, name, detail, button, action)) in rows.iter().enumerate() {
+ // A row of editors is wider than one mark; every mark is centred
+ // in the widest, so the names still line up.
+ let mark_width = |mark: &FoundMark| match mark {
+ FoundMark::Program(_) => icon,
+ FoundMark::Editors(kinds) => crate::editor_projects::stack_width(kinds.len(), icon),
+ };
+ let column = rows
+ .iter()
+ .map(|(mark, ..)| mark_width(mark))
+ .fold(icon, f32::max);
+ for (index, (mark, name, detail, button, action)) in rows.iter().enumerate() {
let top = card.origin.y + index as f32 * row_h;
if index > 0 {
ctx.draw_rect(
@@ -1414,11 +1445,14 @@ impl OnboardingView {
skin.chip_border,
)?;
}
- let icon_x = card.origin.x + pad_x;
+ let column_x = card.origin.x + pad_x;
+ let icon_x = column_x + (column - mark_width(mark)) / 2.0;
let icon_y = top + (row_h - icon) / 2.0;
- match brand {
- Some(brand) => ctx.draw_brand_icon(layers, *brand, icon_x, icon_y, icon)?,
- None => ctx.draw_svg_icon(
+ match mark {
+ FoundMark::Program(Some(brand)) => {
+ ctx.draw_brand_icon(layers, *brand, icon_x, icon_y, icon)?
+ }
+ FoundMark::Program(None) => ctx.draw_svg_icon(
layers,
SvgIcon::Terminal,
icon_x,
@@ -1426,6 +1460,16 @@ impl OnboardingView {
icon,
skin.secondary_text,
)?,
+ FoundMark::Editors(kinds) => crate::editor_projects::draw_stack(
+ ctx,
+ layers,
+ kinds,
+ icon_x,
+ icon_y,
+ icon,
+ skin.chip_bg,
+ skin.dark,
+ )?,
}
let button_w = (self.width(ctx, font, button) + ctx.px(BTN_PAD_X) * 2.0).ceil();
@@ -1442,7 +1486,7 @@ impl OnboardingView {
false,
)?;
- let text_x = icon_x + icon + fx(FOUND_ICON_GAP);
+ let text_x = column_x + column + fx(FOUND_ICON_GAP);
let text_w = (button_x - fx(FOUND_ICON_GAP) - text_x).max(1.0);
let text_y = top + (row_h - body_h * 2.0 - fx(FOUND_LINE_GAP)) / 2.0;
self.text(ctx, layers, font, text_x, text_y, name, skin.text, text_w)?;
@@ -1858,6 +1902,8 @@ struct Skin {
face_border: LinearRgba,
/// The open language menu, a step off the page so it reads as above it.
menu_bg: LinearRgba,
+ /// Whether the page is dark, which lit tiles shade for.
+ dark: bool,
shadow: LinearRgba,
primary_bg: LinearRgba,
primary_text: LinearRgba,
@@ -1885,6 +1931,7 @@ impl Skin {
ground,
face_border: mix(ground, palette.text, 0.24),
menu_bg: mix(ground, palette.text, 0.05),
+ dark: palette.is_dark(),
shadow: LinearRgba::with_components(0.0, 0.0, 0.0, 0.35),
// The mono inversion: the primary action is the highest-contrast
// thing on the page without introducing a hue.
@@ -2184,6 +2231,7 @@ mod tests {
let found = found::Found {
sessions: vec![found::FoundSessions::for_test("example", 2, Some(1))],
wezterm_config: true,
+ editors: None,
};
let order = focus_order(&found);
assert!(order.contains(&OnboardingAction::Import(Some("example"))));
@@ -2280,12 +2328,14 @@ mod tests {
let found = found::Found {
sessions: vec![found::FoundSessions::for_test("example", 2, None)],
wezterm_config: false,
+ editors: None,
};
assert!(found.pending());
assert!(!found.is_empty());
let found = found::Found {
sessions: vec![found::FoundSessions::for_test("example", 2, Some(0))],
wezterm_config: false,
+ editors: None,
};
assert!(!found.pending());
assert!(found::Found::default().is_empty());
diff --git a/wezterm-gui/src/termwindow/onboarding/found.rs b/wezterm-gui/src/termwindow/onboarding/found.rs
index 256daf9a..f3e7bc28 100644
--- a/wezterm-gui/src/termwindow/onboarding/found.rs
+++ b/wezterm-gui/src/termwindow/onboarding/found.rs
@@ -1,5 +1,6 @@
//! What first-run setup offers to bring in from this computer: another
-//! program's terminal sessions, and a WezTerm configuration.
+//! program's terminal sessions, a WezTerm configuration, and the folders
+//! code editors have opened.
//!
//! What is on disk is read when the page opens, so the page has its final
//! height from the first frame. Whether a session is running means asking
@@ -28,10 +29,19 @@ impl FoundSessions {
}
}
+/// Code editors that opened folders no local Space has yet.
+pub(super) struct FoundEditors {
+ /// The editors, by name, as one line: "VS Code, Cursor".
+ pub names: String,
+ /// The editors whose marks the row shows.
+ pub kinds: Vec<crate::editor_projects::EditorKind>,
+}
+
#[derive(Default)]
pub(super) struct Found {
pub sessions: Vec<FoundSessions>,
pub wezterm_config: bool,
+ pub editors: Option<FoundEditors>,
}
impl Found {
@@ -39,11 +49,17 @@ impl Found {
Self {
sessions: sessions(),
wezterm_config: crate::settings_window::wezterm_config_found(),
+ editors: editors(),
}
}
pub fn is_empty(&self) -> bool {
- self.sessions.is_empty() && !self.wezterm_config
+ self.sessions.is_empty() && !self.wezterm_config && self.editors.is_none()
+ }
+
+ /// One per program the page offers to import from.
+ pub fn rows(&self) -> usize {
+ self.sessions.len() + usize::from(self.wezterm_config) + usize::from(self.editors.is_some())
}
/// Whether a running check is still out.
@@ -52,6 +68,35 @@ impl Found {
}
}
+/// The editors that opened a folder no local Space has. Read on this
+/// thread: it is small files on disk, as the WezTerm check is. Only what
+/// the editors wrote down is read -- looking at the folders could ask macOS
+/// for Documents or the Desktop before anyone chose to import -- so this is
+/// a hint: a folder gone since, or one a project reaches by another path (a
+/// symlink), is sorted out by the Import page, which looks.
+fn editors() -> Option<FoundEditors> {
+ if crate::editor_projects::installed().is_empty() {
+ return None;
+ }
+ let scan = crate::editor_projects::scan(&|path| Some(path.to_path_buf()));
+ let mut known = std::collections::HashSet::new();
+ for (space, _) in crate::workspace_threads::local_spaces() {
+ known.extend(
+ crate::workspace_threads::project_paths_for_space(&space)
+ .into_iter()
+ .map(std::path::PathBuf::from),
+ );
+ }
+ if scan.folders.iter().all(|folder| known.contains(&folder.path)) {
+ return None;
+ }
+ let names: Vec<&str> = scan.editors.iter().map(|editor| editor.name.as_str()).collect();
+ Some(FoundEditors {
+ names: names.join(", "),
+ kinds: crate::editor_projects::stack_kinds(scan.editors.iter().map(|editor| editor.kind)),
+ })
+}
+
#[cfg(unix)]
fn sessions() -> Vec<FoundSessions> {
let Ok(context) = wezterm_mux_server_impl::session_import::context() else {
diff --git a/wezterm-gui/src/termwindow/ui/icons.rs b/wezterm-gui/src/termwindow/ui/icons.rs
index 1ed33bdb..a38b33e8 100644
--- a/wezterm-gui/src/termwindow/ui/icons.rs
+++ b/wezterm-gui/src/termwindow/ui/icons.rs
@@ -132,6 +132,9 @@ pub enum SvgIcon {
AgentKimi,
AgentOpenCode,
AgentPi,
+ // VS Code's mark, from the Material Icon Theme's file icons. Its own
+ // blue is ignored like any glyph's colour: it takes the caller's tint.
+ VsCode,
}
impl SvgIcon {
@@ -395,6 +398,9 @@ impl SvgIcon {
include_bytes!("../../../../third_party/lobe-icons/opencode.svg")
}
Self::AgentPi => include_bytes!("../../../../third_party/lobe-icons/pi.svg"),
+ Self::VsCode => {
+ include_bytes!("../../../../third_party/material-icon-theme/icons/vscode.svg")
+ }
}
}
@@ -536,6 +542,7 @@ pub enum BrandIcon {
ArchLinux,
CentOS,
Claude,
+ Cursor,
Debian,
Docker,
Fedora,
@@ -548,7 +555,9 @@ pub enum BrandIcon {
RaspberryPi,
RedHat,
Ubuntu,
+ VSCodium,
WezTerm,
+ Windsurf,
}
/// Brand colors darker than this perceived luminance (0..=255) are rendered
@@ -588,6 +597,7 @@ impl BrandIcon {
}
Self::CentOS => include_bytes!("../../../../third_party/simple-icons/icons/centos.svg"),
Self::Claude => include_bytes!("../../../../third_party/simple-icons/icons/claude.svg"),
+ Self::Cursor => include_bytes!("../../../../third_party/simple-icons/icons/cursor.svg"),
Self::Debian => include_bytes!("../../../../third_party/simple-icons/icons/debian.svg"),
Self::Docker => include_bytes!("../../../../third_party/simple-icons/icons/docker.svg"),
Self::Fedora => include_bytes!("../../../../third_party/simple-icons/icons/fedora.svg"),
@@ -604,7 +614,13 @@ impl BrandIcon {
}
Self::RedHat => include_bytes!("../../../../third_party/simple-icons/icons/redhat.svg"),
Self::Ubuntu => include_bytes!("../../../../third_party/simple-icons/icons/ubuntu.svg"),
+ Self::VSCodium => {
+ include_bytes!("../../../../third_party/simple-icons/icons/vscodium.svg")
+ }
Self::WezTerm => include_bytes!("../../../../assets/icon/wezterm-icon.svg"),
+ Self::Windsurf => {
+ include_bytes!("../../../../third_party/simple-icons/icons/windsurf.svg")
+ }
}
}
@@ -634,6 +650,7 @@ impl BrandIcon {
Self::ArchLinux => (0x17, 0x93, 0xD1),
Self::CentOS => (0x26, 0x25, 0x77),
Self::Claude => (0xD9, 0x77, 0x57),
+ Self::Cursor => (0x00, 0x00, 0x00),
Self::Debian => (0xA8, 0x1D, 0x33),
Self::Docker => (0x24, 0x96, 0xED),
Self::Fedora => (0x51, 0xA2, 0xDA),
@@ -646,7 +663,9 @@ impl BrandIcon {
Self::RaspberryPi => (0xA2, 0x28, 0x46),
Self::RedHat => (0xEE, 0x00, 0x00),
Self::Ubuntu => (0xE9, 0x54, 0x20),
+ Self::VSCodium => (0x2F, 0x80, 0xED),
Self::WezTerm => (0x4E, 0x49, 0xEE),
+ Self::Windsurf => (0x0B, 0x10, 0x0F),
}
}
@@ -874,6 +893,7 @@ mod tests {
SvgIcon::AgentKimi,
SvgIcon::AgentOpenCode,
SvgIcon::AgentPi,
+ SvgIcon::VsCode,
] {
let data: Vec<u8> = icon.rasterize(24).unwrap().into();
assert_eq!(data.len(), 24 * 24 * 4);
@@ -896,6 +916,7 @@ mod tests {
BrandIcon::ArchLinux,
BrandIcon::CentOS,
BrandIcon::Claude,
+ BrandIcon::Cursor,
BrandIcon::Debian,
BrandIcon::Docker,
BrandIcon::Fedora,
@@ -908,7 +929,9 @@ mod tests {
BrandIcon::RaspberryPi,
BrandIcon::RedHat,
BrandIcon::Ubuntu,
+ BrandIcon::VSCodium,
BrandIcon::WezTerm,
+ BrandIcon::Windsurf,
] {
let data: Vec<u8> = icon.rasterize(24).unwrap().into();
assert_eq!(data.len(), 24 * 24 * 4);
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 2fa63153..2247c255 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -2519,6 +2519,108 @@ pub fn create_project_from_path(space_id: &str, path: &str) -> Result<WorkspaceT
Ok(thread_id)
}
+/// The Spaces whose terminals run on this computer, by id and name, in the
+/// sidebar's order.
+pub fn local_spaces() -> Vec<(SpaceId, String)> {
+ let mut store = THREAD_STORE.lock();
+ if store.normalize_after_load() {
+ persist_locked(&store);
+ }
+ store
+ .spaces
+ .iter()
+ .filter(|space| space.client_domain.is_none())
+ .map(|space| (space.id.clone(), space.name.clone()))
+ .collect()
+}
+
+/// `path` resolved, as the sidebar opens a folder, so two spellings of one
+/// folder compare equal. None for a folder that is not there. Taken as it
+/// is first: a name the sidebar's typed-in form would trim is still found.
+pub fn project_path_key(path: &Path) -> Option<PathBuf> {
+ match fs::canonicalize(path) {
+ Ok(canonical) => canonical
+ .is_dir()
+ .then(|| shell_compatible_project_path(canonical)),
+ Err(_) => normalize_project_path(&path.to_string_lossy()).ok(),
+ }
+}
+
+/// A Space's projects by their folder, resolved as by `project_path_key`,
+/// each with its id and whether it is archived.
+pub type ResolvedProjects = HashMap<PathBuf, (ProjectId, bool)>;
+
+/// `space_id`'s projects as [`ResolvedProjects`]. Every folder is looked up
+/// on disk, so this belongs on a thread of its own rather than the UI's: a
+/// project on a network share that has gone away can take seconds.
+pub fn resolved_projects(space_id: &str) -> ResolvedProjects {
+ let projects: Vec<(ProjectId, PathBuf, bool)> = {
+ let store = THREAD_STORE.lock();
+ store
+ .projects
+ .iter()
+ .filter(|project| project.space_id == space_id)
+ .map(|project| (project.id.clone(), project.path.clone(), project.is_archived()))
+ .collect()
+ };
+ // Resolved with the store let go: it is the file system's turn.
+ by_folder(
+ projects
+ .into_iter()
+ .filter_map(|(id, path, archived)| Some((project_path_key(&path)?, id, archived))),
+ )
+}
+
+/// Projects by resolved folder. Where two resolve to one folder -- added
+/// under two spellings of it -- the one the sidebar shows wins, so the
+/// folder reads as there already rather than as one to bring back.
+fn by_folder(projects: impl IntoIterator<Item = (PathBuf, ProjectId, bool)>) -> ResolvedProjects {
+ let mut by_folder = ResolvedProjects::new();
+ for (folder, id, archived) in projects {
+ if by_folder
+ .get(&folder)
+ .map_or(true, |(_, kept_archived)| *kept_archived)
+ {
+ by_folder.insert(folder, (id, archived));
+ }
+ }
+ by_folder
+}
+
+/// Add a project for each of `paths`, resolved already, to `space_id`, each
+/// with one thread that starts when it is first opened. The Space's active
+/// project stays put: an import adds to the sidebar, it does not navigate.
+/// `known` is the Space's projects as `resolved_projects` found them: one of
+/// those, however its path is spelled, is left as it is or brought back if
+/// archived. Nothing here asks the file system. How many the sidebar gained.
+pub fn add_projects(space_id: &str, paths: &[PathBuf], known: &ResolvedProjects) -> usize {
+ let mut store = THREAD_STORE.lock();
+ store.normalize_after_load();
+ if !store.has_space(space_id) {
+ return 0;
+ }
+ let mut added = 0;
+ for path in paths {
+ let kept = known
+ .get(path)
+ .map(|(project_id, _)| project_id)
+ .filter(|project_id| store.projects.iter().any(|project| &project.id == *project_id));
+ let gained = match kept {
+ Some(project_id) => store.unarchive_project(project_id),
+ None => store.add_project_for_path(space_id, path.clone()),
+ };
+ if gained {
+ added += 1;
+ }
+ }
+ if added > 0 {
+ // A Space that had no project to open now has one.
+ store.normalize_after_load();
+ persist_locked(&store);
+ }
+ added
+}
+
pub fn create_disconnected_remote_host_thread(
space_id: &str,
host_id: &str,
@@ -6497,32 +6599,28 @@ impl WorkspaceThreadStore {
}
}
- let name = path
- .file_name()
- .and_then(|name| name.to_str())
- .filter(|name| !name.is_empty())
- .unwrap_or("Project")
- .to_string();
- let mut project = Project {
- id: project_id.clone(),
- space_id: space_id.to_string(),
- name,
- path,
- threads: vec![],
- active_thread_id: None,
- threads_collapsed: false,
- active_note_path: None,
- archived_at: None,
- };
- let session = WorkspaceThread::new(project_id.clone(), "main".to_string(), None);
- let thread_id = session.id.clone();
- project.active_thread_id = Some(thread_id.clone());
- project.threads.push(session);
+ let (project, thread_id) = new_project_for_path(space_id, project_id.clone(), path);
self.set_active_project_for_space(space_id, project_id);
self.projects.push(project);
thread_id
}
+ /// A project for `path` in `space_id`, unless the Space has one for it;
+ /// an archived one is brought back. Whether the sidebar gained one.
+ fn add_project_for_path(&mut self, space_id: &str, path: PathBuf) -> bool {
+ if let Some(project) = self
+ .projects
+ .iter_mut()
+ .find(|project| project.space_id == space_id && project.path == path)
+ {
+ return project.archived_at.take().is_some();
+ }
+ let project_id = project_id_for_path(space_id, &path);
+ let (project, _) = new_project_for_path(space_id, project_id, path);
+ self.projects.push(project);
+ true
+ }
+
fn project_id_for_workspace(&self, space_id: &str, workspace: &str) -> Option<ProjectId> {
self.projects.iter().find_map(|project| {
if project.space_id != space_id {
@@ -9270,6 +9368,37 @@ fn thread_has_restorable_workspace(thread: &WorkspaceThread) -> bool {
thread.layout.is_some() || thread.materialized_workspace_name.is_some()
}
+/// A project for `path` with one thread, named for the folder, and that
+/// thread's id.
+fn new_project_for_path(
+ space_id: &str,
+ project_id: ProjectId,
+ path: PathBuf,
+) -> (Project, WorkspaceThreadId) {
+ let name = path
+ .file_name()
+ .and_then(|name| name.to_str())
+ .filter(|name| !name.is_empty())
+ .unwrap_or("Project")
+ .to_string();
+ let mut project = Project {
+ id: project_id.clone(),
+ space_id: space_id.to_string(),
+ name,
+ path,
+ threads: vec![],
+ active_thread_id: None,
+ threads_collapsed: false,
+ active_note_path: None,
+ archived_at: None,
+ };
+ let session = WorkspaceThread::new(project_id, "main".to_string(), None);
+ let thread_id = session.id.clone();
+ project.active_thread_id = Some(thread_id.clone());
+ project.threads.push(session);
+ (project, thread_id)
+}
+
fn normalize_project_path(path: &str) -> Result<PathBuf> {
let trimmed = path.trim();
ensure!(!trimmed.is_empty(), "project path is empty");
@@ -11733,6 +11862,57 @@ mod tests {
);
}
+ #[test]
+ fn a_folder_two_projects_share_reads_as_the_shown_one() {
+ let folder = PathBuf::from("/private/tmp/demo");
+ let shown = (folder.clone(), "shown".to_string(), false);
+ let archived = (folder.clone(), "archived".to_string(), true);
+ for projects in [
+ vec![archived.clone(), shown.clone()],
+ vec![shown.clone(), archived.clone()],
+ ] {
+ assert_eq!(by_folder(projects)[&folder], ("shown".to_string(), false));
+ }
+ }
+
+ #[test]
+ fn imported_projects_join_the_space_without_moving_its_active_project() {
+ let space_id = default_space_id();
+ let (first, second) = (tempdir().unwrap(), tempdir().unwrap());
+ let mut store = test_store();
+ store.create_project_from_path(&space_id, first.path().to_path_buf());
+ let active = store.active_project_id_for_space(&space_id);
+
+ assert!(store.add_project_for_path(&space_id, second.path().to_path_buf()));
+ // Already there: nothing to add.
+ assert!(!store.add_project_for_path(&space_id, first.path().to_path_buf()));
+ assert_eq!(store.active_project_id_for_space(&space_id), active);
+ let imported = store
+ .projects
+ .iter()
+ .find(|project| project.path == second.path())
+ .unwrap();
+ assert_eq!(imported.threads.len(), 1);
+ assert!(imported.threads[0].materialized_workspace_name.is_none());
+
+ // An archived one comes back rather than being added twice.
+ store
+ .projects
+ .iter_mut()
+ .find(|project| project.path == second.path())
+ .unwrap()
+ .archived_at = Some(1);
+ assert!(store.add_project_for_path(&space_id, second.path().to_path_buf()));
+ assert_eq!(
+ store
+ .projects
+ .iter()
+ .filter(|project| project.path == second.path())
+ .count(),
+ 1
+ );
+ }
+
#[test]
fn duplicate_project_path_reuses_existing_thread() {
let space_id = default_space_id();