Skip to content

Commit

Permalink
Fix searchable text containing new lines (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
goyalmunish authored Apr 16, 2022
1 parent 9cb14a4 commit 14dd394
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ func TestSearchableText(t *testing.T) {
note = model.Note{Text: "a cute dog", Comments: comments}
got = note.SearchableText()
utils.AssertEqual(t, got, "| incidental | | a cute dog [no-comments]")
// case 4
comments = model.Comments{}
note = model.Note{Text: "first line\nsecondline\nthird line", Comments: comments}
got = note.SearchableText()
utils.AssertEqual(t, got, "| incidental | | first line NWL secondline NWL third line [no-comments]")
}

func TestExternalTexts(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion internal/model/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ func (note *Note) SearchableText() string {
searchableText = append(searchableText, note.Text)
searchableText = append(searchableText, note.Summary)
searchableText = append(searchableText, strings.Join(commentsText, ""))
// form a single string
text := strings.Join(searchableText, " ")
// address some special characters
text = strings.ReplaceAll(text, "\n", " NWL ")
// return searchable text for note a string
return strings.Join(searchableText, " ")
return text
}

// AddComment adds a new comment to note.
Expand Down

0 comments on commit 14dd394

Please sign in to comment.