Open GwynethLlewelyn opened 3 days ago
A possible workaround would be to capture text from the clipboard instead. I noticed that there are a few functions in the API which allow the clipboard to be read and/or written to — thus, an alternative would be to check if anything was inside the clipboard instead of being selected inside the editor.
Hi!
Thanks so much for your fantastic plugin, it's extremely useful!
As a Mac user, I have an option to generate the same kind of statistics, which is part of my right-click menu. That menu is a built-in functionality, which, unless overridden, is available on all applications. I use it all the time, since I'm infamously known for writing too much, and, as such, I'm constantly hitting all possible character/word limits everywhere... thus the importance of having an easy way to calculate that. What could be easier than to select the text and let it be counted?
Unfortunately, for some reason only known to the Joplin developers, they thought that it would be a great idea to override the right-click functionality, giving us instead a very simple and minimalistic menu.
Just to give you an idea, this is the kind of menus I get when selecting text and right-clicking on it, inside the Brave (Chromium-based) browser:
Note the richness of all the options there. At the top come the system (macOS) default options. Then you get the additional options for the browser itself. Then come the options from the browser plugins. And below that you still have the Inspect tools (since we're inside a browser) but also this user-defined Services... menu option (actually, it requires additional, specific, system-wide plugins which implement that functionality).
Opening this submenu shows the following:
You can see here how more options have been added, from the several so-called 'services'; a,nd, again, they come from different sources. You might have noticed how I can easily capture a PGP public key and add it to my keyring that way, or digitally sign just a block of text, or get it translated with DeepL (and the translation will automatically replace the selected text), and so on, and so forth. There are even a few system services there, such as Spotlight (what Apple calls their system-wide search facility) or Summarise (a low-end AI running locally to do very simple — and often unuseful — summarisations).
Then come my must-have "WordService" tools, which add lots of simple, useful extra commands which will work on any text editor, even if not directly supported. You might see down there the WordService: Statistics... menu option. Once selected, it just pops up a window with everything I need:
That couldn't be easier, right? Right.
Now, I fully admit that I would rather prefer Joplin to not override my beautiful right-click menu, but, since apparently I cannot change that behaviour easily (perhaps there is an option for that, hidden deep in the documentation...), my best choice is to take what is already available for Joplin — namely, your plugin — and see what can be done with them.
From what I understand of your code, your calculations are always related to the contents of the whole note, as in what we can see in the code for
index.ts
:I have just very briefly browsed through the Joplin API documentation, but I was unable to figure out any examples of how to extract only the selected text. Maybe this is a function of specific editors, not of Joplin per se? I still might take a peek at how the "Math Mode" plugin directly retrieves the selected text and replaces it with whatever mathematical operation had been selected.
That said, do you think that this is an appropriate extension for an upcoming new release of Note Statistics? Or should it be an altogether separate plugin, which just happens to share a lot of common code with Note Statistics?
hanks in advance for the time taken in reading this feature request!