Persist the default Git diff layout
This commit is contained in:
@@ -40,13 +40,6 @@ pub(super) struct GitWorktree {
|
||||
pub(super) files: Vec<GitFile>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub(crate) enum GitDiffMode {
|
||||
#[default]
|
||||
Unified,
|
||||
Split,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(super) enum GitDiffLineKind {
|
||||
Section,
|
||||
@@ -186,6 +179,7 @@ impl App {
|
||||
match load_diff(&worktree.root, file, &self.config.git) {
|
||||
Ok(diff) => {
|
||||
self.git_diff = Some(diff);
|
||||
self.git_diff_layout = self.config.git.diff_layout;
|
||||
self.error = None;
|
||||
}
|
||||
Err(error) => self.error = Some(error),
|
||||
@@ -1113,6 +1107,7 @@ mod tests {
|
||||
.find(|file| file.display_path == "changed.txt")
|
||||
.unwrap();
|
||||
let settings = GitConfig {
|
||||
diff_layout: GitDiffLayout::Unified,
|
||||
diff_algorithm: GitDiffAlgorithm::Patience,
|
||||
context_lines: 0,
|
||||
interhunk_lines: 0,
|
||||
|
||||
@@ -12,6 +12,7 @@ pub(super) struct PreferenceDraft {
|
||||
pub(super) endpoint_cors: bool,
|
||||
pub(super) dev_brain_enabled: bool,
|
||||
pub(super) dev_brain_vault_path: String,
|
||||
pub(super) git_diff_layout: GitDiffLayout,
|
||||
pub(super) git_diff_algorithm: GitDiffAlgorithm,
|
||||
pub(super) git_context_lines: String,
|
||||
pub(super) git_interhunk_lines: String,
|
||||
@@ -70,6 +71,7 @@ impl PreferenceDraft {
|
||||
endpoint_cors: config.endpoint.cors,
|
||||
dev_brain_enabled: config.dev_brain.enabled,
|
||||
dev_brain_vault_path: config.dev_brain.vault_path.clone().unwrap_or_default(),
|
||||
git_diff_layout: config.git.diff_layout,
|
||||
git_diff_algorithm: config.git.diff_algorithm,
|
||||
git_context_lines: config.git.context_lines.to_string(),
|
||||
git_interhunk_lines: config.git.interhunk_lines.to_string(),
|
||||
@@ -140,6 +142,7 @@ impl PreferenceDraft {
|
||||
|
||||
pub(super) fn git(&self) -> Result<GitConfig, String> {
|
||||
Ok(GitConfig {
|
||||
diff_layout: self.git_diff_layout,
|
||||
diff_algorithm: self.git_diff_algorithm,
|
||||
context_lines: parse_u32("Git diff context lines", &self.git_context_lines)?,
|
||||
interhunk_lines: parse_u32("Git diff interhunk lines", &self.git_interhunk_lines)?,
|
||||
|
||||
@@ -12,7 +12,7 @@ use super::{
|
||||
ModelDownload, ModelOperation, PreferenceSection, ProjectChoice, chat_scroll_id, composer_id,
|
||||
models_path, preferences_scroll_id,
|
||||
};
|
||||
use crate::config::{GIT_DIFF_ALGORITHMS, GIT_DIFF_WHITESPACE_MODES};
|
||||
use crate::config::{GIT_DIFF_ALGORITHMS, GIT_DIFF_LAYOUTS, GIT_DIFF_WHITESPACE_MODES};
|
||||
use crate::database::{ProjectWithSessions, Session, SessionState};
|
||||
use crate::model::{
|
||||
self, DownloadPhase, MODEL_CHOICES, ManagedArtifact, ManagedArtifactState, ModelChoice,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::*;
|
||||
use crate::app::git::{GitChangeKind, GitDiffLine, GitDiffLineKind, GitDiffMode, GitDiffRow};
|
||||
use crate::app::git::{GitChangeKind, GitDiffLine, GitDiffLineKind, GitDiffRow};
|
||||
use crate::app::{git_diff_new_scroll_id, git_diff_old_scroll_id};
|
||||
use crate::config::GitDiffLayout;
|
||||
use iced::widget::column;
|
||||
|
||||
impl App {
|
||||
@@ -230,13 +231,13 @@ impl App {
|
||||
|
||||
pub(super) fn git_diff_panel(&self) -> Element<'_, Message> {
|
||||
let diff = self.git_diff.as_ref().unwrap();
|
||||
let unified_active = self.git_diff_mode == GitDiffMode::Unified;
|
||||
let split_active = self.git_diff_mode == GitDiffMode::Split;
|
||||
let unified_active = self.git_diff_layout == GitDiffLayout::Unified;
|
||||
let split_active = self.git_diff_layout == GitDiffLayout::Split;
|
||||
let mode = container(
|
||||
row![
|
||||
button(text("1 column").size(12))
|
||||
.padding([4, 10])
|
||||
.on_press(Message::SetGitDiffMode(GitDiffMode::Unified))
|
||||
.on_press(Message::SetGitDiffLayout(GitDiffLayout::Unified))
|
||||
.style(move |theme, status| segmented_button_style(
|
||||
theme,
|
||||
status,
|
||||
@@ -244,7 +245,7 @@ impl App {
|
||||
)),
|
||||
button(text("2 columns").size(12))
|
||||
.padding([4, 10])
|
||||
.on_press(Message::SetGitDiffMode(GitDiffMode::Split))
|
||||
.on_press(Message::SetGitDiffLayout(GitDiffLayout::Split))
|
||||
.style(move |theme, status| segmented_button_style(
|
||||
theme,
|
||||
status,
|
||||
|
||||
@@ -199,6 +199,20 @@ impl App {
|
||||
PreferenceSection::Git,
|
||||
"GIT DIFFS",
|
||||
column![
|
||||
row![
|
||||
hint(
|
||||
text("Default layout").size(13).width(Length::Fill),
|
||||
"Layout used whenever a file diff is opened. The control in the diff can still change that one view.",
|
||||
),
|
||||
pick_list(
|
||||
&GIT_DIFF_LAYOUTS[..],
|
||||
Some(self.preference_draft.git_diff_layout),
|
||||
Message::PreferenceGitDiffLayoutChanged,
|
||||
)
|
||||
.width(240),
|
||||
]
|
||||
.spacing(12)
|
||||
.align_y(Alignment::Center),
|
||||
row![
|
||||
hint(
|
||||
text("Algorithm").size(13).width(Length::Fill),
|
||||
|
||||
Reference in New Issue
Block a user