From 82f3b14fb7d17dbb706d6d5b37cca7a632df0f3f Mon Sep 17 00:00:00 2001 From: ventupx Date: Sat, 21 Nov 2026 15:11:41 +0800 Subject: [PATCH 1/6] fix: recover Git status after missed file notifications Recheck local status while the Git view is visible and focused, and refresh on focus recovery even when the filesystem watcher is live. Cover missed notifications, focus recovery, repeated writes, and replacement saves with regression tests. --- crates/winc-app/src/app/git.rs | 40 +++++++++ crates/winc-app/src/app/lifecycle/events.rs | 2 + .../src/app/snapshot/workspace/watch.rs | 86 +++++++++++++++++++ crates/winc-app/src/app/workspace/files.rs | 14 +-- .../winc-editor/src/workspace/watch/tests.rs | 30 +++++++ 5 files changed, 160 insertions(+), 12 deletions(-) diff --git a/crates/winc-app/src/app/git.rs b/crates/winc-app/src/app/git.rs index 0d942ad6..73434027 100644 --- a/crates/winc-app/src/app/git.rs +++ b/crates/winc-app/src/app/git.rs @@ -26,6 +26,7 @@ use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; use std::sync::mpsc::{Receiver, Sender, channel}; use std::sync::{Arc, Mutex, PoisonError}; +use std::time::{Duration, Instant}; use ropey::Rope; use winc_editor::diff_view::{BlameSource, DiffSide, DiffView}; @@ -41,6 +42,9 @@ use super::{App, Focus, UserEvent}; use crate::app::NoticeKind; use crate::layout::SidebarView; +/// Git 视图可见时补查本地状态的间隔;系统漏发通知时定期重新读取(经验值)。 +const STATUS_RECHECK: Duration = Duration::from_secs(5); + /// 界面线程与各后台任务共用的 [`Git`]。 /// /// 第一个找到 `git` 的任务写入结果,之后的任务直接使用;未找到时不写入,由下一个任务重新查找 @@ -254,6 +258,8 @@ pub(crate) struct GitState { ignored_paths: HashSet, /// 正在运行的刷新;`None` 表示没有在运行。 running: Option, + /// 下一次补查本地状态的时刻;Git 视图不可见时不安排。 + recheck_due: Option, /// 运行期间是否又收到刷新请求;为真时完成后再刷新一次。 again: bool, /// 下一次刷新是否同时读取分支与储藏(由 [`App::git_refresh`] 设置,读取时清除)。 @@ -353,6 +359,7 @@ impl Default for GitState { decorations: HashMap::new(), ignored_paths: HashSet::new(), running: None, + recheck_due: None, again: false, refs_wanted: false, logs_outdated: false, @@ -437,6 +444,7 @@ impl GitState { cancel.cancel(); } self.again = false; + self.recheck_due = None; self.refs_wanted = false; self.root = None; self.tool.forget(); @@ -876,6 +884,37 @@ impl App { self.git_refresh_status(); } + /// Git 视图可见且窗口有焦点时低频补查本地状态,兜底系统未报告的文件变化。 + /// + /// 通知仍负责即时刷新;补查只读取状态,不读取分支、储藏或访问远程仓库。 + pub(in crate::app) fn git_status_tick(&mut self, now: Instant) -> Option { + let visible = self.commit_shown() + || self + .editor + .active() + .is_some_and(|d| d.log.is_some() || d.diff.is_some()); + let local = self + .git + .root + .as_deref() + .is_some_and(|root| !winc_backend::is_remote(root)); + if !self.git_enabled() || !local || !visible || !self.window.focused || self.unseen() { + self.git.recheck_due = None; + return None; + } + let due = *self.git.recheck_due.get_or_insert(now + STATUS_RECHECK); + if now >= due { + self.git.recheck_due = Some(now + STATUS_RECHECK); + if self.git.running.is_none() + && self.git.branch.running.is_none() + && !self.git.commit.staging_active() + { + self.git_refresh_status(); + } + } + self.git.recheck_due + } + /// 只刷新状态,分支与储藏列表保持不变。 /// /// 分支与储藏只随 `.git` 中的内容变化(目录监视报告 `git`,或 winc 自身执行的 Git 操作), @@ -889,6 +928,7 @@ impl App { self.git.again = true; return; } + self.git.recheck_due = Some(Instant::now() + STATUS_RECHECK); // 尚未读取到状态时(刚打开、上次出错)同样没有分支列表,因此一并读取。 let refs = std::mem::take(&mut self.git.refs_wanted) || self.git.status.is_none(); let cancel = Cancel::default(); diff --git a/crates/winc-app/src/app/lifecycle/events.rs b/crates/winc-app/src/app/lifecycle/events.rs index c2031f9a..468d0b36 100644 --- a/crates/winc-app/src/app/lifecycle/events.rs +++ b/crates/winc-app/src/app/lifecycle/events.rs @@ -776,6 +776,8 @@ impl App { earliest(&mut wake, self.changes_tick(now)); + earliest(&mut wake, self.git_status_tick(now)); + earliest(&mut wake, self.sync_outline(now)); earliest(&mut wake, self.blame_tick(now)); diff --git a/crates/winc-app/src/app/snapshot/workspace/watch.rs b/crates/winc-app/src/app/snapshot/workspace/watch.rs index a23ffa8b..4824c8cc 100644 --- a/crates/winc-app/src/app/snapshot/workspace/watch.rs +++ b/crates/winc-app/src/app/snapshot/workspace/watch.rs @@ -5,6 +5,7 @@ use std::time::{Duration, SystemTime}; use winc_editor::Changes; use crate::app::workspace::watch::DiskBack; +use crate::keymap::Action; use super::*; @@ -477,3 +478,88 @@ fn large_files_save_in_the_background_and_skip_their_own_write() { let _ = std::fs::remove_dir_all(&dir); } + +/// 只初始化仓库,不依赖 shell 脚本或提交身份,Windows 上同样运行 Git 监视的回归测试。 +fn git_watch_app(name: &str) -> Option<(App, PathBuf)> { + let dir = sample_folder(name); + let initialized = std::process::Command::new("git") + .args(["init", "-q"]) + .arg(&dir) + .output() + .is_ok_and(|output| output.status.success()); + if !initialized { + assert!(std::env::var_os("CI").is_none(), "CI 上必须能运行 git"); + eprintln!("跳过:无法初始化 Git 测试仓库"); + let _ = std::fs::remove_dir_all(&dir); + return None; + } + let mut app = app_with(&dir, false); + app.settings_toggle(Setting::GitModule); + assert!(app.git.status.is_some(), "{:?}", app.git.problem); + let root = app.editor.root().unwrap().to_path_buf(); + Some((app, root)) +} + +/// 没收到任何目录通知时,当前 Git 视图仍会在补查后显示磁盘上的新文件。 +#[test] +fn git_status_rechecks_recover_missed_notifications() { + let Some((mut app, root)) = git_watch_app("git-missed-notification") else { + return; + }; + app.run_action(Action::ShowCommit); + app.window.focused = true; + let now = std::time::Instant::now(); + let due = app.git_status_tick(now).unwrap(); + let generation = app.git.generation; + let path = root.join("missed.txt"); + std::fs::write(&path, "written by an external tool\n").unwrap(); + app.git_status_tick(now); + assert_eq!(app.git.generation, generation); + app.git_status_tick(due); + assert!(app.git.generation > generation); + assert!( + app.git + .status + .as_ref() + .unwrap() + .entries + .iter() + .any(|e| e.path == path) + ); + + // 隐藏 Git 视图、失去焦点或窗口不可见时不持续启动状态查询。 + app.set_sidebar_view(SidebarView::Files); + assert!(app.git_status_tick(now).is_none()); + app.set_sidebar_view(SidebarView::Commit); + app.window.focused = false; + assert!(app.git_status_tick(now).is_none()); + app.window.focused = true; + app.window.occluded = true; + assert!(app.git_status_tick(now).is_none()); + let _ = std::fs::remove_dir_all(&root); +} + +/// 即使本地系统监视正常启动,窗口回焦也补查一次,避免把漏通知的旧状态一直当作最新状态。 +#[test] +fn focus_rechecks_git_with_a_live_local_watcher() { + let Some((mut app, root)) = git_watch_app("git-focus-recheck") else { + return; + }; + let watcher = winc_editor::Watcher::start(&root, || {}).unwrap(); + assert!(watcher.reliable()); + app.disk.watcher = Some(watcher); + let path = root.join("missed.txt"); + std::fs::write(&path, "written while unfocused\n").unwrap(); + app.check_disk(); + assert!( + app.git + .status + .as_ref() + .unwrap() + .entries + .iter() + .any(|e| e.path == path) + ); + drop(app); + let _ = std::fs::remove_dir_all(&root); +} diff --git a/crates/winc-app/src/app/workspace/files.rs b/crates/winc-app/src/app/workspace/files.rs index 8e5a9b8e..543d5b28 100644 --- a/crates/winc-app/src/app/workspace/files.rs +++ b/crates/winc-app/src/app/workspace/files.rs @@ -1201,25 +1201,15 @@ impl App { pub(in crate::app) fn check_disk(&mut self) { self.check_remote(); self.sync_documents(|_| true); - // 在终端里提交、切换分支时 `.git` 可能不在监视范围内:打开的是仓库中的子目录,或者没有 - // 启动监视。工作树、子模块的 `.git` 是文件,真正的目录在其他位置。仓库根位于已监视的目录 - // 中、`.git` 是目录时,它的变化已由监视报告,不必每次窗口重新获得焦点都启动 git。 - // `.git` 的位置取自上一次读到的状态,不访问文件系统:远端的仓库不能在界面线程上查询。 + // 系统监视也可能漏发通知(如 Windows 通知缓冲区溢出),回到窗口时补查 Git 状态。 self.git_discover(); self.restart_exited_watcher(); + self.git_refresh(); let live = self .disk .watcher .as_ref() .is_some_and(winc_editor::Watcher::reliable); - let watched = (self.disk.watcher.as_ref().filter(|_| live)).zip(self.git.root.as_deref()); - let git_dir = (self.git.status.as_ref()).and_then(|status| status.git_dir.as_deref()); - if !watched.is_some_and(|(w, root)| { - root.starts_with(w.root()) && git_dir == Some(root.join(".git").as_path()) - }) { - self.git_refresh(); - } - if !live { // 发行版无法访问时目录都读不到,保留现有的文件树。 let reachable = self.editor.root().is_none_or(winc_editor::wsl::reachable); diff --git a/crates/winc-editor/src/workspace/watch/tests.rs b/crates/winc-editor/src/workspace/watch/tests.rs index ca577c19..e05361dc 100644 --- a/crates/winc-editor/src/workspace/watch/tests.rs +++ b/crates/winc-editor/src/workspace/watch/tests.rs @@ -183,6 +183,36 @@ fn changes_inside_the_folder_are_reported() { let _ = fs::remove_dir_all(&dir); } +/// 外部工具连续原地写入、临时文件替换后,监视仍能报告同一目标文件的后续变化。 +#[test] +fn repeated_writes_and_file_replacements_are_reported() { + let dir = scratch("repeated-replacements"); + let path = dir.join("source.rs"); + fs::write(&path, "initial\n").unwrap(); + let (sender, woken) = mpsc::channel(); + let watcher = Watcher::start(&dir, move || { + let _ = sender.send(()); + }) + .unwrap(); + for round in 0..8 { + // 清空上一轮的晚到事件,确认每轮保存都会重新唤醒。 + while woken.recv_timeout(Duration::from_millis(100)).is_ok() { + watcher.take(); + } + let text = format!("round {round}\n"); + if round % 2 == 0 { + fs::write(&path, text).unwrap(); + } else { + let temporary = dir.join("source.tmp"); + fs::write(&temporary, text).unwrap(); + winc_config::files::replace_file(&temporary, &path).unwrap(); + } + wait_for(&watcher, &woken, &[&path]); + } + drop(watcher); + let _ = fs::remove_dir_all(&dir); +} + #[test] fn too_many_changes_become_a_rescan() { let dir = scratch("overflow"); From d7ea7d425d4faa9515b7c2d7e5032399d0b136c8 Mon Sep 17 00:00:00 2001 From: ventupx Date: Sat, 21 Nov 2026 15:11:41 +0800 Subject: [PATCH 2/6] fix: contain editor toolbars and overlays within their panes Clip editor content and hit targets when a maximized terminal hides the editor or a narrow pane cannot fit its fixed-width controls. Keep preview shadows, selection controls, notices, and conflict cards in their areas. Add pixel and hit-target regressions for zero-sized and narrow panes, light and dark themes, and fractional display scales. --- crates/winc-app/src/app/snapshot/tiny.rs | 224 ++++++++++++++++++ crates/winc-app/src/view.rs | 74 ++++-- crates/winc-app/src/view/editor.rs | 11 + crates/winc-app/src/view/editor/picture.rs | 7 + .../src/view/preview/markdown/toolbar.rs | 6 +- crates/winc-app/src/view/tests.rs | 18 ++ 6 files changed, 313 insertions(+), 27 deletions(-) diff --git a/crates/winc-app/src/app/snapshot/tiny.rs b/crates/winc-app/src/app/snapshot/tiny.rs index 48981f28..c8be492e 100644 --- a/crates/winc-app/src/app/snapshot/tiny.rs +++ b/crates/winc-app/src/app/snapshot/tiny.rs @@ -14,6 +14,230 @@ fn resize(app: &mut App, size: (f32, f32)) { app.clamp_scroll(); } +/// 终端在右边最大化时编辑区宽度为零,日志按钮不能画到侧栏的 Git 工具栏上。 +#[test] +fn log_stays_inside_the_editor() { + for dark in [false, true] { + for right in [false, true] { + let mut app = blank_app(dark); + app.panels.sidebar.view = SidebarView::Commit; + app.config.terminal_enabled = Some(true); + app.config.terminal_right = Some(right); + app.terminal.open = true; + app.terminal.maximized = true; + paint(&mut app); + let toolbar = app.commit_parts().header; + let pixels = |app: &App| { + let image = app.frame.renderer.as_ref().unwrap().image().unwrap(); + let width = image.width as usize; + let mut pixels = Vec::new(); + for y in (toolbar.y * SCALE) as usize..(toolbar.bottom() * SCALE) as usize { + let left = y * width + (toolbar.x * SCALE) as usize; + let right = y * width + (toolbar.right() * SCALE) as usize; + pixels.extend_from_slice(&image.pixels[left..right]); + } + pixels + }; + let before = pixels(&app); + app.editor.show_log("Git log"); + paint(&mut app); + assert!(app.layout.editor.w == 0.0 || app.layout.editor.h == 0.0); + assert!(pixels(&app) == before, "dark={dark}, right={right}"); + } + } +} + +/// 单独绘制一个区域,检查它不会改动画布上区域以外的像素。 +fn assert_contained(app: &mut App, area: Rect, scale: f32, draw: fn(&mut App, &mut Frame<'_>)) { + let mut renderer = + Renderer::offscreen(SIZE.0, SIZE.1, scale, Color::hex(0x7f2359), None, None).unwrap(); + renderer.draw(|_| {}); + let background = renderer.image().unwrap().pixels[0]; + app.hits.clear(); + renderer.draw(|frame| draw(app, frame)); + let image = renderer.image().unwrap(); + for (i, &pixel) in image.pixels.iter().enumerate() { + let (x, y) = (i % image.width as usize, i / image.width as usize); + let inside = area.w > 0.0 + && area.h > 0.0 + && (x as f32) >= (area.x * scale).floor() + && (x as f32) < (area.right() * scale).ceil() + && (y as f32) >= (area.y * scale).floor() + && (y as f32) < (area.bottom() * scale).ceil(); + assert!( + inside || pixel == background, + "outside {area:?} at ({x}, {y}), scale={scale}" + ); + } +} + +/// 差异和日志的固定宽度按钮,以及空编辑区的提示,都必须留在编辑区内。 +#[test] +fn editor_surfaces_stay_inside_the_editor() { + use winc_editor::diff_view::{DiffSide, DiffView}; + + for dark in [false, true] { + for scene in ["welcome", "diff", "log"] { + let mut app = blank_app(dark); + match scene { + "diff" => { + let lang = winc_syntax::detect("sample.rs"); + app.editor.show_diff( + "sample.rs", + DiffView::new( + DiffSide::new("before", "old\n", None, lang), + DiffSide::new("after", "new\n", None, lang), + ), + ); + } + "log" => { + app.editor.show_log("Git log"); + } + _ => {} + } + for scale in [1.25, 2.0] { + for (w, h) in [(0.0, 120.0), (96.0, 0.0), (28.0, 24.0), (96.0, 120.0)] { + app.layout.editor = Rect::new(300.0, 80.0, w, h); + assert_contained( + &mut app, + Rect::new(300.0, 80.0, w, h), + scale, + view::tests::draw_editor, + ); + for rect in app + .hits + .diff + .iter() + .map(|(r, _)| r) + .chain(app.hits.log.iter().map(|(r, _)| r)) + { + assert_eq!(*rect, rect.intersect(app.layout.editor)); + } + } + } + } + } +} + +/// 预览工具栏的阴影和边框也不能跨过预览区域,或在区域隐藏后留下像素。 +#[test] +fn floating_bars_stay_inside_their_preview() { + for dark in [false, true] { + let mut app = blank_app(dark); + for (w, h) in [(0.0, 120.0), (96.0, 0.0), (28.0, 24.0), (96.0, 120.0)] { + app.layout.editor = Rect::new(300.0, 80.0, w, h); + assert_contained( + &mut app, + Rect::new(300.0, 80.0, w, h), + 1.25, + view::tests::draw_floating_bar, + ); + } + } +} + +/// Markdown 选区工具栏的卡片与阴影留在预览内。 +#[test] +fn markdown_selection_tools_stay_inside_the_preview() { + use winc_editor::PreviewMode; + + let dir = sample_folder("tiny-markdown-toolbar"); + let path = dir.join("README.md"); + std::fs::write(&path, "Intro\n\nselected words\n").unwrap(); + for dark in [false, true] { + for width in [420.0, 820.0] { + let mut app = app_with(&path, dark); + app.set_preview_mode(PreviewMode::Preview); + resize(&mut app, (width, 320.0)); + for _ in 0..4 { + app.wait_for_markdown(); + paint(&mut app); + } + app.editor.active_mut().unwrap().selection = winc_core::Selection::new(7, 15); + app.start_live_editing(); + app.offer_selection_toolbar(); + paint(&mut app); + assert!(app.hits.selection_card.is_some()); + let area = app.layout.editor; + assert_contained(&mut app, area, 1.25, view::tests::draw_editor); + for (rect, _) in &app.hits.selection_tools { + assert_eq!(*rect, rect.intersect(area)); + } + } + } + let _ = std::fs::remove_dir_all(&dir); +} + +/// 合并、磁盘冲突和提示条的固定宽度内容不能跨到侧栏或相邻窗格。 +#[test] +fn notices_and_conflict_cards_stay_inside_their_area() { + let dir = sample_folder("tiny-conflict-cards"); + let path = dir.join("short.rs"); + for dark in [false, true] { + let mut app = app_with(&path, dark); + app.config.git_enabled = Some(true); + let index = app.editor.active.unwrap(); + let doc = &mut app.editor.documents[index]; + assert_eq!( + doc.restore_unsaved( + "<<<<<<< ours\nours\n=======\ntheirs\n>>>>>>> theirs\n", + doc.disk_mtime(), + winc_core::Selection::default(), + true, + ), + Some(true) + ); + assert_eq!(app.conflicts(index).len(), 1); + app.notice.text = Some("A long message with an action".into()); + app.notice.action = Some(NoticeAction::GitOutput); + for (w, h) in [(0.0, 120.0), (96.0, 0.0), (28.0, 24.0), (96.0, 240.0)] { + app.layout.editor = Rect::new(300.0, 80.0, w, h); + let area = app.overlay_area(); + assert_contained(&mut app, area, 1.25, view::tests::draw_notices); + assert!( + app.hits.conflict_card.is_some() + && app.hits.merge_card.is_some() + && app.hits.notice_card.is_some() + ); + let (card, buttons) = app.hits.conflict_card.as_ref().unwrap(); + for rect in [ + *card, + app.hits.merge_card.unwrap(), + app.hits.notice_card.unwrap(), + app.hits.notice_button.unwrap(), + ] + .into_iter() + .chain(buttons.iter().map(|(r, _)| *r)) + .chain(app.hits.merge.iter().map(|(r, _)| *r)) + { + assert_eq!(rect, rect.intersect(area)); + } + } + } + let _ = std::fs::remove_dir_all(&dir); +} + +/// 窗口缩小后,窗格工具栏不能盖到邻近窗格和侧栏。 +#[test] +fn narrow_panes_keep_their_contents_inside() { + for dark in [false, true] { + let mut app = blank_app(dark); + app.editor.show_log("Git log"); + app.run_action(Action::SplitRight); + for size in [(480.0, 300.0), (340.0, 200.0)] { + resize(&mut app, size); + let area = app + .panes + .rects + .iter() + .find(|r| r.id == app.editor.panes.focused) + .unwrap() + .whole; + assert_contained(&mut app, area, 1.25, view::tests::draw_pane); + } + } +} + /// 在当前界面上依次绘制、移动鼠标、滚动、按下并松开左键。 fn exercise(app: &mut App, size: (f32, f32)) { paint(app); diff --git a/crates/winc-app/src/view.rs b/crates/winc-app/src/view.rs index 4c83af36..266c09b5 100644 --- a/crates/winc-app/src/view.rs +++ b/crates/winc-app/src/view.rs @@ -201,25 +201,7 @@ pub fn draw(app: &mut App, frame: &mut Frame<'_>) { editor::hint::draw_name_hint(app, frame); - app.hits.conflict_card = draw_conflict(app, frame); - // 合并冲突的卡片排在磁盘冲突卡片下面。 - let top = match &app.hits.conflict_card { - Some((card, _)) => card.bottom(), - None => app.overlay_top(), - } + 8.0; - let mut hits = std::mem::take(&mut app.hits.merge); - app.hits.merge_card = git::merge::draw_merge_card(app, frame, top, &mut hits); - app.hits.merge = hits; - (app.hits.notice_card, app.hits.notice_button) = match app.notice.text.as_deref() { - Some(message) => { - let (card, button) = draw_live_notice(app, frame, message); - (Some(card), button) - } - None => (None, None), - }; - if let Some(ghost) = &app.notice.leaving { - draw_notice_ghost(app, frame, ghost); - } + draw_notices(app, frame); suggest::draw_suggest(app, frame); draw_tree_drag(app, frame); @@ -257,6 +239,46 @@ pub fn draw(app: &mut App, frame: &mut Frame<'_>) { app.in_hovered_pane(|app| tooltip::draw_tooltip(app, frame)); } +/// 提示和冲突卡片留在所属区域内,终端最大化时随区域移到终端内容上。 +fn draw_notices(app: &mut App, frame: &mut Frame<'_>) { + let area = app.overlay_area(); + let merge_start = app.hits.merge.len(); + frame.within(area, |frame| { + app.hits.conflict_card = draw_conflict(app, frame); + // 合并冲突的卡片排在磁盘冲突卡片下面。 + let top = match &app.hits.conflict_card { + Some((card, _)) => card.bottom(), + None => app.overlay_top(), + } + 8.0; + let mut hits = std::mem::take(&mut app.hits.merge); + app.hits.merge_card = git::merge::draw_merge_card(app, frame, top, &mut hits); + app.hits.merge = hits; + (app.hits.notice_card, app.hits.notice_button) = match app.notice.text.as_deref() { + Some(message) => { + let (card, button) = draw_live_notice(app, frame, message); + (Some(card), button) + } + None => (None, None), + }; + if let Some(ghost) = &app.notice.leaving { + draw_notice_ghost(app, frame, ghost); + } + }); + // 被裁掉的按钮和卡片不再遮挡侧栏或相邻窗格;冲突标记行已有的按钮保持各自范围。 + for (rect, _) in &mut app.hits.merge[merge_start..] { + *rect = rect.intersect(area); + } + if let Some((card, buttons)) = &mut app.hits.conflict_card { + *card = card.intersect(area); + for (rect, _) in buttons { + *rect = rect.intersect(area); + } + } + app.hits.merge_card = app.hits.merge_card.map(|r| r.intersect(area)); + app.hits.notice_card = app.hits.notice_card.map(|r| r.intersect(area)); + app.hits.notice_button = app.hits.notice_button.map(|r| r.intersect(area)); +} + /// 绘制已打开的窗口内菜单和提示框;提示框覆盖在菜单之上。 fn draw_modal(app: &mut App, frame: &mut Frame<'_>) { popup_menu::draw(app, frame); @@ -817,12 +839,14 @@ fn draw_card_frame(frame: &mut Frame<'_>, p: &Palette, rect: Rect, radius: f32) /// 绘制浮在预览内容上的工具栏或卡片 `rect`(含细边框):阴影、细边框和底色,裁剪到 `clip`; /// 细边框画在卡片底色上,不透出下方的内容。 fn draw_floating_bar(frame: &mut Frame<'_>, p: &Palette, rect: Rect, clip: Rect) { - let covered = frame.covered(rect, RADIUS_POPUP); - frame.shadow(rect, RADIUS_POPUP, 12.0, 4.0, p.shadow, Some(covered)); - frame.rect_clipped(rect, p.popup_bg, RADIUS_POPUP, clip); - frame.rect_clipped(rect, p.popup_border, RADIUS_POPUP, clip); - let inner = rect.inset(1.0, 1.0); - frame.rect_clipped(inner, p.popup_bg, RADIUS_POPUP - 1.0, clip); + frame.within(clip, |frame| { + let covered = frame.covered(rect, RADIUS_POPUP); + frame.shadow(rect, RADIUS_POPUP, 12.0, 4.0, p.shadow, Some(covered)); + frame.rect_clipped(rect, p.popup_bg, RADIUS_POPUP, clip); + frame.rect_clipped(rect, p.popup_border, RADIUS_POPUP, clip); + let inner = rect.inset(1.0, 1.0); + frame.rect_clipped(inner, p.popup_bg, RADIUS_POPUP - 1.0, clip); + }); } /// 卡片阴影超出卡片矩形的范围(逻辑像素)。 diff --git a/crates/winc-app/src/view/editor.rs b/crates/winc-app/src/view/editor.rs index 5363f165..9aa7b640 100644 --- a/crates/winc-app/src/view/editor.rs +++ b/crates/winc-app/src/view/editor.rs @@ -60,6 +60,17 @@ const BRACE_SCAN_LIMIT: usize = 20_000; /// 当前标签是图片、SVG、Markdown 的预览或无法显示的文件时,改为绘制相应的预览或说明; /// 没有标签时绘制开始页或欢迎页。 pub(super) fn draw_editor(app: &mut App, frame: &mut Frame<'_>) { + // 固定宽度的工具栏和提示也必须留在编辑区,包含终端最大化后的零宽、零高区域。 + frame.within(app.layout.editor, |frame| draw_content(app, frame)); + for (rect, _) in &mut app.hits.diff { + *rect = rect.intersect(app.layout.editor); + } + for (rect, _) in &mut app.hits.log { + *rect = rect.intersect(app.layout.editor); + } +} + +fn draw_content(app: &mut App, frame: &mut Frame<'_>) { // Markdown、PDF 预览绘制时重新填充;预览不显示时若仍保留,滚轮和点击事件会被预览接收。 app.preview.markdown.area = Rect::default(); app.preview.pdf.area = Rect::default(); diff --git a/crates/winc-app/src/view/editor/picture.rs b/crates/winc-app/src/view/editor/picture.rs index da1d415b..6fb6fe04 100644 --- a/crates/winc-app/src/view/editor/picture.rs +++ b/crates/winc-app/src/view/editor/picture.rs @@ -24,6 +24,13 @@ const BASE_EDGE: u32 = 1024; /// /// 写到一半解析不了时仍然绘制上一张图,底下一行写出错在哪里;一张都还没绘制出来时只写原因。 pub(in crate::view) fn draw_split(app: &mut App, frame: &mut Frame<'_>) { + let area = app.layout.split; + // 包括预览左侧的一像素分隔线;预览中的浮动工具栏不能盖住源代码。 + let clip = Rect::new(area.x - 1.0, area.y, area.w + 1.0, area.h); + frame.within(clip, |frame| draw_split_content(app, frame)); +} + +fn draw_split_content(app: &mut App, frame: &mut Frame<'_>) { let area = app.layout.split; let Some(doc) = app.editor.active().filter(|_| area.w > 0.0) else { return; diff --git a/crates/winc-app/src/view/preview/markdown/toolbar.rs b/crates/winc-app/src/view/preview/markdown/toolbar.rs index 93066571..6ac521bc 100644 --- a/crates/winc-app/src/view/preview/markdown/toolbar.rs +++ b/crates/winc-app/src/view/preview/markdown/toolbar.rs @@ -82,8 +82,10 @@ pub(in crate::view) fn draw_selection_toolbar(app: &mut App, frame: &mut Frame<' }; let center = (button.x + BUTTON / 2.0, button.y + BUTTON / 2.0); icons::writing(frame, center, tool.glyph(), color, card); - app.hits.selection_tools.push((button, tool)); + app.hits + .selection_tools + .push((button.intersect(area), tool)); x += BUTTON + GAP; } - app.hits.selection_card = Some(card); + app.hits.selection_card = Some(card.intersect(area)); } diff --git a/crates/winc-app/src/view/tests.rs b/crates/winc-app/src/view/tests.rs index 9e9c193e..f9c1bd7f 100644 --- a/crates/winc-app/src/view/tests.rs +++ b/crates/winc-app/src/view/tests.rs @@ -9,6 +9,24 @@ pub(crate) fn tooltip(app: &App) -> Option<(Rect, String)> { workspace::panel::tooltip(app) } +pub(crate) fn draw_editor(app: &mut App, frame: &mut Frame<'_>) { + super::draw_editor(app, frame); +} + +pub(crate) fn draw_pane(app: &mut App, frame: &mut Frame<'_>) { + super::draw_pane(app, frame, true); +} + +pub(crate) fn draw_notices(app: &mut App, frame: &mut Frame<'_>) { + super::draw_notices(app, frame); +} + +pub(crate) fn draw_floating_bar(app: &mut App, frame: &mut Frame<'_>) { + let area = app.layout.editor; + let bar = Rect::new(area.right() - 80.0, area.y + 4.0, 160.0, 28.0); + super::draw_floating_bar(frame, app.palette, bar, area); +} + pub(crate) use super::settings::draw_cached as settings_draw_cached; pub(crate) use crate::app::workspace::tab_names::distinct_folder; From 448cf8bcdea0705615a5cbcd9921e9bb73a32f38 Mon Sep 17 00:00:00 2001 From: ventupx Date: Sat, 21 Nov 2026 15:11:42 +0800 Subject: [PATCH 3/6] fix: match Git filename fades to each repository row Composite filename fades over the current repository card and row state instead of the plain sidebar background. Reuse the same name layout and fade for other repositories, including hovered rows. Compare rendered rows across themes, display scales, sidebar widths, and checkbox or staging modes. --- .../src/app/snapshot/git/commit/others.rs | 170 ++++++++++++++++++ crates/winc-app/src/view/git/commit/others.rs | 24 ++- crates/winc-app/src/view/git/commit/row.rs | 10 +- 3 files changed, 198 insertions(+), 6 deletions(-) diff --git a/crates/winc-app/src/app/snapshot/git/commit/others.rs b/crates/winc-app/src/app/snapshot/git/commit/others.rs index 200a6802..ba4c77d6 100644 --- a/crates/winc-app/src/app/snapshot/git/commit/others.rs +++ b/crates/winc-app/src/app/snapshot/git/commit/others.rs @@ -25,6 +25,176 @@ fn two_repositories(name: &str, dark: bool) -> Option<(App, PathBuf, PathBuf)> { Some((app, dir.join("a"), dir.join("b"))) } +/// 长文件名的渐隐必须使用当前仓库卡片和行状态叠加后的底色,不能露出普通侧栏底色。 +#[test] +fn long_names_fade_into_the_current_repository_background() { + for dark in [false, true] { + let Some((mut app, root, _)) = two_repositories(&format!("git-name-fade-{dark}"), dark) + else { + return; + }; + let path = root.join("src/a-very-long-file-name-that-cannot-fit-in-the-sidebar.rs"); + std::fs::write(&path, "new\n").unwrap(); + app.git_refresh(); + app.poll_git(); + app.run_action(Action::ShowCommit); + app.git.commit.shift = None; + let index = app + .git + .status + .as_ref() + .unwrap() + .entries + .iter() + .position(|e| e.path == path) + .unwrap(); + for flat in [false, true] { + app.git.commit.set_flat(flat); + for selected in [false, true] { + app.git.commit.selected = selected.then(|| path.clone()); + for focus in [Focus::Tree, Focus::CommitList] { + app.focus = focus; + paint(&mut app); + let row = app + .hits + .commit + .iter() + .find(|(_, h)| *h == CommitTarget::File(index)) + .unwrap() + .0; + let image = app.frame.renderer.as_ref().unwrap().image().unwrap(); + let pixel = |x: f32| { + let y = ((row.y + 2.0) * SCALE) as usize; + image.pixels[y * image.width as usize + (x * SCALE) as usize] + }; + let base = pixel(row.x + 20.0); + // 文字和勾选框上方的空白也经过渐隐;整段都应与行底色一致。 + for x in (row.right() as usize - 80)..(row.right() as usize - 28) { + let actual = pixel(x as f32); + // 半透明背景与渐隐分别混合时允许每通道一档取整误差。 + let same = (0..4).all(|c| { + ((actual >> (c * 8)) & 255).abs_diff((base >> (c * 8)) & 255) <= 1 + }); + assert!( + same, + "dark={dark}, flat={flat}, selected={selected}, focus={focus:?}, x={x}" + ); + } + } + } + } + let _ = std::fs::remove_dir_all(root.parent().unwrap()); + } +} + +/// 同名长文件在当前和其他仓库中使用相同的截断渐隐,状态字母前保留相同间距。 +#[test] +fn other_repository_names_fade_like_current_names() { + let name = "2026-07-31-spell-calibration-with-a-very-long-file-name.rs"; + for dark in [false, true] { + let Some((mut app, a, b)) = two_repositories(&format!("git-other-name-fade-{dark}"), dark) + else { + return; + }; + for root in [&a, &b] { + std::fs::write(root.join("src").join(name), "new\n").unwrap(); + } + app.git_refresh(); + app.git_read_summaries(); + app.poll_git(); + app.run_action(Action::ShowCommit); + app.git.commit.shift = None; + app.git.commit.set_flat(true); + app.state.commit_all_repositories = Some(true); + // 去掉当前仓库卡片的色差,直接对比两行的文字和渐隐像素。 + app.palette = Box::leak(Box::new(Palette { + accent: app.palette.sidebar_bg, + ..*app.palette + })); + let index = app + .git + .status + .as_ref() + .unwrap() + .entries + .iter() + .position(|e| e.path.ends_with(name)) + .unwrap(); + let other_index = app + .other_status(1, |_, s| { + s.entries.iter().position(|e| e.path.ends_with(name)) + }) + .flatten() + .unwrap(); + for scale in [1.25, 2.0] { + app.frame.renderer = Some( + Renderer::offscreen(SIZE.0, SIZE.1, scale, app.palette.frame_bg, None, None) + .unwrap(), + ); + app.measure_fonts(); + for staging in [false, true] { + app.git.commit.set_staging(staging); + for width in [230.0, 310.0] { + app.panels.sidebar.width = width; + paint(&mut app); + app.git.commit.names.finish(); + paint(&mut app); + let hit = |target| { + app.hits + .commit + .iter() + .find(|(_, t)| *t == target) + .unwrap() + .0 + }; + let current = hit(CommitTarget::File(index)); + let other = hit(CommitTarget::OtherFile(1, other_index)); + assert_eq!((current.x, current.w), (other.x, other.w)); + let image = app.frame.renderer.as_ref().unwrap().image().unwrap(); + let pixel = |row: Rect, x: usize, y: usize| { + let y = ((row.y + y as f32) * scale) as usize; + image.pixels[y * image.width as usize + (x as f32 * scale) as usize] + }; + for y in 2..COMMIT_ROW as usize - 2 { + for x in (current.right() as usize - 72)..(current.right() as usize - 4) { + let (a, b) = (pixel(current, x, y), pixel(other, x, y)); + assert!( + (0..4) + .all(|c| ((a >> (8 * c)) & 255).abs_diff((b >> (8 * c)) & 255) + <= 1), + "dark={dark}, scale={scale}, staging={staging}, width={width}, x={x}, y={y}: {a:08x} != {b:08x}" + ); + } + } + app.on_mouse_move(other.right() - 80.0, other.y + COMMIT_ROW / 2.0); + paint(&mut app); + assert_eq!( + app.pointer.hover, + Hover::Commit(CommitTarget::OtherFile(1, other_index)) + ); + let image = app.frame.renderer.as_ref().unwrap().image().unwrap(); + let pixel = |x: f32| { + let y = ((other.y + 2.0) * scale) as usize; + image.pixels[y * image.width as usize + (x * scale) as usize] + }; + let base = pixel(other.x + 20.0); + for x in (other.right() as usize - 72)..(other.right() as usize - 28) { + let actual = pixel(x as f32); + assert!( + (0..4).all(|c| ((actual >> (8 * c)) & 255) + .abs_diff((base >> (8 * c)) & 255) + <= 1), + "hover: dark={dark}, scale={scale}, staging={staging}, width={width}, x={x}" + ); + } + app.on_mouse_move(app.layout.editor.x + 40.0, app.layout.editor.y + 40.0); + } + } + } + let _ = std::fs::remove_dir_all(a.parent().unwrap()); + } +} + #[test] fn other_repositories_are_listed_after_the_current_one_and_a_click_switches() { let Some((mut app, a, b)) = two_repositories("git-all-repositories", false) else { diff --git a/crates/winc-app/src/view/git/commit/others.rs b/crates/winc-app/src/view/git/commit/others.rs index bdbc37fd..6f6f56d2 100644 --- a/crates/winc-app/src/view/git/commit/others.rs +++ b/crates/winc-app/src/view/git/commit/others.rs @@ -559,9 +559,27 @@ fn draw_other_file( } let text_end = button.map_or(letter_x - 8.0, |x| x - 4.0); let clip = Rect::new(list.x, band.y, text_end - list.x, COMMIT_ROW).intersect(list); - let end = ui_text(frame, app, text_x, band, &name, file_color(change, p), clip); - if !dir.is_empty() { - ui_text_small(frame, app, end + 8.0, band, &dir, p.text_dim, clip); + let room = (text_end - text_x).max(0.0); + let dir = (!dir.is_empty()).then_some(dir.as_str()); + let parts = file_parts(app, frame, (&name, dir), Some(room)); + let end = draw_file_parts( + app, + frame, + (text_x, band), + &parts, + (file_color(change, p), |_| 1.0), + clip, + ); + // 和当前仓库使用相同的名称排版与截断渐隐,底色随这一行的悬停状态变化。 + if end > text_end + 0.5 { + let solid = if hover == Hover::Commit(target) || button.is_some() { + crate::view::workspace::panel::over(p.sidebar_bg, p.hover) + } else { + p.sidebar_bg + }; + let reach = NAME_FADE.min(room); + let edge = Rect::new(text_end - reach, band.y, reach, COMMIT_ROW); + frame.within(clip, |frame| fade(frame, edge, solid, false)); } hits.push((band.intersect(list), target)); } diff --git a/crates/winc-app/src/view/git/commit/row.rs b/crates/winc-app/src/view/git/commit/row.rs index 4139c713..38fb6c0c 100644 --- a/crates/winc-app/src/view/git/commit/row.rs +++ b/crates/winc-app/src/view/git/commit/row.rs @@ -501,9 +501,13 @@ fn draw_file_row( let content = parts_width(app, frame, &parts, false); let reach = NAME_FADE * stage(view.progress, FADE_FROM, 1.0); if !wanted && text_x + content > name_end + 0.5 && reach > 0.0 { - let solid = shade_color.map_or(p.sidebar_bg, |c| { - crate::view::workspace::panel::over(p.sidebar_bg, c) - }); + let mut solid = p.sidebar_bg; + if app.commit_shows_others() { + solid = crate::view::workspace::panel::over(solid, others::current_fill(app)); + } + if let Some(color) = shade_color { + solid = crate::view::workspace::panel::over(solid, color); + } let edge = Rect::new(name_end - reach, y, reach, COMMIT_ROW); frame.within(name_clip, |frame| fade(frame, edge, solid, false)); } From 91f0eb9a9f8f64bb7090618dc8914981e4e7b270 Mon Sep 17 00:00:00 2001 From: ventupx Date: Sat, 21 Nov 2026 15:28:57 +0800 Subject: [PATCH 4/6] fix: apply editor containment at the pane drawing entry Keep the same clipping and hit bounds at the pane drawing entry, leaving the editor content function unchanged. This also preserves the source fixture used by the existing smooth sticky-scroll regression. --- crates/winc-app/src/view.rs | 12 +++++++++++- crates/winc-app/src/view/editor.rs | 11 ----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/winc-app/src/view.rs b/crates/winc-app/src/view.rs index 266c09b5..9defe70b 100644 --- a/crates/winc-app/src/view.rs +++ b/crates/winc-app/src/view.rs @@ -44,7 +44,6 @@ mod terminal; mod tooltip; mod workspace; -use editor::draw_editor; pub(crate) use editor::{LineTokens, MinimapRows, RulerCache}; use fields::*; use overlays::{ @@ -71,6 +70,17 @@ pub(crate) fn base(app: &App) -> [(Rect, Color); 3] { ] } +/// 编辑区的内容和交互区域都留在窗格内,包括终端最大化后的零宽、零高区域。 +fn draw_editor(app: &mut App, frame: &mut Frame<'_>) { + frame.within(app.layout.editor, |frame| editor::draw_editor(app, frame)); + for (rect, _) in &mut app.hits.diff { + *rect = rect.intersect(app.layout.editor); + } + for (rect, _) in &mut app.hits.log { + *rect = rect.intersect(app.layout.editor); + } +} + /// 绘制一个窗格:标签栏和编辑区,以及分栏预览、合并的两侧等随标签变化的部分。`front` 为假 /// 时是前台以外的窗格:合并的冲突只由前台窗格折叠、展开。 fn draw_pane(app: &mut App, frame: &mut Frame<'_>, front: bool) { diff --git a/crates/winc-app/src/view/editor.rs b/crates/winc-app/src/view/editor.rs index 9aa7b640..5363f165 100644 --- a/crates/winc-app/src/view/editor.rs +++ b/crates/winc-app/src/view/editor.rs @@ -60,17 +60,6 @@ const BRACE_SCAN_LIMIT: usize = 20_000; /// 当前标签是图片、SVG、Markdown 的预览或无法显示的文件时,改为绘制相应的预览或说明; /// 没有标签时绘制开始页或欢迎页。 pub(super) fn draw_editor(app: &mut App, frame: &mut Frame<'_>) { - // 固定宽度的工具栏和提示也必须留在编辑区,包含终端最大化后的零宽、零高区域。 - frame.within(app.layout.editor, |frame| draw_content(app, frame)); - for (rect, _) in &mut app.hits.diff { - *rect = rect.intersect(app.layout.editor); - } - for (rect, _) in &mut app.hits.log { - *rect = rect.intersect(app.layout.editor); - } -} - -fn draw_content(app: &mut App, frame: &mut Frame<'_>) { // Markdown、PDF 预览绘制时重新填充;预览不显示时若仍保留,滚轮和点击事件会被预览接收。 app.preview.markdown.area = Rect::default(); app.preview.pdf.area = Rect::default(); From 7eeec79a44eed7660f15a187179212be04c91017 Mon Sep 17 00:00:00 2001 From: ventupx Date: Sat, 21 Nov 2026 16:26:18 +0800 Subject: [PATCH 5/6] fix: honor Git tree layout and preserve sidebar resizing Apply the selected layout to every repository in the Git sidebar, including compact directories, independent folds, and staging groups. Discard obsolete row animations when switching layouts. Keep the sidebar splitter draggable when a filename is expanded and finish filename transitions during resizing so they cannot leave text over the editor or terminal. Add Windows-capable menu, tree, dragging, and pixel regression tests. --- crates/winc-app/src/app/git.rs | 7 + crates/winc-app/src/app/git/commit.rs | 7 +- crates/winc-app/src/app/git/commit/menu.rs | 8 +- crates/winc-app/src/app/git/commit/others.rs | 130 ++++++++++- crates/winc-app/src/app/git/commit/press.rs | 1 + crates/winc-app/src/app/git/commit/state.rs | 3 +- .../winc-app/src/app/input/mouse/regions.rs | 15 +- crates/winc-app/src/app/input/mouse/target.rs | 5 +- .../src/app/snapshot/git/commit/names.rs | 33 ++- .../winc-app/src/app/snapshot/git_layout.rs | 207 ++++++++++++++++++ .../winc-app/src/app/snapshot/git_overflow.rs | 130 +++++++++++ crates/winc-app/src/app/snapshot/mod.rs | 2 + .../winc-app/src/app/workspace/tree_label.rs | 10 +- crates/winc-app/src/view/git/commit/others.rs | 63 +++++- .../winc-app/src/view/git/commit/overflow.rs | 6 +- 15 files changed, 579 insertions(+), 48 deletions(-) create mode 100644 crates/winc-app/src/app/snapshot/git_layout.rs create mode 100644 crates/winc-app/src/app/snapshot/git_overflow.rs diff --git a/crates/winc-app/src/app/git.rs b/crates/winc-app/src/app/git.rs index 73434027..f0ddbcb9 100644 --- a/crates/winc-app/src/app/git.rs +++ b/crates/winc-app/src/app/git.rs @@ -394,6 +394,13 @@ impl Default for GitState { } impl GitState { + /// 测试用:提供后台读到的仓库状态,不启动 Git 进程。 + #[cfg(test)] + pub(in crate::app) fn summary_for_test(&self, root: PathBuf, status: Status) { + self.summaries.lock().unwrap().insert(root, status); + self.summaries_changed(); + } + /// 记下各仓库的状态(`summaries`)改过了。 pub(crate) fn summaries_changed(&self) { (self.summaries_version).fetch_add(1, std::sync::atomic::Ordering::Release); diff --git a/crates/winc-app/src/app/git/commit.rs b/crates/winc-app/src/app/git/commit.rs index 8d292d29..d53dfea8 100644 --- a/crates/winc-app/src/app/git/commit.rs +++ b/crates/winc-app/src/app/git/commit.rs @@ -500,6 +500,8 @@ pub enum CommitTarget { /// 另一个仓库里的一组的标题行(仓库的下标,组):折叠或展开这一组;暂存区视图中悬停时行尾 /// 显示暂存、取消暂存整组的按钮。 OtherGroup(usize, others::OtherGroup), + /// 其他仓库更改树的目录行,在 `commit_other_rows` 中的下标。 + OtherDir(usize), /// 勾选式下另一个仓库里一组标题的勾选框:勾上或取消这一组的全部文件。 OtherGroupFiles(usize, others::OtherGroup), /// 另一个仓库标题行左端的折叠箭头:折叠或展开这个仓库的一节。 @@ -787,6 +789,8 @@ pub(crate) struct CommitState { pub(in crate::app::git) carry_in: bool, /// 多仓库时折叠着的其他仓库(组为 `None`)和其中折叠着的组,按仓库的根目录记。 other_folds: HashSet<(PathBuf, Option)>, + /// 其他仓库更改树中收起的目录:仓库、分组、相对目录。 + other_collapsed_dirs: HashSet<(PathBuf, others::OtherGroup, PathBuf)>, /// 「没有更改的仓库」一组是否展开;未选过时为 `None`,见 [`App::quiet_repositories_open`]。 pub(crate) quiet_open: Option, /// 其他仓库各行的缓存(见 [`App::commit_other_rows`])。 @@ -959,6 +963,7 @@ impl Default for CommitState { others_left: 0, carry_in: false, other_folds: HashSet::new(), + other_collapsed_dirs: HashSet::new(), quiet_open: None, other_rows: Default::default(), head: None, @@ -1315,7 +1320,7 @@ impl App { /// 窗口坐标的 `y` 是否落在写全名的那一改动行上:鼠标在这一行上时不唤出列表的滚动条, /// 和文件树相同。 - pub(in crate::app) fn over_commit_overflow_row(&self, y: f32) -> bool { + pub(crate) fn over_commit_overflow_row(&self, y: f32) -> bool { self.commit_shown() && (self.git.commit.overflow).is_some_and(|o| (o.y..o.y + COMMIT_ROW).contains(&y)) } diff --git a/crates/winc-app/src/app/git/commit/menu.rs b/crates/winc-app/src/app/git/commit/menu.rs index 8f846166..f5228cdc 100644 --- a/crates/winc-app/src/app/git/commit/menu.rs +++ b/crates/winc-app/src/app/git/commit/menu.rs @@ -30,7 +30,8 @@ impl App { }; let all_collapsed = shown().all(|group| self.git.commit.group_collapsed(group)); let all_expanded = shown().all(|group| !self.git.commit.group_collapsed(group)) - && self.git.commit.collapsed_dirs.iter().all(HashSet::is_empty); + && self.git.commit.collapsed_dirs.iter().all(HashSet::is_empty) + && self.git.commit.other_collapsed_dirs.is_empty(); let busy = self.git.branch.running.is_some(); // 拉取自…、推送到…在远程仓库子菜单里,在分支上、有远程时可用。 let transfer = self.picker_action_enabled(PickerPart::Push); @@ -252,6 +253,11 @@ impl App { pub(in crate::app) fn toggle_commit_layout(&mut self) { let flat = !self.git.commit.flat(); self.git.commit.set_flat(flat); + // 展开、收起动画保存着旧模式的行,切换后立即按新模式绘制。 + self.git.commit.motion = None; + self.git.commit.fold_motion = None; + self.git.commit.shift = None; + self.git.commit.overflow = None; self.update_state(|state| state.commit_tree = !flat); self.git.commit.scroll = self.git.commit.scroll.min(self.commit_max_scroll()); self.reveal_commit_selection(); diff --git a/crates/winc-app/src/app/git/commit/others.rs b/crates/winc-app/src/app/git/commit/others.rs index 9753cfb6..fe5e3f3b 100644 --- a/crates/winc-app/src/app/git/commit/others.rs +++ b/crates/winc-app/src/app/git/commit/others.rs @@ -42,7 +42,7 @@ impl OtherGroup { } /// 多仓库时改动列表中当前仓库那一节以外的一行。 -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum OtherRow { /// 当前仓库的标题行;它的改动列表([`App::commit_rows`])紧接在下面。 Current, @@ -59,6 +59,10 @@ pub(crate) enum OtherRow { /// 另一个仓库中有更改的文件:仓库的下标,文件在该仓库状态各项中的下标。暂存区视图中是 /// 尚未暂存的那一部分。 File(usize, usize), + /// 其他仓库更改树中的目录:仓库、分组、相对路径、合并显示的名称、层数。 + Dir(usize, OtherGroup, PathBuf, String, usize), + /// 其他仓库更改树中的文件:仓库、状态下标、分组、层数。 + TreeFile(usize, usize, OtherGroup, usize), } /// 决定 [`App::commit_other_rows`] 的各项:都没变时各行也不变。 @@ -70,6 +74,8 @@ pub(crate) struct OtherRowsKey { root: Option, /// 是否暂存区视图(分组不同)。 staging: bool, + /// 列表、树形、排序、紧凑目录及目录折叠状态的版本。 + layout: u64, /// 仓库列表。 repositories: Vec, /// 折叠着的仓库和组。 @@ -86,6 +92,68 @@ fn commits_staged(entry: &Entry) -> bool { entry.staged.is_some() && !entry.conflicted() } +/// 将其他仓库一组的改动按目录排列,沿用当前仓库的紧凑目录和文件排序规则。 +fn push_other_level<'a>( + commit: &CommitState, + status: &Status, + (repo, root, group): (usize, &Path, OtherGroup), + dir: &Path, + items: Vec<(usize, &'a Path)>, + depth: usize, + out: &mut Vec, +) { + let mut files = Vec::new(); + let mut dirs: BTreeMap, Vec<(usize, &'a Path)>> = BTreeMap::new(); + for (index, path) in items { + let mut parts = path.components(); + match (parts.next(), parts.as_path()) { + (Some(first), rest) if !rest.as_os_str().is_empty() => { + dirs.entry(NaturalName(first.as_os_str())) + .or_default() + .push((index, rest)); + } + _ => files.push((index, path)), + } + } + for (NaturalName(name), mut sub) in dirs { + let mut label = PathBuf::from(name); + while let Some(next) = only_subdir(&sub).filter(|_| commit.compact) { + label.push(next); + for (_, path) in &mut sub { + let rest: &'a Path = path; + *path = rest.strip_prefix(next).unwrap_or(Path::new("")); + } + } + let full = dir.join(&label); + let label = label + .components() + .map(|p| p.as_os_str().to_string_lossy()) + .collect::>() + .join("/"); + out.push(OtherRow::Dir(repo, group, full.clone(), label, depth)); + if !commit + .other_collapsed_dirs + .contains(&(root.to_path_buf(), group, full.clone())) + { + push_other_level( + commit, + status, + (repo, root, group), + &full, + sub, + depth + 1, + out, + ); + } + } + commit.sort_files(status, &mut files); + out.extend( + files + .into_iter() + .map(|(index, _)| OtherRow::TreeFile(repo, index, group, depth)), + ); +} + impl App { /// 「显示全部仓库」是否开着:没有选过时勾选式开着,暂存区视图关着。 pub(crate) fn commit_all_repositories(&self) -> bool { @@ -114,6 +182,7 @@ impl App { version: self.git.summaries_version(), root: self.git.root.clone(), staging: self.git.commit.staging(), + layout: self.git.commit.layout, repositories: self.git.repositories.clone(), folds: self.git.commit.other_folds.clone(), current_changed: self.current_changed(), @@ -185,10 +254,30 @@ impl App { if folded.contains(&(repo.clone(), Some(group))) { continue; } - rows.extend(files.into_iter().map(|n| match group { - OtherGroup::Staged => OtherRow::Staged(i, n), - _ => OtherRow::File(i, n), - })); + let mut files: Vec<(usize, &Path)> = files + .into_iter() + .map(|n| { + let path = &status.entries[n].path; + (n, path.strip_prefix(repo).unwrap_or(path)) + }) + .collect(); + if self.git.commit.flat() { + self.git.commit.sort_files(status, &mut files); + rows.extend(files.into_iter().map(|(n, _)| match group { + OtherGroup::Staged => OtherRow::Staged(i, n), + _ => OtherRow::File(i, n), + })); + } else { + push_other_level( + &self.git.commit, + status, + (i, repo, group), + Path::new(""), + files, + 0, + &mut rows, + ); + } } } // 当前仓库不在仓库列表里(刚打开、还没查找完)时排在最前。 @@ -351,6 +440,37 @@ impl App { self.git.commit.other_folds.contains(&(root.clone(), group)) } + /// 其他仓库中某一组的目录是否收起。 + pub(crate) fn other_dir_folded(&self, repo: usize, group: OtherGroup, dir: &Path) -> bool { + self.git.repositories.get(repo).is_some_and(|root| { + self.git + .commit + .other_collapsed_dirs + .contains(&(root.clone(), group, dir.to_path_buf())) + }) + } + + /// 点击其他仓库的目录,仅展开、收起该目录,保留当前仓库。 + pub(super) fn toggle_other_dir(&mut self, row: usize) { + let rows = self.commit_other_rows(); + let Some(OtherRow::Dir(repo, group, dir, ..)) = rows.get(row) else { + return; + }; + let Some(root) = self.git.repositories.get(*repo) else { + return; + }; + let key = (root.clone(), *group, dir.clone()); + let commit = &mut self.git.commit; + if !commit.other_collapsed_dirs.remove(&key) { + commit.other_collapsed_dirs.insert(key); + } + commit.layout += 1; + commit.motion = None; + commit.fold_motion = None; + self.git.commit.scroll = self.git.commit.scroll.min(self.commit_max_scroll()); + self.request_redraw(); + } + /// 标题行 `header` 的折叠箭头转过的比例:0 指向右(收起),1 指向下(展开)。该行正在展开 /// 或收起时随动画转动,否则按 `open`。 pub(crate) fn other_fold_turn(&self, header: OtherRow, open: bool) -> f32 { diff --git a/crates/winc-app/src/app/git/commit/press.rs b/crates/winc-app/src/app/git/commit/press.rs index 26144bce..91f88a1d 100644 --- a/crates/winc-app/src/app/git/commit/press.rs +++ b/crates/winc-app/src/app/git/commit/press.rs @@ -56,6 +56,7 @@ impl App { CommitTarget::OtherGroup(repo, group) => { self.toggle_other_fold(Some(repo), Some(group)) } + CommitTarget::OtherDir(row) => self.toggle_other_dir(row), CommitTarget::OtherFold(repo) => self.toggle_other_fold(Some(repo), None), CommitTarget::CurrentFold => self.toggle_other_fold(None, None), CommitTarget::CurrentRepository => self.focus = Focus::CommitList, diff --git a/crates/winc-app/src/app/git/commit/state.rs b/crates/winc-app/src/app/git/commit/state.rs index 6fa4678a..13438a30 100644 --- a/crates/winc-app/src/app/git/commit/state.rs +++ b/crates/winc-app/src/app/git/commit/state.rs @@ -265,7 +265,7 @@ impl CommitState { } /// 按 [`CommitState::sort`] 排 `files`(各项在状态中的下标和相对仓库根的路径)。 - fn sort_files(&self, status: &Status, files: &mut [(usize, &Path)]) { + pub(super) fn sort_files(&self, status: &Status, files: &mut [(usize, &Path)]) { let letter = |index: usize| status.entries.get(index).map(|e| e.shown().letter()); files.sort_by(|a, b| match self.sort { CommitSort::Path => natural_path_cmp(a.1, b.1), @@ -284,6 +284,7 @@ impl CommitState { self.collapsed = [collapse; CommitGroup::COUNT]; if !collapse { self.forget_dirs(); + self.other_collapsed_dirs.clear(); } self.layout += 1; } diff --git a/crates/winc-app/src/app/input/mouse/regions.rs b/crates/winc-app/src/app/input/mouse/regions.rs index 47d5250a..b812fbb6 100644 --- a/crates/winc-app/src/app/input/mouse/regions.rs +++ b/crates/winc-app/src/app/input/mouse/regions.rs @@ -30,8 +30,8 @@ impl App { // 提交视图:输入框之外按绘制时记下的位置找。 if self.commit_shown() && y >= self.panel_rect().y { - // 分隔条由 `Target::Splitter` 处理,写全名的那一行除外:该行覆盖在分隔条之上。 - if self.on_splitter_outside_commit_overflow(x, y) { + // 文件名可以显示在分隔条上,但分隔条始终保留调整宽度的命中区域。 + if self.on_sidebar_splitter(x, y) { return None; } return Some(hit(&self.hits.commit, x, y).map_or(Hover::None, Hover::Commit)); @@ -273,12 +273,9 @@ impl App { true } - /// (`x`, `y`) 是否在分隔条上、且不在提交视图里写全名的那一行上:该行覆盖在分隔条之上,与文件 - /// 树的处理相同(见 [`App::target_at`])。 - fn on_splitter_outside_commit_overflow(&self, x: f32, y: f32) -> bool { - self.panels.sidebar.visible - && self.layout.splitter.contains(x, y) - && !self.over_commit_overflow_row(y) + /// (`x`, `y`) 是否在侧栏分隔条上;Git 文件名浮层不抢占调整宽度的区域。 + fn on_sidebar_splitter(&self, x: f32, y: f32) -> bool { + self.panels.sidebar.visible && self.layout.splitter.contains(x, y) } /// 是否已处理对侧栏顶部切换按钮或搜索面板的点击。 @@ -319,7 +316,7 @@ impl App { } if self.commit_shown() && y >= self.panel_rect().y { - if self.on_splitter_outside_commit_overflow(x, y) { + if self.on_sidebar_splitter(x, y) { return false; } if let Some(focus) = self.field_at(x, y) { diff --git a/crates/winc-app/src/app/input/mouse/target.rs b/crates/winc-app/src/app/input/mouse/target.rs index f5605a6c..cca6722d 100644 --- a/crates/winc-app/src/app/input/mouse/target.rs +++ b/crates/winc-app/src/app/input/mouse/target.rs @@ -368,10 +368,9 @@ impl App { if l.search.contains(x, y) { return Target::Search; } - // 名称显示不全而展开的行(文件树、改动列表)覆盖在分隔条上,该行优先; - // 其余各行仍可拖动分隔条。 + // 文件树、搜索结果的展开行覆盖分隔条;Git 改动列表始终保留分隔条的命中区域。 let over_row = self.over_tree_overflow_row(y); - let over_any = over_row || over_commit_row || over_result_row; + let over_any = over_row || over_result_row; if self.panels.sidebar.visible && !over_any && l.splitter.contains(x, y) { return Target::Splitter; } diff --git a/crates/winc-app/src/app/snapshot/git/commit/names.rs b/crates/winc-app/src/app/snapshot/git/commit/names.rs index 2eda424c..f1ee720b 100644 --- a/crates/winc-app/src/app/snapshot/git/commit/names.rs +++ b/crates/winc-app/src/app/snapshot/git/commit/names.rs @@ -911,11 +911,9 @@ fn the_full_name_row_covers_the_scrollbar_like_the_file_tree() { let _ = std::fs::remove_dir_all(&dir); } -/// 显示全名的改动行覆盖在侧栏与编辑区之间的分隔条之上,与文件树的处理相同:鼠标从名字经分隔条 -/// 移到伸出侧栏的部分时,始终悬停在这一行上,全名不收回;在此处按下选中这一行,不拖动分隔条。 -/// 其他行仍可拖动分隔条。 +/// 全名可以跨过分隔条显示,但分隔条始终响应宽度拖拽;鼠标经过它移向全名时不收回。 #[test] -fn the_full_name_row_covers_the_splitter_like_the_file_tree() { +fn the_splitter_stays_draggable_when_a_change_name_is_expanded() { let Some((dir, long)) = long_name_repo("git-commit-overflow-splitter") else { return; }; @@ -928,13 +926,9 @@ fn the_full_name_row_covers_the_splitter_like_the_file_tree() { paint(&mut app); let status = app.git.status.clone().unwrap(); let rows = app.commit_rows(); - let (i, index) = (rows.iter().enumerate()) - .find_map(|(i, r)| match r { - CommitRow::File { index, .. } if status.entries[*index].path.ends_with(&long) => { - Some((i, *index)) - } - _ => None, - }) + let i = rows + .iter() + .position(|r| matches!(r, CommitRow::File { index, .. } if status.entries[*index].path.ends_with(&long))) .unwrap(); let list = app.commit_parts().list; let y = list.y + i as f32 * COMMIT_ROW - app.git.commit.scroll + COMMIT_ROW / 2.0; @@ -943,7 +937,6 @@ fn the_full_name_row_covers_the_splitter_like_the_file_tree() { assert!(app.git.commit.overflow.is_some_and(|o| o.row == i)); let splitter = app.layout.splitter; - let row = Hover::Commit(CommitTarget::File(index)); for x in [ splitter.x + 1.0, splitter.x + splitter.w / 2.0, @@ -951,17 +944,21 @@ fn the_full_name_row_covers_the_splitter_like_the_file_tree() { ] { app.on_mouse_move(x, y); paint(&mut app); - assert_eq!(app.pointer.hover, row, "x = {x}"); + assert_eq!(app.pointer.hover, Hover::Splitter, "x = {x}"); assert!( app.git.commit.overflow.is_some_and(|o| o.row == i), "x = {x}" ); } - click(&mut app, (splitter.x + splitter.w / 2.0, y)); - assert_eq!( - app.git.commit.selected.as_deref(), - Some(status.entries[index].path.as_path()) - ); + let selected = app.git.commit.selected.clone(); + app.on_mouse_move(splitter.x + splitter.w / 2.0, y); + app.on_mouse_down(MouseButton::Left); + assert!(matches!( + app.pointer.drag, + crate::app::Drag::Splitter { .. } + )); + assert_eq!(app.git.commit.selected, selected); + app.on_mouse_up(MouseButton::Left); assert_eq!(app.layout.splitter, splitter); // 其他行:分隔条正常响应。 diff --git a/crates/winc-app/src/app/snapshot/git_layout.rs b/crates/winc-app/src/app/snapshot/git_layout.rs new file mode 100644 index 00000000..f1e9977d --- /dev/null +++ b/crates/winc-app/src/app/snapshot/git_layout.rs @@ -0,0 +1,207 @@ +//! Git 更改列表的跨平台显示模式测试,不依赖外部 Git 进程。 + +use super::*; +use crate::app::input::context_menu::MenuEntry; +use crate::app::{CommitRow, CommitTarget, OtherGroup, OtherRow, PopupRow}; +use winc_editor::git::{Change, Entry, Head, Status}; + +#[test] +fn git_layout_menu_rebuilds_and_draws_the_current_repository_tree() { + let dir = sample_folder("git-layout-menu"); + let mut app = app_with(&dir, false); + let root = app.editor.root().unwrap().to_path_buf(); + app.git.root = Some(root.clone()); + app.git.status = Some(Status { + head: Some(Head::Branch("main".into())), + entries: ["src/main.rs", "src/nested/lib.rs", "Cargo.toml"] + .into_iter() + .map(|path| Entry { + path: root.join(path), + from: None, + staged: None, + unstaged: Some(Change::Modified), + is_dir: false, + }) + .collect(), + ..Status::default() + }); + app.panels.sidebar.view = SidebarView::Commit; + paint(&mut app); + assert!( + !app.commit_rows() + .iter() + .any(|r| matches!(r, CommitRow::Dir { .. })) + ); + + for command in [MenuCommand::CommitTree, MenuCommand::CommitList] { + // 模式切换不能继续绘制展开动画里保存的旧版列表。 + app.git.commit.motion = Some(crate::app::git::commit::CommitMotion { + rows: app.commit_rows(), + parent: 0, + count: 3, + expanding: true, + clock: crate::app::Clock::stopped( + std::time::Duration::from_secs(1), + std::time::Duration::from_millis(500), + ), + }); + app.press_commit(CommitTarget::More); + paint(&mut app); + let menu = app.overlays.context_menu.as_ref().unwrap(); + let top = &app.popup().unwrap().levels[0]; + let index = top + .rows + .iter() + .position(|row| match row { + PopupRow::Submenu { rows, .. } => rows.iter().any(|row| { + matches!(row, PopupRow::Item { tag, .. } + if MenuEntry::command_at(&menu.entries, *tag) == Some(command)) + }), + _ => false, + }) + .unwrap(); + let at = top.row_rects[index]; + click(&mut app, (at.x + 20.0, at.y + at.h / 2.0)); + paint(&mut app); + let menu = app.overlays.context_menu.as_ref().unwrap(); + let sub = &app.popup().unwrap().levels[1]; + let index = sub + .rows + .iter() + .position(|row| { + matches!(row, PopupRow::Item { tag, .. } + if MenuEntry::command_at(&menu.entries, *tag) == Some(command)) + }) + .unwrap(); + let at = sub.row_rects[index]; + click(&mut app, (at.x + 20.0, at.y + at.h / 2.0)); + paint(&mut app); + let tree = command == MenuCommand::CommitTree; + assert_eq!(app.state.commit_tree, tree); + assert!(app.menu_checked(command)); + assert!(app.git.commit.motion.is_none()); + assert!(app.git.commit.fold_motion.is_none()); + assert_eq!( + app.commit_rows() + .iter() + .any(|r| matches!(r, CommitRow::Dir { .. })), + tree + ); + assert_eq!( + app.hits + .commit + .iter() + .any(|(_, t)| matches!(t, CommitTarget::Dir(_))), + tree + ); + } + let _ = std::fs::remove_dir_all(&dir); +} + +#[test] +fn git_layout_tree_applies_to_other_repositories() { + let folder = sample_folder("git-layout-others"); + let mut app = app_with(&folder, false); + let root = app.editor.root().unwrap().to_path_buf(); + let other = root.join("other"); + app.git.root = Some(root.clone()); + app.git.repositories = vec![root.clone(), other.clone()]; + app.git.status = Some(Status::default()); + app.state.commit_all_repositories = Some(true); + app.git.summary_for_test( + other.clone(), + Status { + entries: ["src/main.rs", "src/nested/lib.rs", "Cargo.toml"] + .into_iter() + .map(|path| Entry { + path: other.join(path), + from: None, + staged: None, + unstaged: Some(Change::Modified), + is_dir: false, + }) + .collect(), + ..Status::default() + }, + ); + let flat = app.commit_other_rows(); + app.toggle_commit_layout(); + let tree = app.commit_other_rows(); + assert!(tree.len() > flat.len(), "树形模式应显示其他仓库的目录行"); + assert!( + tree.iter() + .any(|r| matches!(r, OtherRow::TreeFile(1, 1, OtherGroup::Changes, 2))) + ); + app.panels.sidebar.view = SidebarView::Commit; + paint(&mut app); + if std::env::var_os("WINC_SNAPSHOT_DIR").is_some() { + shoot(&mut app, "git-layout-other-tree"); + } + let dir = tree + .iter() + .position(|r| matches!(r, OtherRow::Dir(_, _, path, _, 0) if path == Path::new("src"))) + .unwrap(); + let hit = app + .hits + .commit + .iter() + .find(|(_, t)| *t == CommitTarget::OtherDir(dir)) + .unwrap() + .0; + click(&mut app, (hit.x + 80.0, hit.y + hit.h / 2.0)); + assert_eq!(app.git.root, Some(root)); + assert!( + !app.commit_other_rows() + .iter() + .any(|r| matches!(r, OtherRow::TreeFile(1, 0 | 1, ..))) + ); + assert!( + app.commit_other_rows() + .iter() + .any(|r| matches!(r, OtherRow::TreeFile(1, 2, ..))) + ); + app.run_commit_more_command(MenuCommand::CommitExpandAll); + assert_eq!(app.commit_other_rows(), tree); + app.toggle_commit_layout(); + assert_eq!(app.commit_other_rows(), flat); + + // 只暂存了一部分的文件分别出现在两组,目录的折叠互不影响。 + app.git.summary_for_test( + other.clone(), + Status { + entries: vec![Entry { + path: other.join("src/main.rs"), + from: None, + staged: Some(Change::Modified), + unstaged: Some(Change::Modified), + is_dir: false, + }], + ..Status::default() + }, + ); + app.git.commit.set_staging(true); + app.toggle_commit_layout(); + let rows = app.commit_other_rows(); + for group in [OtherGroup::Staged, OtherGroup::Changes] { + assert!( + rows.iter() + .any(|r| matches!(r, OtherRow::TreeFile(1, 0, g, 1) if *g == group)) + ); + } + let dir = rows + .iter() + .position(|r| matches!(r, OtherRow::Dir(_, OtherGroup::Staged, ..))) + .unwrap(); + app.press_commit(CommitTarget::OtherDir(dir)); + let rows = app.commit_other_rows(); + assert!( + !rows + .iter() + .any(|r| matches!(r, OtherRow::TreeFile(_, _, OtherGroup::Staged, _))) + ); + assert!( + rows.iter() + .any(|r| matches!(r, OtherRow::TreeFile(_, _, OtherGroup::Changes, _))) + ); + let _ = std::fs::remove_dir_all(&folder); +} diff --git a/crates/winc-app/src/app/snapshot/git_overflow.rs b/crates/winc-app/src/app/snapshot/git_overflow.rs new file mode 100644 index 00000000..702dac55 --- /dev/null +++ b/crates/winc-app/src/app/snapshot/git_overflow.rs @@ -0,0 +1,130 @@ +//! Git 文件名悬停展开与侧栏宽度拖拽的跨平台回归测试。 + +use super::*; +use crate::app::{CommitName, CommitTarget, Drag}; +use winc_editor::git::{Change, Entry, Head, Status}; + +fn long_change_app(name: &str, flat: bool, dark: bool) -> (App, PathBuf, CommitName, Rect) { + let dir = sample_folder(name); + let mut app = app_with(&dir, dark); + let root = app.editor.root().unwrap().to_path_buf(); + let path = + root.join("src/a-very-long-file-name-that-extends-over-the-editor-or-terminal.zip.sha256"); + app.git.root = Some(root); + app.git.status = Some(Status { + head: Some(Head::Branch("dev".into())), + entries: vec![Entry { + path: path.clone(), + from: None, + staged: None, + unstaged: Some(Change::Modified), + is_dir: false, + }], + ..Status::default() + }); + app.git.commit.set_flat(flat); + app.git.commit.names.animate_without_window = true; + app.panels.sidebar.view = SidebarView::Commit; + paint(&mut app); + let row = app + .hits + .commit + .iter() + .find(|(_, t)| *t == CommitTarget::File(0)) + .unwrap() + .0; + (app, dir, CommitName::File(path), row) +} + +fn pixels_beside_row(app: &App, row: Rect) -> Vec { + let image = app.frame.renderer.as_ref().unwrap().image().unwrap(); + let left = ((app.layout.sidebar.right() + 12.0) * SCALE) as usize; + let right = (left + 600).min(image.width as usize - 12); + let top = (row.y * SCALE) as usize; + let bottom = ((row.bottom() - 1.0) * SCALE) as usize; + (top..bottom) + .flat_map(|y| { + let start = y * image.width as usize; + image.pixels[start + left..start + right].to_vec() + }) + .collect() +} + +#[test] +fn git_overflow_keeps_the_splitter_draggable_on_a_hovered_file_row() { + for flat in [false, true] { + let (mut app, dir, _, row) = + long_change_app(&format!("git-overflow-splitter-{flat}"), flat, false); + let y = row.y + row.h / 2.0; + app.on_mouse_move(row.x + 120.0, y); + paint(&mut app); + app.git.commit.names.finish(); + app.git.commit.actions_slide = None; + paint(&mut app); + let spill = app.git.commit.overflow.and_then(|o| o.spill).unwrap(); + let splitter = app.layout.splitter; + let x = splitter.x + splitter.w / 2.0; + app.on_mouse_move(x, y); + paint(&mut app); + assert_eq!(app.pointer.hover, Hover::Splitter); + // 经过分隔条仍能看到全名,但在边界按下时应开始调整宽度。 + assert!(app.git.commit.overflow.is_some()); + app.on_mouse_move(spill.x + 40.0, y); + paint(&mut app); + assert!(matches!(app.pointer.hover, Hover::Commit(_))); + app.on_mouse_move(x, y); + paint(&mut app); + app.on_mouse_down(MouseButton::Left); + assert!(matches!(app.pointer.drag, Drag::Splitter { .. })); + assert!(app.git.commit.selected.is_none()); + let before = app.layout.sidebar.w; + app.on_mouse_move(x + 64.0, y); + assert!(app.layout.sidebar.w > before + 40.0); + app.on_mouse_up(MouseButton::Left); + let _ = std::fs::remove_dir_all(dir); + } +} + +#[test] +fn git_overflow_retraction_leaves_no_filename_over_the_editor_during_resize() { + for dark in [false, true] { + for flat in [false, true] { + let (mut app, dir, key, row) = + long_change_app(&format!("git-overflow-retract-{dark}-{flat}"), flat, dark); + let baseline = pixels_beside_row(&app, row); + let y = row.y + row.h / 2.0; + app.on_mouse_move(row.x + 120.0, y); + paint(&mut app); + app.git.commit.names.finish(); + app.git.commit.actions_slide = None; + paint(&mut app); + assert!( + pixels_beside_row(&app, row) != baseline, + "必须先显示伸出侧栏的全名" + ); + // 在另一行开始拖动,让原来那一行进入收回动画,复现偶发的残留。 + let x = app.layout.splitter.x + app.layout.splitter.w / 2.0; + let away = y + 3.0 * row.h; + app.on_mouse_move(x, away); + paint(&mut app); + assert!(app.git.commit.names.moving()); + app.on_mouse_down(MouseButton::Left); + assert!(matches!(app.pointer.drag, Drag::Splitter { .. })); + paint(&mut app); + assert!(app.git.commit.overflow.is_none()); + assert!( + pixels_beside_row(&app, row) == baseline, + "拖拽期间不应在编辑区上残留文件名" + ); + assert!(!app.git.commit.names.moving()); + let clipped = app.git.commit.names.peek(&key).unwrap().width; + app.on_mouse_move(x + 48.0, away); + paint(&mut app); + assert!(app.git.commit.names.peek(&key).unwrap().width > clipped); + app.on_mouse_up(MouseButton::Left); + paint(&mut app); + assert!(app.git.commit.overflow.is_none()); + let _ = std::fs::remove_dir_all(dir); + } + } +} diff --git a/crates/winc-app/src/app/snapshot/mod.rs b/crates/winc-app/src/app/snapshot/mod.rs index d38e1c93..63616112 100644 --- a/crates/winc-app/src/app/snapshot/mod.rs +++ b/crates/winc-app/src/app/snapshot/mod.rs @@ -22,6 +22,8 @@ mod animation; mod editor; #[cfg(unix)] mod git; +mod git_layout; +mod git_overflow; mod input; #[cfg(target_os = "macos")] mod memory; diff --git a/crates/winc-app/src/app/workspace/tree_label.rs b/crates/winc-app/src/app/workspace/tree_label.rs index 09396664..9f3a4066 100644 --- a/crates/winc-app/src/app/workspace/tree_label.rs +++ b/crates/winc-app/src/app/workspace/tree_label.rs @@ -136,6 +136,11 @@ impl TreeLabels { pub fn begin_frame(&mut self, animate: bool) { self.frame += 1; self.animate = animate; + if !animate { + for row in self.rows.get_mut().values_mut() { + row.motion = None; + } + } } /// 结束绘制一帧:不再显示的行不再记录,之后再出现时不播放过渡。 @@ -258,8 +263,11 @@ impl App { self.clock(STATUS_SLIDE).is_some() } - /// 改动列表的名字本帧是否播放过渡,条件同 [`App::animate_tree_labels`]。 + /// 改动列表名字的过渡条件同 [`App::animate_tree_labels`];拖动或侧栏开合时直接采用当前布局。 pub(crate) fn animate_commit_names(&mut self) -> bool { + if !self.idle_pointer() { + return false; + } #[cfg(test)] if self.git.commit.names.animate_without_window { return true; diff --git a/crates/winc-app/src/view/git/commit/others.rs b/crates/winc-app/src/view/git/commit/others.rs index 6f6f56d2..35d14b35 100644 --- a/crates/winc-app/src/view/git/commit/others.rs +++ b/crates/winc-app/src/view/git/commit/others.rs @@ -6,8 +6,8 @@ use crate::app::{OtherGroup, OtherRow}; /// 绘制多仓库时当前仓库改动列表以外的各行,记下可点击的位置。 /// /// 各行按 `App::commit_other_rows` 的顺序排,随列表一起滚动。当前仓库标题行之后的各行让出 -/// 当前仓库改动列表的高度 `block`(逻辑像素)。仓库标题在最外一层,组、文件缩进一层,与当前 -/// 仓库改动列表的组、平铺的文件同列。 +/// 当前仓库改动列表的高度 `block`(逻辑像素)。仓库标题在最外一层,组、平铺的文件缩进一层, +/// 树形模式中的目录和文件再按层级缩进,与当前仓库的排法相同。 pub(super) fn draw_other_rows( app: &App, frame: &mut Frame<'_>, @@ -29,6 +29,17 @@ pub(super) fn draw_other_rows( let mut row_hits = Vec::new(); frame.within(clip, |frame| { let hits = &mut row_hits; + if let OtherRow::Dir(.., depth) | OtherRow::TreeFile(.., depth) = row { + for level in 1..=*depth { + let x = (band.x + ARROW + (level + 1) as f32 * INDENT).round(); + frame.rect_clipped( + Rect::new(x, band.y, 1.0, COMMIT_ROW), + app.palette.indent_guide, + 0.0, + list, + ); + } + } match *row { OtherRow::Current => draw_current_row(app, frame, (list, band), hits), OtherRow::Repository(repo) => { @@ -42,11 +53,47 @@ pub(super) fn draw_other_rows( draw_other_group(app, frame, (list, band), (repo, group), hits); } OtherRow::Staged(repo, entry) => { - draw_other_file(app, frame, (list, band), (repo, entry, Some(true)), hits); + draw_other_file(app, frame, (list, band), (repo, entry, Some(true), 0), hits); } OtherRow::File(repo, entry) => { let side = app.git.commit.staging().then_some(false); - draw_other_file(app, frame, (list, band), (repo, entry, side), hits); + draw_other_file(app, frame, (list, band), (repo, entry, side, 0), hits); + } + OtherRow::Dir(repo, group, ref dir, ref label, depth) => { + let target = CommitTarget::OtherDir(i); + shade_hovered(app, frame, (list, band), target); + let cy = band.y + COMMIT_ROW / 2.0; + let arrow = band.x + ARROW + (depth + 1) as f32 * INDENT; + let open = !app.other_dir_folded(repo, group, dir); + icons::chevron_turned( + frame, + (arrow, cy), + 6.0, + f32::from(u8::from(open)) * std::f32::consts::FRAC_PI_2, + app.palette.text_dim, + list, + ); + let icon_x = arrow + check_gap(app) + ICON; + icons::folder( + frame, + (icon_x, (cy - 6.0).round()), + open, + app.palette.folder, + list, + ); + let text_x = icon_x + icons::FOLDER_WIDTH + LABEL_GAP; + let room = (band.right() - 6.0 - text_x).max(0.0); + let parts = dir_parts(app, frame, label, Some(room)); + draw_dir_parts(app, frame, (text_x, band), &parts, |_| 1.0, list); + hits.push((band.intersect(list), target)); + } + OtherRow::TreeFile(repo, entry, group, depth) => { + let side = app + .git + .commit + .staging() + .then_some(group == OtherGroup::Staged); + draw_other_file(app, frame, (list, band), (repo, entry, side, depth), hits); } } }); @@ -481,7 +528,7 @@ fn draw_other_group( hits.push((band.intersect(list), row)); } -/// 画另一个仓库中的一个文件:图标、名字、淡色的所在目录,右端是状态字母。 +/// 画另一个仓库中的一个文件:图标、名字,平铺时加淡色的所在目录,右端是状态字母。 /// /// `side` 是暂存区视图中这一行所在的部分:`Some(true)` 为已暂存,`Some(false)` 为未暂存; /// 此时行尾是取消暂存或暂存的按钮,状态字母在按钮左边。勾选式下为 `None`。 @@ -489,7 +536,7 @@ fn draw_other_file( app: &App, frame: &mut Frame<'_>, (list, band): (Rect, Rect), - (repo, entry, side): (usize, usize, Option), + (repo, entry, side, depth): (usize, usize, Option, usize), hits: &mut Vec<(Rect, CommitTarget)>, ) { let p = app.palette; @@ -532,7 +579,7 @@ fn draw_other_file( }); let cy = band.y + COMMIT_ROW / 2.0; // 缩进一层,与当前仓库平铺时的文件行同列:勾选式下前面是勾选框,暂存区视图中那一列没有。 - let check = band.x + ARROW + INDENT + check_gap(app); + let check = band.x + ARROW + (depth + 1) as f32 * INDENT + check_gap(app); if check_gap(app) > 0.0 { let state = app.other_status(repo, |_, status| { (status.entries.get(entry)).and_then(|e| app.other_pick_state(e)) @@ -560,7 +607,7 @@ fn draw_other_file( let text_end = button.map_or(letter_x - 8.0, |x| x - 4.0); let clip = Rect::new(list.x, band.y, text_end - list.x, COMMIT_ROW).intersect(list); let room = (text_end - text_x).max(0.0); - let dir = (!dir.is_empty()).then_some(dir.as_str()); + let dir = (app.git.commit.flat() && !dir.is_empty()).then_some(dir.as_str()); let parts = file_parts(app, frame, (&name, dir), Some(room)); let end = draw_file_parts( app, diff --git a/crates/winc-app/src/view/git/commit/overflow.rs b/crates/winc-app/src/view/git/commit/overflow.rs index 106b6107..c858aec7 100644 --- a/crates/winc-app/src/view/git/commit/overflow.rs +++ b/crates/winc-app/src/view/git/commit/overflow.rs @@ -17,6 +17,10 @@ pub(in crate::view) fn commit_overflow(app: &App, frame: &mut Frame<'_>) -> Opti let root = app.git.root.as_deref()?; let rows = app.commit_rows(); let row = match app.pointer.hover { + // 鼠标经过分隔条移向全名时保持展开;在分隔条上按下仍由分隔条开始拖拽。 + Hover::Splitter if app.over_commit_overflow_row(app.mouse().1) => { + app.git.commit.overflow?.row + } Hover::Commit( CommitTarget::Dir(r) | CommitTarget::DirCheck(r) @@ -200,7 +204,7 @@ pub(in crate::view) fn draw_commit_overflow(app: &App, frame: &mut Frame<'_>) { /// /// 底色和列表里的那一段一起淡出(`retracting_color`),写的是收回前的全名,与文件树相同。 pub(in crate::view) fn draw_commit_overflow_closing(app: &App, frame: &mut Frame<'_>) { - if !app.commit_shown() || !app.git.commit.names.moving() { + if !app.commit_shown() || !app.idle_pointer() || !app.git.commit.names.moving() { return; } let (Some(status), Some(root)) = (app.git.status.as_ref(), app.git.root.as_deref()) else { From d6f403d3e178a1a82e92c39995c6254c7b91a2aa Mon Sep 17 00:00:00 2001 From: ventupx Date: Sat, 21 Nov 2026 17:40:49 +0800 Subject: [PATCH 6/6] fix: isolate sidebar hit targets and satisfy source size checks Ignore cached file-tree overflow hit regions outside the file view so they cannot intercept the Git sidebar splitter or the adjacent editor. Seed stale hit regions in the resizing regression to cover every host. Move the periodic Git status recheck into its own module without changing its behavior, keeping the parent module below the source line limit. --- crates/winc-app/src/app/git.rs | 32 +-------------- crates/winc-app/src/app/git/refresh.rs | 39 +++++++++++++++++++ crates/winc-app/src/app/input/mouse/target.rs | 20 ++++++---- .../winc-app/src/app/snapshot/git_overflow.rs | 6 +++ 4 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 crates/winc-app/src/app/git/refresh.rs diff --git a/crates/winc-app/src/app/git.rs b/crates/winc-app/src/app/git.rs index f0ddbcb9..d4561945 100644 --- a/crates/winc-app/src/app/git.rs +++ b/crates/winc-app/src/app/git.rs @@ -16,6 +16,7 @@ pub(crate) mod log; pub(crate) mod merge; pub(crate) mod question; pub(crate) mod rebase; +mod refresh; mod repository; pub(super) mod rewrite; mod stepping; @@ -891,37 +892,6 @@ impl App { self.git_refresh_status(); } - /// Git 视图可见且窗口有焦点时低频补查本地状态,兜底系统未报告的文件变化。 - /// - /// 通知仍负责即时刷新;补查只读取状态,不读取分支、储藏或访问远程仓库。 - pub(in crate::app) fn git_status_tick(&mut self, now: Instant) -> Option { - let visible = self.commit_shown() - || self - .editor - .active() - .is_some_and(|d| d.log.is_some() || d.diff.is_some()); - let local = self - .git - .root - .as_deref() - .is_some_and(|root| !winc_backend::is_remote(root)); - if !self.git_enabled() || !local || !visible || !self.window.focused || self.unseen() { - self.git.recheck_due = None; - return None; - } - let due = *self.git.recheck_due.get_or_insert(now + STATUS_RECHECK); - if now >= due { - self.git.recheck_due = Some(now + STATUS_RECHECK); - if self.git.running.is_none() - && self.git.branch.running.is_none() - && !self.git.commit.staging_active() - { - self.git_refresh_status(); - } - } - self.git.recheck_due - } - /// 只刷新状态,分支与储藏列表保持不变。 /// /// 分支与储藏只随 `.git` 中的内容变化(目录监视报告 `git`,或 winc 自身执行的 Git 操作), diff --git a/crates/winc-app/src/app/git/refresh.rs b/crates/winc-app/src/app/git/refresh.rs new file mode 100644 index 00000000..88401dbb --- /dev/null +++ b/crates/winc-app/src/app/git/refresh.rs @@ -0,0 +1,39 @@ +//! Git 视图可见时补查本地状态,恢复目录监视未报告的改动。 + +use std::time::Instant; + +use super::STATUS_RECHECK; +use crate::app::App; + +impl App { + /// Git 视图可见且窗口有焦点时低频补查本地状态,兜底系统未报告的文件变化。 + /// + /// 通知仍负责即时刷新;补查只读取状态,不读取分支、储藏或访问远程仓库。 + pub(in crate::app) fn git_status_tick(&mut self, now: Instant) -> Option { + let visible = self.commit_shown() + || self + .editor + .active() + .is_some_and(|d| d.log.is_some() || d.diff.is_some()); + let local = self + .git + .root + .as_deref() + .is_some_and(|root| !winc_backend::is_remote(root)); + if !self.git_enabled() || !local || !visible || !self.window.focused || self.unseen() { + self.git.recheck_due = None; + return None; + } + let due = *self.git.recheck_due.get_or_insert(now + STATUS_RECHECK); + if now >= due { + self.git.recheck_due = Some(now + STATUS_RECHECK); + if self.git.running.is_none() + && self.git.branch.running.is_none() + && !self.git.commit.staging_active() + { + self.git_refresh_status(); + } + } + self.git.recheck_due + } +} diff --git a/crates/winc-app/src/app/input/mouse/target.rs b/crates/winc-app/src/app/input/mouse/target.rs index cca6722d..54a2dc7f 100644 --- a/crates/winc-app/src/app/input/mouse/target.rs +++ b/crates/winc-app/src/app/input/mouse/target.rs @@ -738,19 +738,23 @@ impl App { /// /// 只有已展开的行优先。沿边缘上下移动到其他行时,该行尚未展开,滚动条正常响应。 pub(in crate::app) fn over_tree_overflow_row(&self, y: f32) -> bool { - self.panels - .tree - .overflow - .is_some_and(|(rect, _)| (rect.y..rect.bottom()).contains(&y)) + self.panels.sidebar.view == SidebarView::Files + && self + .panels + .tree + .overflow + .is_some_and(|(rect, _)| (rect.y..rect.bottom()).contains(&y)) } /// 窗口坐标 (`x`, `y`)(逻辑像素)是否位于文件树中显示不全的文件名 /// 向右展开、覆盖到编辑区上方的区域内。 pub(in crate::app) fn in_tree_overflow(&self, x: f32, y: f32) -> bool { - self.panels - .tree - .overflow - .is_some_and(|(rect, _)| rect.contains(x, y)) + self.panels.sidebar.view == SidebarView::Files + && self + .panels + .tree + .overflow + .is_some_and(|(rect, _)| rect.contains(x, y)) } /// 按鼠标当前位置重新判断悬停目标和指针样式;每绘制完一帧调用一次。 diff --git a/crates/winc-app/src/app/snapshot/git_overflow.rs b/crates/winc-app/src/app/snapshot/git_overflow.rs index 702dac55..3b4579be 100644 --- a/crates/winc-app/src/app/snapshot/git_overflow.rs +++ b/crates/winc-app/src/app/snapshot/git_overflow.rs @@ -105,9 +105,15 @@ fn git_overflow_retraction_leaves_no_filename_over_the_editor_during_resize() { // 在另一行开始拖动,让原来那一行进入收回动画,复现偶发的残留。 let x = app.layout.splitter.x + app.layout.splitter.w / 2.0; let away = y + 3.0 * row.h; + // 切换视图后文件树可能保留全名区域;隐藏的区域不应抢占分隔条。 + app.panels.tree.overflow = + Some((Rect::new(x - 10.0, away - row.h / 2.0, 80.0, row.h), 0)); + app.on_mouse_move(x + 40.0, away); + assert!(!matches!(app.pointer.hover, Hover::TreeRow(_))); app.on_mouse_move(x, away); paint(&mut app); assert!(app.git.commit.names.moving()); + assert_eq!(app.pointer.hover, Hover::Splitter); app.on_mouse_down(MouseButton::Left); assert!(matches!(app.pointer.drag, Drag::Splitter { .. })); paint(&mut app);