aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-10-16 06:05:26 -0400
committerBrad Lewis <22850972+BradLewis@users.noreply.github.com>2025-10-16 06:05:26 -0400
commit70818f746ce29a429c4bd2302abc0a026ee1e93d (patch)
tree717a0c0f40a95697e8605b451f0fc50dbd904582 /src/common
parent5c2f9e18eda3421d252be59c734e34651c885faf (diff)
Fix issue calculating the absolute range with a file starting with a new line
Diffstat (limited to 'src/common')
-rw-r--r--src/common/position.odin6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/common/position.odin b/src/common/position.odin
index 4d01f58..2ea9e20 100644
--- a/src/common/position.odin
+++ b/src/common/position.odin
@@ -159,6 +159,10 @@ get_absolute_range :: proc(range: Range, document_text: []u8) -> (AbsoluteRange,
line_count := 0
index := 1
last := document_text[0]
+ if last == '\n' {
+ // if we start with a new line, we set the index back to 0 to ensure it gets accounted for
+ index = 0
+ }
if !get_index_at_line(&index, &line_count, &last, document_text, range.start.line) {
return absolute, false
@@ -168,7 +172,7 @@ get_absolute_range :: proc(range: Range, document_text: []u8) -> (AbsoluteRange,
//if the last line was indexed at zero we have to move it back to index 1.
//This happens when line = 0
- if index == 0 {
+ if index == 0 && last != '\n' {
index = 1
}