Select, grab and move - faster way
-
Thanks for your response! Sure, this could save my life :)
Contact me on alexander.post(at)protonmail.com for details.
I am for that functionality: holding left Control + LMB will highlight and “cut” my number with “|” delimeter. Then this number will float with my cursor automatically, without any other action and embed when I click LMB again. Can you do that? It will be great…
About your question: I add this delimeter in Preferences -> Delimeter -> “Add your character…”. -
@learner9753 said:
I am for that functionality: holding left Control + LMB will highlight and “cut” my number with “|” delimeter. Then this number will float with my cursor automatically, without any other action and embed when I click LMB again. Can you do that?
Nope, it wouldn’t work that way. Scripting only gives you so much capability (with reasonable effort). It would work the way I said before, but I can make it plainer, I think: Double click some text, it totally disappears. You now have a normal looking caret and you have no mouse button down. Next you move the mouse to where you want the text to appear but you DO NOT STOP on the way (if you stop it will get pasted wherever you stop). When you reach your stopping point your text gets pasted without any other action (besides stopping).
Contact me on alexander.post(at)protonmail.com for details.
Gosh if I contacted you any way other than postings back-n-forther here it would have to be with an invoice for services. ;)
-
Here’s a Pythonscript that implements the functionality:
from Npp import editor, SCINTILLANOTIFICATION, NOTIFICATION try: install_state except NameError: install_state = 0 # 0 = first run, 1 = active, 2 = inactive if install_state == 0: paste_upon_mouse_stopped = False pos_of_cut = -1 cut_word_length = 0 LINE_NUMBER_MARGIN_DEFAULT_BACK_RGB = editor.styleGetBack(STYLESCOMMON.LINENUMBER) BLUEISH_RGB = (135, 206, 250) # margin color when paste is pending def dwell_start_callback(args): if install_state == 2: return global paste_upon_mouse_stopped if paste_upon_mouse_stopped: pos_of_mouse_stop = args['position'] if pos_of_mouse_stop != -1: # if mouse cursor points beyond end-of-line or other non-position'd spot if pos_of_mouse_stop < pos_of_cut or pos_of_mouse_stop > pos_of_cut + cut_word_length: editor.setSelectionStart(pos_of_mouse_stop) editor.setSelectionEnd(pos_of_mouse_stop) editor.paste() editor.setSelectionStart(pos_of_mouse_stop) editor.styleSetBack(STYLESCOMMON.LINENUMBER, LINE_NUMBER_MARGIN_DEFAULT_BACK_RGB) paste_upon_mouse_stopped = False def double_click_callback(args): if install_state == 2: return ss = editor.getSelectionStart() se = editor.getSelectionEnd() if ss != se: global cut_word_length, pos_of_cut, paste_upon_mouse_stopped cut_word_length = len(editor.getSelText()) editor.cut() pos_of_cut = editor.getCurrentPos() paste_upon_mouse_stopped = True editor.styleSetBack(STYLESCOMMON.LINENUMBER, BLUEISH_RGB) editor.setMouseDwellTime(300) # set a more reasonable value than the default (10000000 ms) editor.callback(dwell_start_callback, [SCINTILLANOTIFICATION.DWELLSTART]) editor.callback(double_click_callback, [SCINTILLANOTIFICATION.DOUBLECLICK]) install_state = 1 else: install_state = 2 if install_state == 1 else 1
It turns the line number margin area blue while the functionality is “in progress”. This was kind of interesting to experiment with, not sure of its general usefulness…
BTW, once the script is run it remains “on” and available. Running it a second time will turn it “off” without really uninstalling it. A third run will turn it back on, etc.
-
Thank you very much Bro!
Besides: I’m very noob in python scripting in notepad++… I tried to run this by link text (Python Script). I even do not know if this is apropriate plugin for that. I have installed Python in my computer already. I tried to install this plugin through normal executable and I do not see this in my plugin list… Excuse me ;) -
welcome to the notepad++ community, @learner9753
here is the Guide How to install the PythonScript plugin on Notepad++ 7.6.3, 7.6.4 and above
-
Thank you, thank you very much! Everything goes perfectly well :) This script is great! Now my workflow improves heavily :D
-
Hello, @learner9753, @alan-kilborn, @meta-chuh and All,
Your script is really surprising, as it deals with mouse gestures ! This gives it a dynamic look, in contrast to most Python scripts, which provide, obviously, static results ;-))
Now, I think that it would be very useful to add a leading and/or a trailing string to the present cut selection ! I don’t mean dialogs to enter these string values. But, simply, two variables, let’s say
prefix
andsuffix
;-)). For instance, with, the two assignments :prefix = "......" suffix = " €"
and the original text :
Article A Article B Article C 120 270 53
We would get, after
3
mouse gestures :Article A......120 € Article B......270 € Article C......53 €
What’s your feeling about it ?
Starting with your example :
1|w| Na początku stworzył Bóg niebo i ziemię. |7225| |1254| |430| |853| |8064| |853| |776| and the result : 1|w| Na początku|7225| stworzył|1254| Bóg|430| [-]|853| niebo|8064| i|853| ziemię.|776|
Let’s suppose that any set of characters, surrounded by spaces, is always associated with a tagging number, of the next line. Then we could organize your example as below :
1 Na początku stworzył Bóg [-] niebo i ziemię. |w| || |7225| |1254| |430| |853| |8064| |853| |776|
Notes :
-
I just inserted some space characters, in order to see the associated zones clearly !
-
You’ve certainly noticed :
-
That an empty tagging number
||
have been added and associated to the word Na, of your example -
The string
[-]
have been added, in order to correspond with the853
tagging number of your example
-
Now, this template of text could be easily handled and modified with a regular expression S/R !
So, assuming, for instance, the original text, below, pasted in a new tab :
1 Na początku stworzył Bóg [-] niebo |w| || |7225| |1254| |430| |853| |8064| Some text indepedent of the main zones to process 1 Na początku stworzył |w| || |7225| |1254| Other rubbish text between 1 Na początku stworzył Bóg [-] niebo i ziemię. |w| || |7225| |1254| |430| |853| |8064| |853| |776|
- Open the N++ Replace dialog (
Ctrl + H
)
SEARCH
(?-s)^((.+\|)?\h*[^\h\r\n]+)(.*\R\h*)(\|.*?\|)\h*
REPLACE
\1\4\3
-
Click on the
Wrap around
option -
Choose the
Regular expression
search mode
Now, click on the
Replace All
button, exclusively, several times, till you see the lineReplace All: 0 occurrence were replaced.
. ( You may also use theALT + A
shortcut ! )Note that the number of hits on the Replace All button is equal to the value : 1 + number of tags of the longest line of tagging numbers of your file !
You should get the text below :
1|w| Na|| początku|7225| stworzył|1254| Bóg|430| [-]|853| niebo|8064| Some text indepedent of the main zones to process 1|w| Na|| początku|7225| stworzył|1254| Other rubbish text between 1|w| Na|| początku|7225| stworzył|1254| Bóg|430| [-]|853| niebo|8064| i|853| ziemię.|776|
- Finally just get rid of the surplus
||
empty tags ( as, for instance, after the Na word ! )
Best Regards,
guy038
P.S. :
The last line of the Alan script can be changed into :
install_state = 3 - install_state # values 1 or 2
Whatever your programming language, if you have a variable that can only take
2
valuesa
andb
, you can always use the simple assignment, below :var = ( a + b ) - var
to express the two possible values :-))
Indeed:
-
If var is equal to the value
a
, the next value becomes(a + b) - a
, i.e. the valueb
-
If var is equal to the value
b
, the next value becomes(a + b) - b
, i.e. the valuea
So, this syntax avoids an useless test. However, as this syntax does not, explicitly, show the two values, you may indicate them in comments, if desired
For instance, let’s suppose you have a test variable, which should be
-11
or+7
, only. Then, simply use the simple assignment :test = -4 - test # test = -11 or +7
Just because
(-11) + (+7) = - 4
!Of course, if you’re using the
-1
and+1
values to identify the two states, the above statement just becomes :test = - test # test = - 1 or + 1
-
-
@guy038 said:
Your script is really surprising,
I don’t know about surprising but I did think it was an interesting approach to the problem! :)
What’s your feeling about it ?
Sure, go for it! :)
“install_state”
Yea, my “install_state” stuff was kind of bad in the script (wrote that part very fast). After posting initially I made it better for myself, even though I may never have use for that script.
-
Hello, @learner9753, @alan-kilborn, @meta-chuh and All,
Alan, my post-script, about the
install_state
variable, was not intended to you, personally, but to everyone, of course. Just an easy trick ;-))
Now, I tried to slightly change your script to add a prefix and/or a suffix zones to the selected and cut text on a double mouse click. Of course, changes are quite minimum but, Alan, just tell me if something seems incorrect to you ;-)). Here is my version :
# coding= utf-8 # Modified version, on 04-20-2019, of the Alan KILBORN's Python script, which includes TWO preset # variables to define 2 text areas BEFORE and/or AFTER the text, selected and cut on a DOUBLE-MOUSE click # # ORIGINAL file at location : https://notepad-plus-plus.org/community/topic/17462/select-grab-and-move-faster-way/5 from Npp import editor, SCINTILLANOTIFICATION, NOTIFICATION try: install_state except NameError: install_state = 0 # 0 = first run, 1 = active, 2 = inactive if install_state == 0: # ----- START of the CONFIGURATION area ----- prefix = '......' suffix = ' €' # ----- END of the CONFIGURATION area ----- paste_upon_mouse_stopped = False pos_of_cut = -1 cut_word_length = 0 LINE_NUMBER_MARGIN_DEFAULT_BACK_RGB = editor.styleGetBack(STYLESCOMMON.LINENUMBER) BLUEISH_RGB = (135, 206, 250) # margin color when paste is pending def dwell_start_callback(args): if install_state == 2: return global paste_upon_mouse_stopped if paste_upon_mouse_stopped: pos_of_mouse_stop = args['position'] if pos_of_mouse_stop != -1: # if mouse cursor points beyond end-of-line or other non-position'd spot if pos_of_mouse_stop < pos_of_cut or pos_of_mouse_stop > pos_of_cut + cut_word_length: editor.setSelectionStart(pos_of_mouse_stop) editor.setSelectionEnd(pos_of_mouse_stop) editor.addText(prefix) editor.paste() editor.addText(suffix) editor.setSelectionStart(pos_of_mouse_stop) editor.styleSetBack(STYLESCOMMON.LINENUMBER, LINE_NUMBER_MARGIN_DEFAULT_BACK_RGB) paste_upon_mouse_stopped = False def double_click_callback(args): if install_state == 2: return if editor.getSelectionStart() != editor.getSelectionEnd(): global cut_word_length, pos_of_cut, paste_upon_mouse_stopped cut_word_length = len(editor.getSelText()) editor.cut() pos_of_cut = editor.getCurrentPos() paste_upon_mouse_stopped = True editor.styleSetBack(STYLESCOMMON.LINENUMBER, BLUEISH_RGB) editor.setMouseDwellTime(300) # set a more reasonable value than the default (10000000 ms) editor.callback(dwell_start_callback, [SCINTILLANOTIFICATION.DWELLSTART]) editor.callback(double_click_callback, [SCINTILLANOTIFICATION.DOUBLECLICK]) install_state = 1 else: install_state = 3 - install_state
Cheers,
guy038
-
@guy038 said:
Alan, just tell me if something seems incorrect to you
Seems reasonable – is there any problem with it when you run it?
-
None ! It does what I was expected to ;-)) I was thinking about syntax : may be, an other function than
editor.addText()
or… ?Anyway, thank you for your offer to help !
Best regards,
guy038
-
Hello @guy038
Thanks for your help and tips. But this text was only an example. This kind of work is only to do “by hand”, because things are not always so simple. Numbers are not always matching text with that simple order as in my example…