dedukun / bookmarks.yazi

MIT License
43 stars 1 forks source link

Add Persistence #14

Closed dedukun closed 2 months ago

dedukun commented 2 months ago

closes #6 and #9

dedukun commented 2 months ago

Hey @sxyazi, can you take a look just to make sure that I'm using the pub_static correctly?

There's seems to be an issue, or maybe this is just how DDS is suppose to work, but this only saves to persistent memory if there's a different instance of Yazi also sub_remote the same time. If only the instance that is doing the pub_static is subbed it's not saving the data.

sxyazi commented 2 months ago

Sure, it sounds like a bug, I'll investigate it

sxyazi commented 2 months ago

Hi, I pushed a new commit, please give it a try

dedukun commented 2 months ago

Hey,

It still seems to need to have two a different instance of Yazi subbed

https://github.com/dedukun/bookmarks.yazi/assets/25795432/7099cbe0-4ff2-4324-8ed2-d9372bcf1c22

dedukun commented 2 months ago

Weird I tried now again and it seems to be working, I'll have a better look at it and do some more tests.

dedukun commented 2 months ago

Oh I had a hidden terminal with Yazi running, that's why it was working... :smile:

sxyazi commented 2 months ago

I pushed a new commit just now, please try it again

dedukun commented 2 months ago

Thanks @sxyazi , I think that it is working correctly now.

dedukun commented 2 months ago

Thanks, I updated to the last commit and it is working has you said.

Just a side note, I noticed that when running the jump, i.e.

ya.manager_emit("cd", { bookmarks[selected].desc })
ya.manager_emit("arrow", { -99999999 })
ya.manager_emit("arrow", { bookmarks[selected].cursor })

that sometimes the arrows don't do anything, I must run it twice to jump to the cursor. The manager_emit doesn't run in sync right? Maybe it does the arrow before finishing the cd?

This is not an issue in the last commit, I think that it was happening before.

dedukun commented 2 months ago

I'm not sure if this is even an issue, I can always listen to the cd DDS event and only do the arrow then.

sxyazi commented 2 months ago

The manager_emit doesn't run in sync right? Maybe it does the arrow before finishing the cd?

Yeah manager_emit is async, but it does ensure the order of commands.

I can always listen to the cd DDS event and only do the arrow then.

I'm not very sure I understand what you mean. If you cd into a new directory (that hasn't been loaded before), triggering arrow at this point won't do anything because until the directory is fully loaded (or partially loaded), there are no files in that directory. arrow will be ignored when executed on an empty directory.

If that's the issue, currently the only solution is to use loop + ya.sleep(). I'll add a utility function in the next target to better address it.

DreamMaoMao commented 2 months ago

Thanks, I updated to the last commit and it is working has you said.

Just a side note, I noticed that when running the jump, i.e.

ya.manager_emit("cd", { bookmarks[selected].desc })
ya.manager_emit("arrow", { -99999999 })
ya.manager_emit("arrow", { bookmarks[selected].cursor })

that sometimes the arrows don't do anything, I must run it twice to jump to the cursor. The manager_emit doesn't run in sync right? Maybe it does the arrow before finishing the cd?

This is not an issue in the last commit, I think that it was happening before.

You should not record cwd and cursor,

you just record the url of the file,

Then you can cd the url to jump to where you have record.

https://github.com/DreamMaoMao/bookmarks-persistence.yazi/blob/f974ea19282fcad57e21a0ec12bffcd4228da3ff/init.lua#L103

https://github.com/DreamMaoMao/bookmarks-persistence.yazi/blob/f974ea19282fcad57e21a0ec12bffcd4228da3ff/init.lua#L264

sxyazi commented 2 months ago

Ah yeah, that reminds me, you can just use the reveal command, it handles all that automatically, even if there aren't any files in the directory yet. It'll hover over the correct file once the directory files are loaded.

dedukun commented 2 months ago

I'm not very sure I understand what you mean. If you cd into a new directory (that hasn't been loaded before), triggering arrow at this point won't do anything because until the directory is fully loaded (or partially loaded), there are no files in that directory. arrow will be ignored when executed on an empty directory.

If that's the issue, currently the only solution is to use loop + ya.sleep(). I'll add a utility function in the next target to better address it.

Yes I think that's what was happening, I'll have a look at reveal has you said, I didn't know about that command.

dedukun commented 2 months ago

Thanks, I updated to the last commit and it is working has you said. Just a side note, I noticed that when running the jump, i.e.

ya.manager_emit("cd", { bookmarks[selected].desc })
ya.manager_emit("arrow", { -99999999 })
ya.manager_emit("arrow", { bookmarks[selected].cursor })

that sometimes the arrows don't do anything, I must run it twice to jump to the cursor. The manager_emit doesn't run in sync right? Maybe it does the arrow before finishing the cd? This is not an issue in the last commit, I think that it was happening before.

You should not record cwd and cursor,

you just record the url of the file,

Then you can cd the url to jump to where you have record.

https://github.com/DreamMaoMao/bookmarks-persistence.yazi/blob/f974ea19282fcad57e21a0ec12bffcd4228da3ff/init.lua#L103

https://github.com/DreamMaoMao/bookmarks-persistence.yazi/blob/f974ea19282fcad57e21a0ec12bffcd4228da3ff/init.lua#L264

Oh, I also didn't know that we could use cd like that. Thanks I'll also have a look at it.