matt-dray / quartostamp

:white_flower::scroll: R package: RStudio Addin to insert ('stamp') useful Quarto elements
https://matt-dray.github.io/quartostamp
Other
59 stars 2 forks source link

Remove overtyping of existing code? #6

Closed Lextuga007 closed 1 year ago

Lextuga007 commented 1 year ago

Not sure how feasible this is but if there is code already written, like for the incremental bullets, then if that code is highlighted and Insert incremental list is selected it would be magical if it surrounded the text and didn't overtype it.

The reason why this is so useful is if you've (as in I've!) written ::: incremental instead of ::: {.incremental} multiple times!

matt-dray commented 1 year ago

Oh yeppers, this is doable. In fact, {snorkel} has this behaviour.

Stretch goal: in theory there could be some input checks too. Like a warning() if you've asked for incremental but your text doesn't appear to be bullet points.

You also just reminded me re ::: {.notes} vs ::: notes, so I've added #7.

matt-dray commented 1 year ago

Hullo @Lextuga007, I've now done this in the branch md-overwrite. Would you like to guinea-pig it for me? You can install like:

remotes::install_github("matt-dray/quartostamp@md-overwrite")

So, as before: if you don't highlight any text, you'll get this generic thing inserted when you use the addin for 'Insert Incremental List':

::: {.incremental}
- List element A
- List element B
:::

But let's say you have the following text:

- I'm going to build tension...
- By revealing incrementally until...
- BOO!

If you highlight that and then use the addin, you'll get this instead:

::: {.incremental}
- I'm going to build tension...
- By revealing incrementally until...
- BOO!
:::

Another thing I'd be interested to hear about it footnotes. I decided to drastically improve the 'Insert Footnote' one as well. Before it just inserted '[^A footnote]' inline where your cursor was. It will still do that if you don't select any text, but if you do select some text, it will generate the footnote label by taking the first 10 non-space, non-punctuation characters (e.g. select 'NHS-R Community' and you'll get 'NHS-R Community [^nhsrcommun]' inserted). Additionally, it will generate a footnote string ('[^nhsrcommun]: Insert description.' in this case), copy it to the clipboard and prompt you in the console to paste it at the bottom of the document. (I tried to automatically insert the footnote in a new row at the bottom of the document, but that involves first resaving the user's document with a new blank row at the end and then pasting into it. It doesn't feel right to manipulate the user's file like that).

Happy to explain more if that doesn't make sense!

Lextuga007 commented 1 year ago

Tested the incremental and all works 😃

Lextuga007 commented 1 year ago

With the footnote I accidentally (but luckily perhaps!) highlighted the incremental text before using the footnote and that produced:

::: {.incremental}
- I'm going to build tension...
- By revealing incrementally until...
- BOO!
::: [^incrementa]

Highlighting some text gave:

This is text [^Thisistext]

and adding just a footnote with no highlighted gives:

This is text  [^footnote]

I did get this in the console:

The footnote '[^Thisistext]: Insert description.' was added to the clipboard. Paste it at the bottom of your document.

I totally agree with not saving a user's document first - good call 😃

matt-dray commented 1 year ago

Smashing, thank you for taking a look.

And whoops, yes, 'NHS-R Community' actually becomes [^NHSRCommun] rather than [^nhsrcommun]. I thought I'd put in a call to tolower(), but turns out that I didn't.

In retrospect, I might change the labelling system so the 'NHS-R Community' label would be [^nhsr-community]. This should be more readable.

Initially I wanted to keep the footnote labels short, but I think it's better to have 'This bit of text' become [^this-bit-of-text] rather than [^thisbitoft]. Downside is that you could end up with a really long footnote label if you select a lot of text, but I think the user can deal with that.

Also, I think that the message in the console should be slightly different if the user simply inserts a footnote. I think it should also say 'You may need to change the footnote label if it isn't unique' or something. Otherwise there'll be several conflicting [^footnote] labels.

Lextuga007 commented 1 year ago

I like having a bit of text and sometimes it will work brilliantly, often not. Getting it right for all circumstances may take too much work?

matt-dray commented 1 year ago

Okey doke, I merged this branch and bumped to v0.1, so the 'overtyping' thing is solved. Thanks Zoë! The (opinionated) footnotes addin now does what I think it should; happy to receive a new issue for any improvements.