Multi-cursor editing
-
@Ekopalypse I use BetterMultiSelection in conjunction with LuaScript to select multiple instances and then edit them simultaneously…works quite nicely.
-
I have no doubt that this works great. :-)
-
@Ekopalypse said in Multi-cursor editing:
Just select the part of the word you are interest in and it should respect it already. This is a scintilla feature not really my work.
Yes, it works fine… almost all the time. In one of my tests Notepad++ ceased to respond and have to quit it via the taskbar.
Better stop for today.
-
Hello, @czmaniak, @alan-kilobrn, @peterjones, @ekopalypse, @astrosofista,
In that discussion, I suppose that the
Multi-Editing
option is enabled, in>Settings > Preferences... > Editing
and that theBetterMultiSelection
andPythonScript
plugins are both installed, in your N++ configuration !
It may be worth to note that, by default, in Notepad++, the multiple cursors editing feature behave differently from the column mode editing and that it is identical only if you install and enable the
Better MultiSelection
plugin of @dail !For instance, assuming the five lines, below, the
BetterMultiSelection
not enabled and thePython script
not used :12 56498><717 5123 131 21 78483><000 0456 235 16 89410><575 5156 464 97 89411><056 6045 454 01 25822><644 8970 544
If you create a zero-length column selection, through these five lines, between the
>
and<
chars, you’re able to
type in some chars, even tabulations and/or spaces and you may delete few chars, with thebackspace
or theDelete
key.However, as soon as you want to use, for instance, the right arrow key or the
Ctrl + Left
shortcut, theHome
orEnd
key and even theEnter
key, these commands do not act for all the lines of the column selection
Now, click between the
>
and<
chars of the first line. Then, holding down aCtrl
key, click, at the same location, for line2
to5
. The screen seems similar to before but, this time, we get, I would say, something like a5
one-line column selection ( instead a1
five-line column selection ) !Therefore, the use of the arrow keys, shortcuts involving arrow keys, the the
Home
,End
key andEnter
key correctly act as expected ;-))The good news is that IF you enable the
BetterMultiselection
@Dail’s plugin, from within N++, you can, use this enhanced behaviour, too, when creating a classical column selection ;-))
Obviously, the @ekopalypse’s python script does not create a column selection but, indeed, places individual cursors on every line, containing a specific word. This explains why if we use the @ekopalypse’s python script, below, we do not need the
BetterMultiSeelection
, in conjunction !from Npp import editor first_line = editor.getFirstVisibleLine() editor.setTarget(0, editor.getTextLength()) editor.multipleSelectAddEach() editor.rotateSelection() editor.setFirstVisibleLine(first_line)
Of course, this script solution seems more flexible, because it places all the cursors at the end of a specific selected word, so, not necessarily at the same column, in each line !
Now, and a bit off-topic, I would like some information from Python guru’s people ;-))
In order to realize this post, I decided to install, manually, on my portable N++
v7.8.5
release, the lastV1.5.3
version of thePythonScript
plugin, from :https://github.com/bruderstein/PythonScript/releases
-
First, I did not know to choose between the
PythonScript_Full_1.5.3.0.zip
and thePythonScript_Full_1.5.3.0_PluginAdmin.zip
archives ! After downloading the two archives, I just realized that they were strictly identical and, also, verified, with WinMerge, that their contents were the same !? So what ? -
Then I created, as usual, a
PythonScript
sub-folder, in thePlugins
folder -
Opening the archive
PythonScript_Full_1.5.3.0.zip
, I noticed that the two dllPython27.dll
andPythonScript
were at the same level. So, I supposed that, from now on, thePython27.dll
file wasn’t anymore along with theNotepad++.exe
file -
Therefore, I just extracted all the contents of the archive in the
PythonScript
sub-folder, that I just created -
However, during N++ start-up, I got the message, in French :
“This application could not start because python27.dll cannot be found. …”
- Luckily, putting back the
Python27.dll
library, along withNotepad++.exe
, everything is back to normal ;-)) And the consultation of thev1.5.3
documentation works just fine, too, from its new location !
Best Regards,
guy038
-
-
@guy038 said in Multi-cursor editing:
PythonScript_Full_1.5.3.0.zip and the PythonScript_Full_1.5.3.0_PluginAdmin.zip … they were strictly identical
I also confirm this.
No idea as to the “why” of it.“This application could not start because python27.dll cannot be found. …”
This part I could NOT duplicate.
For me it worked just fine with python27.dll in the PythonScript subfolder under Plugins. -
@guy038 said in Multi-cursor editing:
So I tried the following with no BetterMultiselection plugin, nor any Pythonscript influence. I’m interested in what you think about it.
I started with this text:
12 56498><717 5123 131 21 78483><000 0456 235 16 89410><575 5156 464 97 89411><056 6045 454 01 25822><644 8970 544 123 456789 12 56498><717 5123 131 21 78483><000 0456 235 16 89410><575 5156 464 97 89411><056 6045 454 01 25822><644 8970 544
and created “a 5 one-line column selection” like you did on the first five lines. Thus the most-recent (i.e., the “main” selection caret) was on the 5th line.
My goal in this testing was to use the down arrow (and only that key) to move my “selection carets” so that they were in the same spot in the lower grouping of five lines as they were in the top set of five lines.
I found I could not do it.
What I obtained was four carets in column 1 and one caret (the original “main” selection one) in between the
><
on the last line of the file.To be fair to N++, I did the same test in the Scintilla demo editor, with the same result.
Maybe my expectation in this scenario is unrealistic?
-
@astrosofista said in Multi-cursor editing:
… almost all the time
Ooopppss - did not happen to me yet.
Is it possible that a very, very large amount of data had to be selected?
I have done a small performance/stress test using this script to generate the test data.editor.appendText('This is a teest to see if it works\r\n'*100000)
It took about 1 minute, on my PC, until all 100_000 instances were selected.
For a test with 1000 instances, which in my opinion is still not
a real world test - I mean, who has 1000 instances of the same word
in their source code? - it actually selected it immediately.I ASSUME one of it, guess which one, is for the plugin admin,
maybe a naming thing?? But of course, if both are the same then the
non-plugin-admin version could have been deleted.Python27 should be loadable from within plugin directory.
There was a change in npp source which allows plugins now to find
their needed dlls within its directory. -
Hello, @czmaniak, @alan-kilborn, @peterjones, @ekopalypse, @astrosofista,
Regarding the Python problem, I deleted my Python install and re-installed the plugin with, unfortunately, the same result. My python27.dll library has version
2.7.17150.1013
and contains2,649,600 bytes
. But, never minds : it should be related to my old Win-XP laptop !!
Now, Alan, assuming the text,below :
123 456789 12 56498><717 5123 131 21 78483><000 0456 235 16 89410><575 5156 464 97 89411><056 6045 454 01 25822><644 8970 544 123 456789 12 56498><717 5123 131 21 78483><000 0456 235 16 89410><575 5156 464 97 89411><056 6045 454 01 25822><644 8970 544 123 456789
I did your test, without any plugin, involved :
-
I placed a caret, between the
>
and<
chars inside the first block, so5
ones, using theCtrl
key -
Then, hitting
9
times on theDown arrow
, only, I obtained exactly what you got ! -
Now, cancel any null selection
-
Create a normal column selection, between the
>
and<
chars of the first block -
Then, hitting
9
times on theDown arrow
, only, anunique cursor was present on the 5th line of the second block
-
Now, enable the
BetterMultiSelection
plugin -
Place a caret, between the
>
and<
chars inside the first block, so5
ones, using theCtrl
key -
If you hit
9
times on theDown arrow
, only, this time, the5
carets are correctly located, between the>
and<
chars of the second block of five lines :-)) -
Cancel any null selection
-
Create a normal column selection, between the
>
and<
chars of the first block -
If you hit
9
times on theDown arrow
, only, again, the5
carets are correctly located, between the>
and<
chars of the second block of five lines :-))
So, the @dail’s
BetterMultiSelection
plugin is definitively a must and should be installed and enabled every time ;-))
IMPORTANT : To cancel any complicated number of selections, resulting of the use of the
BetterMultiSelection
plugin, simply hit theESC
key !Cheers,
guy038
-
-
Ahh, yes - this was one of the reason to drop XP support as this
API is not supported by XP. -
@Ekopalypse said in Multi-cursor editing:
Ooopppss - did not happen to me yet.
Is it possible that a very, very large amount of data had to be selected?No, it wasn’t. It was late and I’m sorry but can’t exactly remember what was the selection to be made, surely the target were partial words. But don’t worry, maybe the issue had other causes. If I can reproduce it will let you know.
Best Regards
-
@guy038, @alan-kilborn, All
I tried to replicate your tests as long as I understood them, with just Notepad++ basic multiselection feature, that is, disabling the BMS plugin and without running Ekopalypse PS:
In the first test I created a null selection column by pressing Shift + Alt + Down Arrow 5 times. As soon as I moved the caret down with an arrow key, the multiselection got lost. End of test.
Second test. Created a null selection column pressing Cntrl + Click 5 times. Moved it down and arrived to line 14 with 5 cursors but misalignated. To resolve this unwanted result hit End and all the 5 cursors aligned at the end lines —or hit Home to get a similar output—. Then went up and got the same as before.
Conclusion: It matters how the multiselection is created. I’m really puzzled.
Best Regards
-
scintilla knows and uses different selection modes.
By using SHIFT+ALT+ARROWDOWN/UP you are creating a rectangular selection. By using CTRL+mouse_click you are creating the stream mode.
-
-Thank you. I was unaware of these different modes of selection, considered them as an unique mode, without any difference.
So the selection mode that is created by means of your Python plugin, for example, like in the gif animation you uploaded to this thread two days ago, seems to be a stream mode. Am I right?
-
@astrosofista said in Multi-cursor editing:
So the selection mode that is created by means of (PythonScript) plugin…seems to be a stream mode.
It’s not explicit in the Python code presented, but most of the P.S. functions that deal with creating selections assume you want stream mode. There are only a few functions that allow you to create column-block selections:
editor.setRectangularSelectionAnchor() editor.setRectangularSelectionAnchorVirtualSpace() editor.setRectangularSelectionCaret() editor.setRectangularSelectionCaretVirtualSpace()
-
-
Good to know, thank you :)
-
Thank you :)
-
@astrosofista said in Multi-cursor editing:
@Ekopalypse said in Multi-cursor editing:
Ooopppss - did not happen to me yet.
Is it possible that a very, very large amount of data had to be selected?No, it wasn’t. It was late and I’m sorry but can’t exactly remember what was the selection to be made, surely the target were partial words. But don’t worry, maybe the issue had other causes. If I can reproduce it will let you know.
Hi @Ekopalypse, All
I think I found the mentioned issue. When a character as a comma (
,
) is selected —shown at the top of the posted imagen— the Python script works as expected, but things go weird when you select a period or a dot (.
) and run the PS —at the bottom of the imagen—, as the multiselection now encompass all the characters of the document:Hope this helps.
-
Apparently the script is treating the
.
as the regular expression for “any single character”. Thus, when the script is run with only a.
character selected, you get a blinking (if so configured) caret at every position in the doc. This script modification corrects it:from Npp import editor first_line = editor.getFirstVisibleLine() editor.setSearchFlags(0) # <---------- the new line editor.setTarget(0, editor.getTextLength()) editor.multipleSelectAddEach() editor.rotateSelection() editor.setFirstVisibleLine(first_line)
I’m not sure of the complete set of possible arguments to
.setSearchFlags()
– it is not documented so well in the P.S. docs–but I found these in the Notepad++ source code:#define SCFIND_NONE 0x0 #define SCFIND_WHOLEWORD 0x2 #define SCFIND_MATCHCASE 0x4 #define SCFIND_WORDSTART 0x00100000 #define SCFIND_REGEXP 0x00200000 #define SCFIND_POSIX 0x00400000 #define SCFIND_CXX11REGEX 0x00800000
My modification to the script is using
SCFIND_NONE
. -
Definitively regex, or at least some of its functions are invoked in the original PS. I typed an
\s
at the end of the first paragraph —I mean the GNU License sample text—, then selected thebackslash
, run the script, then thes
and the script… PS ignored single characters and only take into consideration whole words, so when I selected the firstT
, PS did nothing, butThis
was selected and PS correctly matched the other two instances of the word.Anyway, the script modification you provided solved the issue. A big thanks for your assistance and fast reply.
Best Regards.