Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not collapse empty lines in snippets #595

Merged
merged 2 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Aug-07 12h20: parser.rs, cases.cheat, writer.rs
  • Loading branch information
denisidoro committed Aug 7, 2021
commit ef6c01a17922b58fedf3e5805089eb2cbc08be7c
3 changes: 3 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ pub fn read_lines(
if !item.tags.is_empty() && !item.comment.is_empty() {}
// blank
if line.is_empty() {
if !(&item.snippet).is_empty() {
item.snippet.push_str(writer::LINE_SEPARATOR);
}
}
// tag
else if line.starts_with('%') {
Expand Down
2 changes: 1 addition & 1 deletion src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn write(item: &Item) -> String {
tags = item.tags,
comment = item.comment,
delimiter = DELIMITER,
snippet = &item.snippet,
snippet = &item.snippet.trim_end_matches(LINE_SEPARATOR),
file_index = item.file_index,
)
}
2 changes: 1 addition & 1 deletion tests/no_prompt_cheats/cases.cheat
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo lorem ipsum
echo lorem ipsum
echo baz

# empty line -> "foo\n\n\n\nbar"
# empty line -> "foo\n\n\nbar"
echo "$(cat <<EOF
foo

Expand Down
1 change: 0 additions & 1 deletion tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ for i in $(_get_tests "$filter"); do
IFS="$ifs"
query="$(echo "$i" | cut -d'|' -f1)"
expected="$(echo "$i" | tr "$NEWLINE_CHAR" '\n' | cut -d'|' -f2)"
echoerr "expected: $i"
test::run "$query" _navi_cases_test "$query" "$expected"
done

Expand Down