Pasting without losing selection

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
knn
Posts: 30
Joined: 30 Mar 2020, 20:35

Pasting without losing selection

28 Apr 2020, 16:55

When I select text in Notepad++ and then copy ^c and paste ^v, I lose the selection.

Is there a way to paste but keep the pasted text selected?
User avatar
littlegandhi1199
Posts: 195
Joined: 29 Aug 2016, 23:58

Re: Pasting without losing selection

28 Apr 2020, 17:45

knn wrote:
28 Apr 2020, 16:55
When I select text in Notepad++ and then copy ^c and paste ^v, I lose the selection.

Is there a way to paste but keep the pasted text selected?
I'm sure this tip will come in handy. A core windows function exists which lets you tab through words in a line
Holding Ctrl+Left and right will go through the text as it finds spaces/enumerators (which it thinks are important)

Holding Ctrl+Shift+Left will go through (while also selecting them). It might be useful to you!

Here's a script that counts spaces in clipboard then issues correct number to go back to highlight your paste
after sending it.
Now to take it a step further we'll have to figure out the behavior it gets up to when it finds commas and % signs in there

Here's the script that works with clipboard pastes that only have spaces in them

Code: Select all

Clipboard =
(
The dog jumped over the sleeping cat
)
msgbox, Loaded your clipboard test a paste`n`n"%Clipboard%"


^V::
SendInput, +{Ins}
If (Paste = 1)
{
loop, parse, Clipboard, %A_Space%
	Total := A_Index
SendInput, ^+{Left %Total%}
}
Else
{
Paste = 1
msgbox, Now try it again with new pasting
}
return
Script Backups on every Execution :mrgreen:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=75767&p=328155#p328155

Scrabble Solver 4-15 letter word outputs ( :crazy: # of inputs)
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=34285
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: Pasting without losing selection

28 Apr 2020, 19:24

Not really the best method but it does work
Copy your text like normal and then paste it with ctrl+v
When you release the ctrl key,it will mark all of the rows

Code: Select all

#IfWinActive,AHK_class Notepad++
~^v::
KeyWait,Ctrl
Count =
Loop,Parse,Clipboard,`n
Count += 1
Send,{Shift Down}
Send,{Up %Count%}
Send,{Right}
Send,{Shift Up}
Return
It does similar thing as littlegandhi1199 example but in a faster way
User avatar
littlegandhi1199
Posts: 195
Joined: 29 Aug 2016, 23:58

Re: Pasting without losing selection

28 Apr 2020, 21:51

Oh yeah multiple lines.
So I started with that approach too but it wouldn't work if you were only pasting to the end of a line.
That would go back and select the entire line.
***However if that is sufficient and you'll only be pasting to blank lines (and not adding to the end sometimes) then that would work no matter what characters were contained in it and you could call it a day with his code.

If you will be posting to the end of lines then give me a day and I'll figure out how it works and get back to you

>>>There's mine (now supporting multiple lines) but still only spaces. Took out the tutorial to shorten it down lol

Code: Select all

^V::
SendInput, +{Ins}
loop, parse, Clipboard, %A_Space%
	Total := A_Index
loop, parse, Clipboard, `n`r
{
If (A_Index > 1)
	Total++
}
SendInput, ^+{Left %Total%}
return
Script Backups on every Execution :mrgreen:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=75767&p=328155#p328155

Scrabble Solver 4-15 letter word outputs ( :crazy: # of inputs)
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=34285
knn
Posts: 30
Joined: 30 Mar 2020, 20:35

Re: Pasting without losing selection

01 May 2020, 12:42

littlegandhi1199 wrote:
28 Apr 2020, 21:51
>>>There's mine (now supporting multiple lines) but still only spaces. Took out the tutorial to shorten it down lol
Yes, unfortunately it only supports spaces and not other delimiters that ctrl-left stops at, like / or .

It also doesn't handle leading spaces and tabs.

The fool-proof way (handles even Unicode) is to not use CTRL-LEFT but simply LEFT

Code: Select all

moveback := StrLen(clipboard)
SendInput, +{Ins} ; paste clipboard
SendInput, +{Left %moveback%}
return
But that's very sloooooow if the clipboard is long.

There must be a better way to paste without losing selection... :?
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: Pasting without losing selection

01 May 2020, 13:21

Notepadd++ actually have an option to mark a selection
This kinda work...most of the time

Code: Select all

~^c::
KeyWait,c
WinMenuSelectItem,A,,Edit,Begin/End Select
Return

~^v::
KeyWait,v
WinMenuSelectItem,A,,Edit,Begin/End Select
Return
knn
Posts: 30
Joined: 30 Mar 2020, 20:35

Re: Pasting without losing selection

01 May 2020, 18:14

vsub wrote:
01 May 2020, 13:21
This kinda work...most of the time

Code: Select all

~^c::
WinMenuSelectItem,A,,Edit,Begin/End Select
Doesn't work if the menu bar is hidden :(

Could it be done via Scintilla Control somehow?

I found https www.scintilla.org /ScintillaDoc.html#SelectionAndInformation. Broken Link for safety Could AHK use Scintilla directly to paste without losing the selection?
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: Pasting without losing selection

01 May 2020, 19:13

What about this

Code: Select all

^v::
	MouseMove, A_CaretX, A_CaretY, 0
	click down
	Send, ^v
	MouseMove, A_CaretX, A_CaretY, 0
	click up
return
knn
Posts: 30
Joined: 30 Mar 2020, 20:35

Re: Pasting without losing selection

02 May 2020, 03:28

GEV wrote: What about this

Code: Select all

^v::
	MouseMove, A_CaretX, A_CaretY, 0...
Your code doesn't work for me. Also I guess it would fail when the pasted text is long and scrolls the the screen.
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: Pasting without losing selection

02 May 2020, 09:35

This seems to be working here but it requires the Menu to be visible(unless you map a hotkey to the "Begin/End Select" from Settings=>Shortcut Mapper and then replace WinMenuSelectItem with the hotkey but with WinMenuSelectItem is more likely to work properly)

Select a text with the mouse and then paste it with ctrl+v

Code: Select all

SetWinDelay,-1
#IfWinActive,AHK_class Notepad++
~LButton::
MouseGetPoS,,,,Control
IfNotInstring,Control,Scintilla
Return
StatusBarGetText,Line,3,A
Line := SubStr(Line,6,InStr(Line,A_Space,,1,2))
StringReplace,Line,Line,% A_Space,,All
KeyWait,LButton
StatusBarGetText,Line1,3,A
Line1 := SubStr(Line1,6,InStr(Line1,A_Space,,1,2))
StringReplace,Line1,Line1,% A_Space,,All
If (Line > Line1)
{
Start := Line1
End := Line
}
Else
{
Start := Line
End := Line1
}
Return

~^v::
KeyWait,Ctrl
Sleep,100
StatusBarGetText,Line1,3,A
Line1 := SubStr(Line1,6,InStr(Line1,A_Space,,1,2))
StringReplace,Line1,Line1,% A_Space,,All
If (Line1 != End)
End := Line1
WinMenuSelectItem,AHK_class Notepad++,,Search,Go To
WinWaitActive,Go To...
ControlSetText,Edit1,% Start,A
Send,{Enter}
WinWaitClose,Go To...
WinMenuSelectItem,AHK_class Notepad++,,Edit,Begin/End Select
Sleep,50
WinMenuSelectItem,AHK_class Notepad++,,Search,Go To
WinWaitActive,Go To...
ControlSetText,Edit1,% End,A
Send,{Enter}
WinWaitClose,Go To...
WinMenuSelectItem,AHK_class Notepad++,,Edit,Begin/End Select
Return
knn
Posts: 30
Joined: 30 Mar 2020, 20:35

Re: Pasting without losing selection

02 May 2020, 23:42

vsub wrote:
02 May 2020, 09:35
This seems to be working here but it requires the Menu to be visible(unless you map a hotkey to the "Begin/End Select" from Settings=>Shortcut Mapper
I've added now a shortcut to Notepad++. Thank you for that tip. Now everything works.

Interestingly, sometimes clipboards do get messed up when I use SendInput, ^v, but when I use Send, ^v it always works.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mstrauss2021 and 337 guests