roam-unofficial / roam-toolkit

Roam force multiplier
MIT License
476 stars 43 forks source link

Fuzzy Dates Edge Case when using multiple semicolons in a paragraph #201

Open shanrauf opened 3 years ago

shanrauf commented 3 years ago

If I write out something like below, Roam Toolkit will replace everything between the semicolons because there is a fuzzy date in that text:

Here is some text; in two weeks, I'm going to do x. I'm not sure if I should do x; might be a waste of time.

I spent a few hours working on a PR, but what I was coming up with was pretty complicated and there's probably a magical regex solution to this problem that someone could create instead (I don't know regex), so I'm going to hold off on that...

Stvad commented 3 years ago

One potential workaround to consider is replacing the ; guard with some other symbol in settings

shanrauf commented 3 years ago

@Stvad Good idea, thanks. Do you think this should be fixed eventually? (If so, I can go learn regex to try to solve it) My sense is that you would never want the behavior I described above.

shanrauf commented 3 years ago

Ah I'm re-reading your comment, and are you suggesting to instead change the default guard to something other than semicolon? That would help but probably not solve the underlying problem which you could probably run into with any guard I think.

Stvad commented 3 years ago

How do you see the proper fix behaving? :)

That would help but probably not solve the underlying problem which you could probably run into with any guard I think.

that's true but with a proper guard you basically never hit undesired substitution...

I think one potential approach would be to do substitution not on key press, but after key press (so it's recorded in edit history and then if you do the "undo" operation - you get to a state when you have a text surrounded with semicolons without substitution)

shanrauf commented 3 years ago

@Stvad The way I was trying to code it was to check if a fuzzy date existed between the guards, and if it did, make sure that there is no text on either side of the fuzzy date except for the semicolons (i.e node === ";${fuzzy_date_text};"):

Substitute: ;in two weeks;

Don't substitute: ;text before fuzzy date in two weeks and after fuzzy date;

That way, you would never have an undesired substitution (that I can think of...).

Stvad commented 3 years ago

I think it may be possible to substitute only the date part, or check what percentage of the text is actually encoding the date and prevent substitution in some cases. I'd look into the https://github.com/wanasit/chrono api to figure this out though (vs trying to detect it via a custom regex) That is lib that toolkit is using internally for this.