gatziourasd / typora-tabbar-plugin

Unofficial plugin that adds a tabbar to Typora
62 stars 4 forks source link

Is it possible to open link to new tab #6

Closed caiyunlin closed 1 year ago

caiyunlin commented 2 years ago

e.g. I have two documents

index.md
[chapter1.md](chapter1.md)

chapter1.md
chapter1content

when I use Ctrl+click to open [chapter1.md] link, it will open a new instance of Typora to open that document, is it possible to open it on a new tab? thanks a lot.

gatziourasd commented 2 years ago

Files now open in new tabs when Ctrl+Click on a link.

File links must have a supported file extension (".md", ".markdown", ".mmd", ".text", ".txt", ".mdown", ".mdwn", ".apib"). File links without extension will still open in a new window!

I haven't had the time to really test it yet. That is why its marked as pre-release. Download v0.4.2 (Pre-release)

You can install it by replacing the tabbar folder in %userprofile%/AppData/Roaming/Typora/plugins/ with the new one.

caiyunlin commented 2 years ago

Hi @gatziourasd , thank you very much for the quick implementation. I have tested the new version, a small issue, when I open the new Typora instance, I can't open "chapter1.md" link from the index.md file, but after I open the "chapter1.md" file manually on the tab, and close it, then I can open it from link of index.md, thanks.

caiyunlin commented 2 years ago

I think I found the pattern, kindly create below files for testing, thanks.

index.md
[chapter1.md](chapter1.md)                  # This one is work, since chapter1.md and index1.md at same folder
[chapters/chapter1.md](chapters/chapter1.md)         # This one is not work, unless I expand chapters folder firstly on left panel

chapter1.md
This is index.chapter1.md

chapters/chapter1.md
This is chapters/chapter1.md
caiyunlin commented 2 years ago

I looked at the code, it seems openFile query the filename div, but if I didn't expand the folder, the querySelector can't get the div and trigger click().

export function openFile(path) {
  fileLibrary
    .querySelector(
      `[data-path=\"${path.replace(/\\/gm, "\\\\")}\"] > div.file-node-content`
    )
    ?.click();
}
gatziourasd commented 2 years ago

Oh yeah, I remember now. File node children are only created when expanding the folders (no need to open the files). You may have also noticed that tabs remain open even if you delete, rename or move the corresponding file. That is also a side effect of this same behavior, because there is no way to accurately observe the state of files. Originally, I wanted the application to be as streamlined and simple as possible, to prevent it from breaking in future updates. I also thought we would get native tab support anyway in a couple of months, which sadly doesn’t seem to be the case. The way the application works right now is by simply analyzing the Interface and interacting with it the same way a human would do.

The bad news is, implementing this feature correctly (and many others) means changing the entire underlying architecture and basically rewrite the whole thing. This time using a more tightly integrated approach and reverse engineering Typora more. The good news is, it’s a very small program so it can probably be done in 2-3 hours. But I first have to test what the best strategy would be.

On the other hand, I am not sure if I will stick with Typora as my main notetaking app. Since the beta ended there wasn’t really any notable progress and Typora remains pretty buggy (Also reading Typora’s source code reveals a lot of messy code). Another Idea would be to create a more flexible plugin system other developers can use to fix these problems. But that would also be a lot of work, and with other projects like milkdown.dev which offer, in my opinion, a more robust and open experience I don’t know if it’s worth the effort.

caiyunlin commented 2 years ago

Thanks @gatziourasd , I totally understand, no need to change the architecture. I can manually open the folder as a workaround :)

caiyunlin commented 1 year ago

Thanks for the help, closing the issue.