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

Add plugin previewer #459

Merged
merged 3 commits into from
Jan 6, 2025
Merged

Add plugin previewer #459

merged 3 commits into from
Jan 6, 2025

Conversation

Mandarancio
Copy link
Contributor

Simple plugin that allow to preview file and buffers before before opening them.

@Guldoman
Copy link
Member

Mmmh as it is, this plugin is a bit problematic as it overrides the CommandView in every case, so it'll try previewing anything the CommandView is showing.
It even causes a crash in some cases, for example when trying to create a new file from the context menu of the TreeView (only if you try doing that with one of the first directories for some reason).

A better solution would be to provide your own function to open files. I think it could use suggest directly to change files.
You could also provide a wrapper function that will have to be passed to suggest, for people/plugins that want to integrate your preview.

As a note, you don't really need to specify . as path in the manifest.

@Mandarancio
Copy link
Contributor Author

Mandarancio commented Jul 19, 2024 via email

@Mandarancio Mandarancio marked this pull request as draft July 22, 2024 07:42
@Mandarancio
Copy link
Contributor Author

Mmmh as it is, this plugin is a bit problematic as it overrides the CommandView in every case, so it'll try previewing anything the CommandView is showing. It even causes a crash in some cases, for example when trying to create a new file from the context menu of the TreeView (only if you try doing that with one of the first directories for some reason).

I fixed the issue by creating a new method called enter_with_preview so that you must explicitly call it for enabling the preview.
Also I overwritten core:open-file and core:find-file to use it.

A better solution would be to provide your own function to open files. I think it could use suggest directly to change files. You could also provide a wrapper function that will have to be passed to suggest, for people/plugins that want to integrate your preview.

The problem that suggest will be only called when some input text is changed and not if you move your arrows around.
To get the correct suggestion_idx the only way I found was to overwrite CommandView:update.

As a note, you don't really need to specify . as path in the manifest.

Done

@Mandarancio Mandarancio marked this pull request as ready for review July 22, 2024 09:19
@adamharrison
Copy link
Member

The problem that suggest will be only called when some input text is changed and not if you move your arrows around.
To get the correct suggestion_idx the only way I found was to overwrite CommandView:update.

I think this is fine for now, but it makes me think we should have an additional callback in CommandView:enter to trigger on suggestion selection, like change.

I fixed the issue by creating a new method called enter_with_preview so that you must explicitly call it for enabling the preview. Also I overwritten core:open-file and core:find-file to use it.

I think this is also reasonable. I like it.

@adamharrison
Copy link
Member

Of note, this will crash on certain binary files on master, but that's not necessarily a problem with this plugin, more with lite itself.

Discussion on discord was that this is probably OK; rather than handling it in this plugin, there are numerous ways to treat opening a binary file, including plugins that throw up confirmation screens, so I think this is fine. Merging.

@adamharrison adamharrison merged commit 9918d3a into lite-xl:master Jan 6, 2025
@Guldoman
Copy link
Member

Guldoman commented Jan 6, 2025

As a note, this is pointing to an old commit, so it should be updated if needed.

I would also suggest adding more ignored filetypes (for example zip), or at least checking the file content for non-unicode characters.

PerilousBooklet pushed a commit to PerilousBooklet/lite-xl-plugins that referenced this pull request Jan 14, 2025
* Update manifest.json

* Update manifest.json

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

Successfully merging this pull request may close these issues.

3 participants