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

interactive filtering results in Found 0 note #331

Closed
khimaros opened this issue Jun 6, 2023 · 3 comments · Fixed by #339
Closed

interactive filtering results in Found 0 note #331

khimaros opened this issue Jun 6, 2023 · 3 comments · Fixed by #339
Labels
bug Something isn't working

Comments

@khimaros
Copy link
Contributor

khimaros commented Jun 6, 2023

i traced the issue down to fzf.parseSelection()

the call to stringsutil.SplitLines() returns an empty array, despite the output parameter containing many bytes.

2023/06/06 16:23:39 fzf len(output): 153396
2023/06/06 16:23:39 fzf lines: []
Found 0 note

reproduction

when i zk edit -i -m <name> it shows up as the top result

when i press enter to select the note, it says Found 0 note

the same outcome when using zk list -i

this file i'm attempting to open is 153,335 bytes large

notes

editing the note with zk edit -m "<name>" -n 1 works fine

editing the note by name zk edit <name> works fine

the problem appears to be restricted to fzf integration

@khimaros
Copy link
Contributor Author

khimaros commented Jun 7, 2023

i believe the issue will occur with any document larger than bufio.MaxScanTokenSize https://pkg.go.dev/bufio#pkg-constants

for files with content beyond this limit, stringsutil.SplitLines() never finds the newline after the filename, which means the loop in fzf.parseSelection() is never entered.

@khimaros
Copy link
Contributor Author

khimaros commented Jun 7, 2023

this patch solves the problem for me.

for files which are larger than 2MB, shows an error to the user. i'm not sure using 2MB for every string split makes sense, but the error checking code at least i think should be incorporated:

diff --git a/internal/util/strings/strings.go b/internal/util/strings/strings.go
index be5f406..4db54c4 100644
--- a/internal/util/strings/strings.go
+++ b/internal/util/strings/strings.go
@@ -2,6 +2,7 @@ package strings
 
 import (
        "bufio"
+       "log"
        "net/url"
        "regexp"
        "strconv"
@@ -37,9 +38,15 @@ func Pluralize(word string, count int) string {
 func SplitLines(s string) []string {
        var lines []string
        scanner := bufio.NewScanner(strings.NewReader(s))
+       // increase the buffer size to 2Mb
+       buf := []byte{}
+       scanner.Buffer(buf, 2048*1024)
        for scanner.Scan() {
                lines = append(lines, scanner.Text())
        }
+       if err := scanner.Err(); err != nil {
+               log.Fatalf("error while scanning text: %v", err)
+       }
        return lines
 }

@mickael-menu
Copy link
Member

Thanks @khimaros, feel free to open a PR with your patch.

@github-actions github-actions bot added the stale No recent activity label Jul 25, 2023
@zk-org zk-org deleted a comment from github-actions bot Jul 25, 2023
@mickael-menu mickael-menu added bug Something isn't working and removed stale No recent activity labels Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants