zk-org / zk-nvim

Neovim extension for zk
https://github.com/zk-org/zk
GNU General Public License v3.0
530 stars 42 forks source link

fix tag name selection in fzf #57

Closed idevat closed 2 years ago

idevat commented 2 years ago

In tag list in fzf the line format is notes_count delimiter tag_name (e. g. 3 sometag). Incorrect regexp is used for parsing tag name from the selected line. It causes that the selected tag is empty and notes are not filtered by tag in the following notes list. This pull request should fix it.

mickael-menu commented 2 years ago

Hi @idevat, thanks for submitting this PR.

How can I reproduce this error exactly? It works fine for me with my tags and fzf. Do you have a sample of a note with a problematic tag?

idevat commented 2 years ago

For me, it is reproducible with this zk files:

$ cat eszc.md 
---
tags:
  - tag1
  - tag3
---
# Test2
cat gv7g.md 
---
tags:
  - tag1
  - tag2
---
# Test1

When I run :ZkTags I get tags selector (where the number on the beginning of the line is count of notes for tag):

   1   tag3
>  1   tag2
   2   tag1
   Zk Tags
   3/3 (0)
>

and when I select tag2 I get both notes:

   Test2
 > Test1
   Zk Notes for tag(s) {}
   2/2 (0)

but I should get only Test1.

When I inspected it a bit, I found that the tag name is not correctly extracted from line:

> print(string.match("1   "..delimiter.."tag2", "([^" .. delimiter .. "]+)", 2))
...nothing...

I also found out that my patch is wrong and I updated it. My specific case was corrected only by accident and this reproducer showed it. Sorry for that, I'm less than beginner with lua.