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

Edit in external editor #749

Closed
gerroon opened this issue Dec 5, 2019 · 16 comments
Closed

Edit in external editor #749

gerroon opened this issue Dec 5, 2019 · 16 comments

Comments

@gerroon
Copy link

gerroon commented Dec 5, 2019

Hi

I think that being able to edit the current note in an external editor can be very useful especially for Markdown since the Trilium does not render .md at all beside showing it as text.

Joplin provides this functionality, Ctr-E opens the text in an external editor of choice, and the content is updated when the user saves the page in that editor.

Trying to edit a file externally and bringing it back is quite a bit of involved atm.

thanks

@zadam
Copy link
Owner

zadam commented Dec 5, 2019

Hmm, that would be very useful also for file attachments (e.g. word documents etc.)

@gerroon
Copy link
Author

gerroon commented Dec 5, 2019

I did not think about the attachments, that is a really good point too.

@nil0x42
Copy link
Contributor

nil0x42 commented Dec 6, 2019

for the code notes it would be soooo practical !

It would even be relatively simple to implement (at least on linux):

  1. You press let's say Ctrl+Shift+E to edit current note.
  2. Trilium creates a tmpfile containing note's content, then opens it with user's favorite editor.
  3. as soon as the editor is closed, the note is rewritten with tmpfile's current content.
  4. tmpfile is removed

I have a shortcut on my system which opens clipboard buffer in vim to edit it before pasting it somewhere, so from now i use it to edit most of my code notes, but it's less efficient, because i need to:

  1. selected all note's content (Ctrl+A)
  2. copy (Ctrl+C)
  3. press my custom shortcut to open clipboard in vim
  4. edit the file
  5. delete note content
  6. press Ctrl+V (paste) to write my vim-edited clipboard content

@zadam
Copy link
Owner

zadam commented Dec 6, 2019

as soon as the editor is closed, the note is rewritten with tmpfile's current content.

This is the hard part - it is possible to know when the editor is closed when the editor is spawned as a new process from trilium. But in many use cases it would make more sense to open it in an existing process (e.g. new tab in VS Code). Also to spawn it as a process the trilium would have to know exact command to run, I don't think it's possible to use the native OS application selection dialog ...

@gerroon
Copy link
Author

gerroon commented Dec 6, 2019

Why not take a look at Joplin's code to see how they did it there? It works great with it. I realize that Joplin is a flatfile system but still it might be helpful. It is an Electron app too, so maybe the code can be used easily.

I use that functionality in Joplin on WIndows and Linux, and I have not met a glitch with it. It also does not block Joplin during that time.

@nil0x42
Copy link
Contributor

nil0x42 commented Dec 6, 2019

But in many use cases it would make more sense to open it in an existing process (e.g. new tab in VS Code).

My knowledge of windows internals is very bad. But for linux at least you can list processes having an active file descriptor to a file (lsof command). So a solution might be to wait until the file is not anymore open by a process

But really it's harder to realiably implement.

@chncho
Copy link

chncho commented Dec 28, 2019

Hope can be integrated the editor (https://github.com/nhn/tui.editor), feel it is a more modern editor, user experience is very good, support for markdown is better, and supports uml syntax, etc.

@JohnWang1023
Copy link

Hope can be integrated the editor (https://github.com/nhn/tui.editor), feel it is a more modern editor, user experience is very good, support for markdown is better, and supports uml syntax, etc.

Or https://github.com/pandao/editor.md

@popey456963 popey456963 changed the title FR: Edit in external editor Edit in external editor May 7, 2020
@danielandastro
Copy link

This would be useful, I personally have an entire year of notes made in Typora (uses github flavoured markdown) and I can't really refer to / edit them in trillium, being able to open them in Typora would help

@agentydragon
Copy link
Sponsor Contributor

I'm currently editing a note with a large LaTeX display equation. Currently LaTeX is only edited in a single-line textbox:
image
This is too small for how long that equation that I wanna type is. Opening in an external program would be one way to work around this.

@abitofevrything
Copy link
Contributor

There is a related issue on the upstream library used for math that you can look at: isaul32/ckeditor5-math#10

@zadam
Copy link
Owner

zadam commented Aug 15, 2021

Closing as this feature has been added in 0.47 IIRC:

image

@zadam zadam closed this as completed Aug 15, 2021
@agentydragon
Copy link
Sponsor Contributor

Closing as this feature has been added in 0.47 IIRC:

image

For me, this opens the note in the web browser. Is there some way to change which program should handle it?

@zadam
Copy link
Owner

zadam commented Aug 20, 2021

Opening in the web browser is the fallback in cases no application is associated with this file type in the OS.

@agentydragon
Copy link
Sponsor Contributor

I see. And for HTML files (which seems to be the type for text notes), I might even just have the browser associated. So I'll try associating an editor with HTML files and see if it helps.

I suspect people other than me might be hitting this issue, though. Having the browser associated with HTML is probably a common setting, but browsers aren't useful for editing. So it might still be useful to allow the user to open in an alternative program other than the associated one - like an editor.

@zadam
Copy link
Owner

zadam commented Aug 20, 2021

Yes, I agree but I'm not sure if it's possible to show/choose application to open with in electron.

Electron API always seems to use the default associated application: https://www.electronjs.org/docs/api/shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants