From 1ba2dbdec59ff52dcf2c8c4c1e9704ecc1d94564 Mon Sep 17 00:00:00 2001 From: Qkal Date: Tue, 19 May 2026 15:57:02 +0200 Subject: [PATCH 1/2] Refine markdown path detection in CodeView --- app/src/code/view.rs | 75 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/app/src/code/view.rs b/app/src/code/view.rs index 3243df78..3c0855bc 100644 --- a/app/src/code/view.rs +++ b/app/src/code/view.rs @@ -141,6 +141,25 @@ pub fn tab_position_id(index: usize) -> String { format!("file_tab_position_{index}") } +fn preferred_code_view_path( + local_path: Option, + tab_path: Option, + source_path: Option, +) -> Option { + local_path.or(tab_path).or(source_path) +} + +fn is_markdown_code_view_path( + local_path: Option, + tab_path: Option, + source_path: Option, +) -> bool { + preferred_code_view_path(local_path, tab_path, source_path) + .as_ref() + .map(is_markdown_file) + .unwrap_or(false) +} + #[derive(Debug, Clone)] enum TabBarDragPosition { BeforeTab { index: usize }, @@ -278,15 +297,7 @@ impl CodeView { #[cfg(feature = "local_fs")] fn update_markdown_mode_segmented_control(&mut self, ctx: &mut ViewContext) { - let path = self - .local_path(ctx) - .or_else(|| { - self.tab_at(self.active_tab_index) - .and_then(|t| t.path.clone()) - }) - .or_else(|| self.source.path()); - - let is_markdown = path.as_ref().map(is_markdown_file).unwrap_or(false); + let is_markdown = self.is_active_markdown_tab(ctx); if !is_markdown { self.markdown_mode_segmented_control = None; @@ -641,6 +652,15 @@ impl CodeView { }) } + fn is_active_markdown_tab(&self, ctx: &AppContext) -> bool { + is_markdown_code_view_path( + self.local_path(ctx), + self.tab_at(self.active_tab_index) + .and_then(|t| t.path.clone()), + self.source.path(), + ) + } + pub fn pane_configuration(&self) -> ModelHandle { self.pane_configuration.clone() } @@ -2123,10 +2143,7 @@ impl View for CodeView { fn render(&self, app: &AppContext) -> Box { let tab = self.tab_at(self.active_tab_index); - let is_markdown_tab = tab - .and_then(|t| t.path.as_deref()) - .map(is_markdown_file) - .unwrap_or(false); + let is_markdown_tab = self.is_active_markdown_tab(app); let body = if let Some(tab) = tab { let mut column = Flex::column().with_main_axis_size(MainAxisSize::Max); if let CodeSource::AIAction { .. } = self.source { @@ -2408,3 +2425,35 @@ fn render_unsaved_changes_icon(color: ColorU) -> Box { .with_height(8.) .finish() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn markdown_path_detection_prefers_live_local_path() { + assert!(!is_markdown_code_view_path( + Some(PathBuf::from("src/main.rs")), + Some(PathBuf::from("README.md")), + None, + )); + } + + #[test] + fn markdown_path_detection_falls_back_to_tab_path() { + assert!(is_markdown_code_view_path( + None, + Some(PathBuf::from("README.md")), + Some(PathBuf::from("src/main.rs")), + )); + } + + #[test] + fn markdown_path_detection_falls_back_to_source_path() { + assert!(is_markdown_code_view_path( + None, + None, + Some(PathBuf::from("CHANGELOG")), + )); + } +} From 3eb1e407b15669987327ce77167685053471aec5 Mon Sep 17 00:00:00 2001 From: Qkal Date: Tue, 19 May 2026 19:53:45 +0200 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- app/src/code/view.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/code/view.rs b/app/src/code/view.rs index 3c0855bc..1c6cc445 100644 --- a/app/src/code/view.rs +++ b/app/src/code/view.rs @@ -653,12 +653,18 @@ impl CodeView { } fn is_active_markdown_tab(&self, ctx: &AppContext) -> bool { - is_markdown_code_view_path( - self.local_path(ctx), - self.tab_at(self.active_tab_index) - .and_then(|t| t.path.clone()), - self.source.path(), - ) + if let Some(local_path) = self.local_path(ctx) { + return is_markdown_code_view_path(Some(local_path), None, None); + } + + if let Some(tab_path) = self + .tab_at(self.active_tab_index) + .and_then(|t| t.path.clone()) + { + return is_markdown_code_view_path(None, Some(tab_path), None); + } + + is_markdown_code_view_path(None, None, self.source.path()) } pub fn pane_configuration(&self) -> ModelHandle {