Persist the default Git diff layout

This commit is contained in:
Georg Bauer
2026-07-28 19:07:59 +02:00
parent 07c89094b4
commit 191ff0b2ce
7 changed files with 64 additions and 21 deletions

View File

@@ -8,14 +8,15 @@ mod view;
pub(crate) use view::app_theme;
use generation::ChatMessage;
use git::{ActiveGitOperation, GitDiff, GitDiffMode, GitWorktree};
use git::{ActiveGitOperation, GitDiff, GitWorktree};
use model_manager::{ActiveDownload, ModelDownload, ModelOperation};
use preferences::PreferenceDraft;
#[cfg(test)]
use preferences::{parse_optional_gib, parse_streaming_cache};
use crate::config::{
Config, DevBrainConfig, EndpointConfig, GitConfig, GitDiffAlgorithm, GitDiffWhitespace,
Config, DevBrainConfig, EndpointConfig, GitConfig, GitDiffAlgorithm, GitDiffLayout,
GitDiffWhitespace,
};
use crate::database::{Database, ProjectWithSessions, SessionState, StoredMessage};
#[cfg(target_os = "macos")]
@@ -77,7 +78,7 @@ pub(crate) struct App {
git_selected_files: HashSet<PathBuf>,
git_commit_message: String,
git_diff: Option<GitDiff>,
git_diff_mode: GitDiffMode,
git_diff_layout: GitDiffLayout,
git_commit_all_confirmation: bool,
git_operation: Option<ActiveGitOperation>,
last_git_scan: Instant,
@@ -350,6 +351,7 @@ pub(crate) enum Message {
PreferenceEndpointCorsChanged(bool),
PreferenceDevBrainEnabledChanged(bool),
PreferenceDevBrainVaultChanged(String),
PreferenceGitDiffLayoutChanged(GitDiffLayout),
PreferenceGitDiffAlgorithmChanged(GitDiffAlgorithm),
PreferenceGitContextLinesChanged(String),
PreferenceGitInterhunkLinesChanged(String),
@@ -437,7 +439,7 @@ pub(crate) enum Message {
SwitchGitBranch(String),
ToggleGitFile(PathBuf),
OpenGitDiff(PathBuf),
SetGitDiffMode(GitDiffMode),
SetGitDiffLayout(GitDiffLayout),
GitDiffScrolled(scrollable::Viewport),
GitCommitMessageChanged(String),
GitStageSelected,
@@ -503,6 +505,7 @@ impl App {
let metrics =
Arc::new(Metrics::new(&application_support_path().join("kv-cache")));
let metrics_snapshot = metrics.snapshot();
let git_diff_layout = config.git.diff_layout;
#[cfg(target_os = "macos")]
let (runtime_config, generation_service, endpoint, service_error) =
spawn_services(&config, Arc::clone(&metrics));
@@ -532,7 +535,7 @@ impl App {
git_selected_files: HashSet::new(),
git_commit_message: String::new(),
git_diff: None,
git_diff_mode: GitDiffMode::default(),
git_diff_layout,
git_commit_all_confirmation: false,
git_operation: None,
last_git_scan: Instant::now() - GIT_SCAN_INTERVAL,
@@ -641,6 +644,7 @@ impl App {
let context_limit = config.generation.context_tokens.max(0) as u32;
let metrics = Arc::new(Metrics::new(&application_support_path().join("kv-cache")));
let metrics_snapshot = metrics.snapshot();
let git_diff_layout = config.git.diff_layout;
#[cfg(target_os = "macos")]
let (runtime_config, generation_service, endpoint, service_error) =
spawn_services(&config, Arc::clone(&metrics));
@@ -674,7 +678,7 @@ impl App {
git_selected_files: HashSet::new(),
git_commit_message: String::new(),
git_diff: None,
git_diff_mode: GitDiffMode::default(),
git_diff_layout,
git_commit_all_confirmation: false,
git_operation: None,
last_git_scan: Instant::now() - GIT_SCAN_INTERVAL,
@@ -1187,6 +1191,10 @@ impl App {
self.preference_draft.dev_brain_vault_path = value;
self.preference_error = None;
}
Message::PreferenceGitDiffLayoutChanged(layout) => {
self.preference_draft.git_diff_layout = layout;
self.preference_error = None;
}
Message::PreferenceGitDiffAlgorithmChanged(algorithm) => {
self.preference_draft.git_diff_algorithm = algorithm;
self.preference_error = None;
@@ -1798,7 +1806,7 @@ impl App {
Message::SwitchGitBranch(branch) => self.switch_git_branch(&branch),
Message::ToggleGitFile(path) => self.toggle_git_file(path),
Message::OpenGitDiff(path) => self.open_git_diff(&path),
Message::SetGitDiffMode(mode) => self.git_diff_mode = mode,
Message::SetGitDiffLayout(layout) => self.git_diff_layout = layout,
Message::GitDiffScrolled(viewport) => {
let offset = scrollable::AbsoluteOffset {
x: viewport.absolute_offset().x,