Skip to content

Commit 95d1731

Browse files
committed
Fix off by one error when getting matched line number
The note parser extracts the note starting line number which includes the note title. When getting the matched line number on gathering context it will recount the title line again as that's its line 1. The Note 'Content' property will now always include the title line becauese if a note has a markdown title it would be excluded from the content but if there isn't a markdown title, the title of the note will be the first line of the main text which means when calculating the line number we won't know if the title was included or not, so make the behaviour consistent.
1 parent 6434acb commit 95d1731

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

notebook/notebook.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (book *Notebook) SearchRelated(id uint64) []Result {
160160
for _, context := range contexts {
161161
result := Result{
162162
Context: context.Text,
163-
Line: startLine + context.Line,
163+
Line: startLine + context.Line - 1,
164164
Value: vertex,
165165
}
166166
results = append(results, result)
@@ -210,7 +210,7 @@ func (book *Notebook) SearchByTags(searchTags ...string) []Result {
210210
for _, context := range context {
211211
result := Result{
212212
Context: context.Text,
213-
Line: startLine + context.Line,
213+
Line: startLine + context.Line - 1,
214214
Value: vertex,
215215
}
216216
results = append(results, result)

notebook/search.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (book *Notebook) Search(query ...string) []Result {
1616
startLine := 0
1717
switch val := vertex.Properties["Value"].(type) {
1818
case parser.Note:
19-
content := val.Title + "\n\n" + val.Content
19+
content := val.Content
2020
paragraphs := extractParagraphs(content)
2121
startLine = val.Start
2222
PARAGRAPH:
@@ -51,7 +51,7 @@ func (book *Notebook) Search(query ...string) []Result {
5151
for _, context := range context {
5252
result := Result{
5353
Context: context.Text,
54-
Line: startLine + context.Line,
54+
Line: startLine + context.Line - 1,
5555
Value: vertex,
5656
}
5757
results = append(results, result)

parser/parser.go

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func Parse(filepath string) []Note {
7878
title = line
7979
if strings.HasPrefix(line, "# ") {
8080
title = line[2:]
81-
continue
8281
}
8382
content += fmt.Sprintln(line)
8483
}

0 commit comments

Comments
 (0)