Noorts / Toggler

JetBrains IDE Plugin - Quickly toggle words and symbols with a hotkey

Home Page:https://plugins.jetbrains.com/plugin/16166-toggler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Allow toggling for partial matches

FeBe95 opened this issue · comments

Hello, thanks for this plugin so far, I just wanted to share a small feature request with you:

Sometimes I am working with symbols such as add_class or addClass. It would be nice to be able to change it to remove_class or removeClass with your plugin. Sure I could add the whole word to the list in my settings, but often enough it is not just this exact combination of these two words.

Would it be possible to add the functionality to toggle parts of strings as well? Maybe only allow it if there is a underscore or a case-change present, or allow it in general for all partial matches (addclass would match too).

I'd love to here your opinion on this!

Hey @FeBe95, thanks for the feature request. The functionality would indeed be a nice addition to the plugin.

I will look into how feasible this is soon. I'll update this thread once I know more.

Hey @FeBe95 once again. I've finally had some time to take a look at your request.

I've thought about the functionalities you suggested, some edge-cases and how I can implement the feature into the plugin. I'll discuss the problems faced, their solutions and my proposal down below.

Problems

There are a few problems that force me to make decisions about the way in which the partial matching is performed, they affect most implementations.

These are the following problems:

Word match vs partial match

In the current state of the plugin the dev | prod and development | production pairs have both been included by default. Partial matching introduces the following problem, should development by toggled to proelopment using the partial match or production using the full word match?

I think it is pretty logical for it to toggle to production, which means that a full word match should be given priority over a partial match if one can be found. Or you can say that in general a longer match gets the priority.

Multiple partial matches in one word

The plugin currently also includes the add | remove and class | interface pairs. If we toggle a symbol such as addClass, then which of the two words should be swapped? Should it be both, should it always be the first match found (starting from the left) or should the priority be based on the caret (cursor) its position inside of the symbol?

I think the best solution would be the third, which is to give priority to the caret position and to toggle that partial match. This allows the user to decide for themselves which part should be toggled.

Proposal

I plan on implementing general partial matching. So this will work on add_class, addClass and addclass. It will first try to find a full word match, if that can't be found, then it will proceed to look for a partial match at the caret position.

Implementing this general matching requires more effort than just the case-change and underscore cases, but I think it will be worth it in the end. It will be a little heavier computationally, but I think it will still be negligible.

I will add an option to the configuration menu that allows the users to enable this new matching. In that way it can still be toggled off.

I'd love to hear your feedback. I plan to work on it "soon".

Hey @Noorts, thank you for your in-depth explanation before implementing this feature. You proposal sounds well thought out and solves all the introduced problems.

I'd maybe add one additional differentiation for the cursor(s):

  • If a cursor has no width (the selection start equals the selection end) your solution works perfectly fine. Try to find a match for the whole word, if it does not exist take the cursor position and try to find a partial match, otherwise do nothing.
  • But if the cursor is explicitly selecting any text (the selection start does not equal the selection end) ONLY try to toggle the selected string, otherwise do nothing.

With this solution one could swap specific words by searching/finding and selecting a (partial) word throughout a file and toggle the them exactly as desired - even if they are part of a longer matching word.

Thanks again for your time and feel free to reply with your thoughts on this :)

Great suggestion 👍. I'll take it into account when I start implementing the new feature.

Thanks again to you aswell, this discussion has definitely helped to make clear what functionality is desired.

Hey @FeBe95, I've finally had some time to work on this project.
The partial matching functionality has been added (PR) as per v1.2.0 and is pretty neat if I have to say so myself.

The new update (v1.2.0) is available here as a release and will be available on the marketplace and in your IDE once JetBrains approves the update (usually two business days).

Once again thanks for the feedback.

Hey @Noorts, I just wanted to thank you again for the quick implementation! Partial toggling works flawlessly and exactly the way I imagined!