argenos / nldates-obsidian

Work with dates in natural language in Obsidian
MIT License
497 stars 46 forks source link

Use command without select multiple-words dates #20

Closed desk7 closed 3 years ago

desk7 commented 3 years ago

The plugin's description says that "for single-word dates (e.g. today, tomorrow, friday, etc.), it's possible to use the command without selecting the word first."

Could you extend this feature to include also the other multiple-words date?

argenos commented 3 years ago

This would be quite hard to do! The reason why you need to select multi-word dates is that the parser needs to know where in your document to find them. On a particular note, how would you identify multi-word dates? How many words should the parser try to include?

desk7 commented 3 years ago

Let me explain. I write the date, as in the demo, then, without selecting anything, I press Ctrl+Y and the parser searches for multi-word dates in the words before the cursor position. How many words? According to the demo, the recognized expressions are at most 3 words long (e.g. in 3 weeks, in one year etc.), so the parser should search in the 3 words before the cursor position. I don't mean that the parser should search the whole document.

argenos commented 3 years ago

That could be doable but I am not sure that commands are always at most 3 words long. It probably also needs first to check the two prior words, and if it doesn't return a valid date try with three. Since I can't really promise I'll have time to look into this in the near future, I'm willing to accept PRs for this.

twwilliams commented 3 years ago

What if this just looked back to the beginning of the current line (or to the end of the current line) rather than searching throughout the document? That way it wouldn't have to be specifically three words.

But that's still not a trivial kind of parsing to do.

desk7 commented 3 years ago

I honestly thought to parse 3 words is easier than a whole line.

I am not a programmer, but I would like to make an observation. Currently the plugin parses the selected text. To get the desired behavior, the plugin should automatically select the 3 words before the cursor, then parse them; if it doesn't find a date, it tries the last 2 words; if it still doesn't find anything, it tries the last word.

I'll give an example. Suppose I write "in 2 months" and I have the cursor after the s. I press Ctrl+Y. The plugin selects the 3 words before the cursor, recognizes the date and replaces it.

Other example Suppose I write "I will go to the park today" and I have the cursor after y. I press Ctrl+Y. The plugin selects the 3 words before the cursor, it doesn't recognize any date. Then try with the last 2 words, it doesn't recognize any date. Then try with the last word, it recognizes the date and replaces it.

argenos commented 3 years ago

Not exactly the way it was requested in this issue, but I consider the auto-suggest in v0.5.0 to fix this.