This commit is contained in:
2026-09-04 08:16:05 +07:00
parent 212f35d6bb
commit 17de4f6376
43 changed files with 376 additions and 721 deletions
@@ -17,6 +17,7 @@ const TREE_WIDTH: f32 = 240.;
/// Files larger than this are not previewed.
pub(super) const MAX_PREVIEW_BYTES: usize = 1024 * 1024;
/// Preview cache caps, a file count and a text byte count.
///
/// The oldest previews are evicted beyond the caps.
pub(super) const MAX_PREVIEWED_FILES: usize = 32;
pub(super) const MAX_PREVIEW_CACHE_BYTES: usize = 8 * 1024 * 1024;
@@ -34,9 +35,6 @@ pub(super) enum FileContent {
}
/// A markdown document loaded into a persistent [`TextViewState`].
/// The state lives in the view rather than being created per render.
/// GPUI drops keyed element state after one absent frame.
/// A per-render state would re-parse the whole document on every pane switch.
pub(super) struct MarkdownView {
/// Source path, `None` means the repository README.
pub(super) path: Option<SharedString>,
@@ -44,9 +42,6 @@ pub(super) struct MarkdownView {
}
/// A code file loaded into a persistent [`InputState`].
/// It renders as a disabled, read-only code editor.
/// Syntax highlighting, line numbers and search are included.
/// Persistent for the same reason as [`MarkdownView`].
pub(super) struct CodeView {
/// Source path, relative to the worktree root.
pub(super) path: SharedString,
@@ -216,8 +211,6 @@ impl RepoDetailView {
}
/// Load `text` into the persistent markdown TextView state.
/// The state is created empty and fed via `push_str`, which parses on a background task.
/// Switching files never blocks the main thread.
pub(super) fn set_markdown(
&mut self,
path: Option<SharedString>,
@@ -230,15 +223,18 @@ impl RepoDetailView {
}
/// The persistent markdown TextView for `path`, where `None` is the README.
///
/// Shows a spinner while the document is being loaded or parsed.
fn markdown_element(&self, path: Option<&str>, _cx: &mut Context<Self>) -> AnyElement {
let Some(md) = &self.md else {
return preview_spinner();
};
let ready = match path {
Some(path) => md.path.as_deref() == Some(path),
None => md.path.is_none(),
};
if !ready {
return preview_spinner();
}
@@ -252,8 +248,8 @@ impl RepoDetailView {
}
/// Load `text` into the persistent code editor state for `path`.
///
/// Code editor mode makes the Input render it read-only and highlighted.
/// The tree-sitter parse runs on a background task like [`set_markdown`]'s.
pub(super) fn set_code(
&mut self,
path: SharedString,