PlanetCNC / PlanetCNCNpp

Expression calculator plugin for Notepad++
5 stars 0 forks source link

[Feature] Multiple selections support #2

Open pidgeon777 opened 2 years ago

pidgeon777 commented 2 years ago

Let's consider this example with multiple selections:

image

When executing the Expression command, this happens:

image

Ideally, the expression should be simultaneously calculated for each selection, and the result saved to the clipboard.

As a result, the original selections should be replaced with the corresponding expression results when pasting.

If an expression is not recognized, the ERROR string could be output instead, for the corresponding selection.

PlanetCNC commented 2 years ago

This is still one selection. But it is multiline. In this case you need to use ; separator at the end of each line. All lines will be evaluated aby you'll get result from last evaluation. See "Example 2"

pidgeon777 commented 2 years ago

Perfect.

But I was discussing the case with three single selections (one per row).

For example, when you hold Ctrl and click with left mouse button to add a selection.

In that case, it would be extremely helpful to consider all of the selections as independent and calculate the associated expression.

In the end, the clipboard should contain something like the following:

result1
result2
ERROR
result3
...

ERROR could be associated with an erroneous expression result, for the corresponding selection.

pidgeon777 commented 2 years ago

@PlanetCNC do you think my proposal could be integrated?

PlanetCNC commented 2 years ago

I'll think of something

PlanetCNC commented 2 years ago

In next version this will be possible: print(2+3*5); print(0x0004+2); print(sin(3.141)); print("Hooray");

pidgeon777 commented 2 years ago

Thanks for the new info, I'm just wondering if it will be necessary to add all of those prints to enable multiple selection supports.

I imagine it would be enough to do something like this, e.g. with this text:

Let `22and0xc+9,ACand finallysin(3.14)`.

  1. Those are our four selections:

    a. 2*2 b. 0xc+9 c. A*C d. sin(3.14)

  2. We trigger the Expression command.

  3. The plugin detects all of our selections and calculates their expressions separately.

  4. We obtain:

Let 4 and 21, ERROR and finally 0.00159.

So, no need to use the print(expression) format.

Or did you mean to use it for something else?