boltex / leojs

Leo Literate Editor with Outline in Typescript
MIT License
22 stars 0 forks source link

CTRL-CLicking A file:/// URL should open with correct file handler #143

Open tbpassin opened 1 week ago

tbpassin commented 1 week ago

I have a file:/// url to a .pdf file in the body of an outline. The .pdf file is on my computer. When I CTRL-click on it, LeoJS tries to open it in VSC, but VSC does not know how to open it.

LeoPy sends it to the browser. I don't know if it specifically uses the browser or the system-specified program for .pdf files.

IMO, LeoJS should open obvious text files as text, and binary or uncertain files with an appropriate handler. LeoJS does send http: urls to the browser as it should.

ISTR that LeoPy can properly dispatch file: urls that have relative paths. I haven't checked that with LeoJS, but I assume that the JS handling code is equivalent to leoPy's. if not it should be.

tbpassin commented 1 week ago

UPDATE - I just found and installed the VSC extension "vscode-pdf". This does allow a CTRL-Click on a .pdf file:URL to display the file in VSC.

This solves the issue for .pdf files. The underlying issue remains, though - if VSC doesn't know how to open a file type, it should try to delegate to the system's handler when that exists.

boltex commented 1 week ago

@tbpassin Thanks for this noticing this! I'll see what the 'url detection' code I had in place can do for regular urls other than Leo's UNL (such as file:///some_folder/some_file.txt )

boltex commented 1 week ago

@tbpassin Thanks again for this great feature suggestion!

I've given it some thought: I'll first check if there's a feature (or at least create a vscode issue if not) in vscode to signify to vscode that a binary file link should be opened with the default OS system handler for such binary file, (on a per-extension basis, with a customizable list in the options settings), instead of trying to be opened by vscode itself.

Therefore I'm considering closing this 'LeoJS' issue to instead open a 'VSCode' issue, inquiring about implementing this very same concept...

To be clear, I'm not thinking about closing this issue because it's a bad idea, to the contrary, it's such an obvious 'nice-to-have' concept that I think it should be a VSCode feature in itself.

I'll leave this issue opened for a while in the meantime, and will take a decision about closing or implementing this later.

tbpassin commented 1 week ago

If VSC will let you call the OS, for example equivalent to Python's os.system() or POpen.run(), you can roll your own if VSC hasn't got one built in.

This link might be what's needed: https://code.visualstudio.com/docs/terminal/shell-integration

boltex commented 1 week ago

@tbpassin Thanks, but these features (Have the underlying OS launch external files) were already covered with run-command, execute-general-script and execute-external-file which were implemented in the latest release. They are also demoed in the sample scripts at https://github.com/boltex/scripting-samples-leojs .

Thanks again for bringing my attention to this lacking feature: opening file links with default app instead of opening it in the vscode editor, I have decided to implement it in LeoJS. (for 1.0.1)

Note: After doing a little research, I've found that it is a feature that other people have asked in general for VSCode -> https://stackoverflow.com/questions/63224768/visual-studio-code-how-to-make-local-file-link-open-default-program?rq=3