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

Editing a snippet in an editor #104

Closed
tpoliaw opened this issue Sep 16, 2021 · 7 comments · Fixed by #106
Closed

Editing a snippet in an editor #104

tpoliaw opened this issue Sep 16, 2021 · 7 comments · Fixed by #106

Comments

@tpoliaw
Copy link
Contributor

tpoliaw commented Sep 16, 2021

When editing an existing snippet (the-way search -> select -> shift+right), after confirming the other fields, the prompt says Code snippet (<RET> to edit in external editor). What is <RET> in this case? Return/enter appears to only submit the snippet as it is.

I have tried with $EDITOR both unset and set to vi.

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Sep 16, 2021

Been looking at this again and it only behaves like this if the command/snippet is a single line. Happy to submit a PR for this but not sure what the preferred behaviour would be.

Options I can think of:

  • Open the editor for all snippets immediately instead of using the prompt (keep the prompt for the other fields)
  • Open the editor with the original command if you delete the contents of a single line command. Potentially more convenient for single line commands but a bit unintuitive
  • Change the prompt to only mention editor when there are multiple lines (but keep the behaviour the same)
  • Something else?

@Ninjani
Copy link
Member

Ninjani commented Sep 17, 2021

Ah yes, good point, it's not super obvious now. I personally would prefer option 3

Change the prompt to only mention editor when there are multiple lines (but keep the behaviour the same)

since spinning up an editor for a single line command seems unnecessary in most cases - but let me know if you think otherwise or there are cases I'm not thinking of where editor support would be useful.

@Ninjani
Copy link
Member

Ninjani commented Sep 17, 2021

Another alternative would be to use a different key combo (Shift-Enter for instance) to open up the editor in this case - so would need a change in the prompt and behaviour.

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Sep 17, 2021

The only issue I can see is if you want to add a second line to a single line command. Not sure how common a use case that is though. How easy is it to handle key-combos from Dialoguer? I think that would be the best of both worlds but is probably the most involved change.

@Ninjani
Copy link
Member

Ninjani commented Sep 17, 2021

if you want to add a second line to a single line command

Oh this is a great point, hadn't considered it. Also, looks like dialoguer has some issues with certain characters (e.g. #128) so I think your Option 1 ( Open the editor for all snippets immediately instead of using the prompt ) makes the most sense now, even if it is a bit cumbersome for single line snippets.

Would you be up for making a PR?

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Sep 17, 2021

Sure, will have a look this evening.

a bit cumbersome for single line snippets.

Thinking about this, would a fourth option be to prompt for edit snippet [y/N]?? Given edit also lets you edit the other metadata, it's not unlikely that the only edit is to change tag/description and this would prevent the editor opening every time which may be slow (can $EDITOR be set to a GUI app?).

tpoliaw added a commit to tpoliaw/the-way that referenced this issue Sep 17, 2021
Previously if a snippet was a single line, there was no way of opening
it in an external editor. This meant (among other things) that is was
not possible to add a line break to a single line snippet.

It also meant for multi line snippets that the editor had to be opened
and closed in order for the edit to be completed even if the user only
wanted to edit tags or description.

This is slightly more involved when making simple edits to single lines
but the consistency across all snippets makes it clearer how things
work.

Fixes out-of-cheese-error#104
tpoliaw added a commit to tpoliaw/the-way that referenced this issue Sep 17, 2021
Previously if a snippet was a single line, there was no way of opening
it in an external editor. This meant (among other things) that is was
not possible to add a line break to a single line snippet.

It also meant for multi line snippets that the editor had to be opened
and closed in order for the edit to be completed even if the user only
wanted to edit tags or description.

This is slightly more involved when making simple edits to single lines
but the consistency across all snippets makes it clearer how things
work.

Fixes out-of-cheese-error#104
@Ninjani
Copy link
Member

Ninjani commented Sep 20, 2021

Thinking about this, would a fourth option be to prompt for edit snippet [y/N]??

Yep, I like this idea! And yeah EDITOR could be anything so it's a pretty good way to make sure you don't open it unless you want to.

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 a pull request may close this issue.

2 participants