Skip to content

Commit

Permalink
fix: tabs would not be rendered, render them as 4 spaces for now
Browse files Browse the repository at this point in the history
closes: #201
  • Loading branch information
altsem committed Jun 19, 2024
1 parent d6bb33c commit eccb097
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn format_diff_hunk_items(depth: usize, hunk: Rc<Hunk>) -> Vec<Item> {
.iter()
.enumerate()
.map(|(i, line)| Item {
display: line.clone(),
display: replace_tabs_with_spaces(line.clone()),
unselectable: line
.spans
.first()
Expand All @@ -112,6 +112,17 @@ fn format_diff_hunk_items(depth: usize, hunk: Rc<Hunk>) -> Vec<Item> {
.collect()
}

fn replace_tabs_with_spaces(line: Line<'_>) -> Line<'_> {
let spans = line
.spans
.iter()
.cloned()
.map(|span| Span::styled(span.content.replace('\t', " "), span.style))
.collect::<Vec<_>>();

Line { spans, ..line }
}

pub(crate) fn stash_list(config: &Config, repo: &Repository, limit: usize) -> Res<Vec<Item>> {
let style = &config.style;

Expand Down
12 changes: 12 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,15 @@ fn crlf_diff() {

insta::assert_snapshot!(ctx.redact_buffer());
}

#[test]
fn tab_diff() {
let mut ctx = TestContext::setup_init();
let mut state = ctx.init_state();

commit(ctx.dir.path(), "tab.txt", "this has no tab prefixed\n");
fs::write(ctx.dir.child("tab.txt"), "\tthis has a tab prefixed\n").unwrap();
state.update(&mut ctx.term, &keys("g")).unwrap();

insta::assert_snapshot!(ctx.redact_buffer());
}
25 changes: 25 additions & 0 deletions src/tests/snapshots/gitu__tests__tab_diff.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/mod.rs
expression: ctx.redact_buffer()
---
On branch main |
|
Unstaged changes (1) |
modified tab.txt |
@@ -1 +1 @@ |
-this has no tab prefixed |
+ this has a tab prefixed |
|
Recent commits |
_______ main add tab.txt |
|
|
|
|
|
|
|
|
|
|
styles_hash: 4c33c9d79050f1a0

0 comments on commit eccb097

Please sign in to comment.