summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-04-20 16:27:55 +0200
committerOskar <[email protected]>2024-04-20 16:27:55 +0200
commitb3d8be14e12aca5993925c156da5eb76af88e665 (patch)
tree0e9f01bcce336ebdc6b53575f2e1d082a69313d3
parenta5b0a8dd423fd15d133645987f21a3e87f5fa606 (diff)
Fixed issue where files with no lines dont work properly with 'N'
-rw-r--r--TODO2
-rw-r--r--editmode.c8
-rwxr-xr-xtest/nl.sh2
3 files changed, 10 insertions, 2 deletions
diff --git a/TODO b/TODO
index 1290cca..36ab87d 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
TODO list. This is mostly so i can plan more granularly and remember small stuff i was working on last time and what i should prioritise first.
This is not my overall big planning board. (1 highest prio, 10 lowest)
-1 - remove_line_contents more efficient. Maybe allow specifying amount of lines to add so we dont need to call the function too many times.
+1 - Make remove_line_contents more efficient. Maybe allow specifying amount of lines to add so we dont need to call the function too many times.
diff --git a/editmode.c b/editmode.c
index b5aa770..14485d3 100644
--- a/editmode.c
+++ b/editmode.c
@@ -178,7 +178,13 @@ int new_line(char filename[], long long new_line_pos_temp, uint64_t amount_of_li
fputc('\n', file);
fputc('\n', file);
fclose(file);
- return 0;
+
+ if(amount_of_lines == 1) {
+ return 0;
+ }
+ if(amount_of_lines > 1) {
+ amount_of_lines = amount_of_lines-1;
+ }
}
}
diff --git a/test/nl.sh b/test/nl.sh
index 9d3d0cb..d064504 100755
--- a/test/nl.sh
+++ b/test/nl.sh
@@ -1,5 +1,7 @@
#!/bin/bash
+#Regen 'newlinetest' file so i dont have to manually repair it to its original state
+
filename="testgrounds/newlinetest"
rm -f $filename