Snapshot/History State in Notepad++ ?
-
- Posts: 844
- Joined: 21 Dec 2015, 02:34
Re: Snapshot/History State in Notepad++ ?
awesome. but yeah, it's failing on larger text files of 1000 lines or more. Especially if it has to scroll down like 1,000 lines down to re-insert the caret - you can watch the scrollbar automatically scroll down to return its position so maybe this where the keys are misfiring......
Re: Snapshot/History State in Notepad++ ?
It doesn’t matter if some of the keys are misfiring if you have a positive-feedback loop. Don’t just determine the number of down arrows required and send that many. Keep sending them until the status bar reads the row number it’s supposed to.
-
- Posts: 844
- Joined: 21 Dec 2015, 02:34
Re: Snapshot/History State in Notepad++ ?
ah, I see. It'll be a loop until it reaches the line and column, instead of sending all those keys. I'll work on this a bit further and report back later on
Re: Snapshot/History State in Notepad++ ?
I understand that you were asking about NPP, but such a feature is offered by git to perfection. You might want to take a look at it. I use git with github desktop (and a GitHub account, but that is not needed if you donˋt want a remote backup)
ciao
toralf
toralf
-
- Posts: 844
- Joined: 21 Dec 2015, 02:34
Re: Snapshot/History State in Notepad++ ?
thanks toralf, I'm going to check out git in a few minutes.
In the meantime, I think I have this working now. But it seems like a hack job at best.
If the text file has 1000's of lines, and the snapshot was taken while the cursor was active at line 1200 (as an example), and then the text file was altered a little bit by maybe typing in a few extra lines, and then we restore the snapshot using the hotkey, the problem now is that the script scans every line from 0-1200 before it returns the cursor to its original position (which ultimately was at line 1200, and it takes quite a while watching the cursor go down line-by-line until it reaches its destination).
For anyone who can try out this script, thanks - just create a text file with maybe 2,000 lines of jibberish in it, and then go to, say, line 1200 and take the snapshot using the hotkey. Then, alter the text a little bit (cut/paste or type some xtra jibberish anywhere in it) and then restore the text using the second hotkey - now it should restore the text to the point at where you took the original snapshot and also return the cursor to line 1200. But it takes forever to get there.
Is this pretty well the only way to do this in Notepad++ ? Thanks for checking..
In the meantime, I think I have this working now. But it seems like a hack job at best.
If the text file has 1000's of lines, and the snapshot was taken while the cursor was active at line 1200 (as an example), and then the text file was altered a little bit by maybe typing in a few extra lines, and then we restore the snapshot using the hotkey, the problem now is that the script scans every line from 0-1200 before it returns the cursor to its original position (which ultimately was at line 1200, and it takes quite a while watching the cursor go down line-by-line until it reaches its destination).
For anyone who can try out this script, thanks - just create a text file with maybe 2,000 lines of jibberish in it, and then go to, say, line 1200 and take the snapshot using the hotkey. Then, alter the text a little bit (cut/paste or type some xtra jibberish anywhere in it) and then restore the text using the second hotkey - now it should restore the text to the point at where you took the original snapshot and also return the cursor to line 1200. But it takes forever to get there.
Is this pretty well the only way to do this in Notepad++ ? Thanks for checking..
Code: Select all
#IfWinActive, ahk_class Notepad++
^k:: ; take snapshot
;get the position of the caret(cursor):
StatusBarGetText, StatusPt3, 3, ahk_exe notepad++.exe
StatusPt3 := StrReplace(StatusPt3, ",")
RegExMatch(StatusPt3, "Ln : (\d+) *Col : (\d+)", Match)
Tooltip, SNAPSHOT TAKEN
SetTimer, TooltipOff, 500
ControlGetText, tx, Scintilla1, ahk_class Notepad++
return
^m:: ; restore snapshot
Tooltip, SNAPSHOT RESTORED
SetTimer, TooltipOff, 500
ClipSaved := ClipBoardAll
ClipBoard := tx
Sleep, 100
ControlSend, Scintilla1, ^a^v, ahk_class Notepad++ ;select all, then paste
Sleep, 500
ClipBoard := ClipSaved
sleep, 500
winactivate, ahk_class Notepad++
sleep, 250
sendinput, {ctrl down}
sendinput, {home}
sendinput, {ctrl up}
sleep, 50
Loop
{
StatusBarGetText, StatusPt3, 3, ahk_exe notepad++.exe
StatusPt3 := StrReplace(StatusPt3, ",")
RegExMatch(StatusPt3, "Ln : (\d+) *Col : (\d+)", Lighter)
if (Match1 = Lighter1)
{
Match2-=1
sendinput, {right %Match2%}
break
winactivate, ahk_class Notepad++
}
else
{
sendinput, {down}
}
}
return
#If
TooltipOff:
tooltip,
Return
Re: Snapshot/History State in Notepad++ ?
With the scintilla api you can send messages to the control and also receive answers/information. E.g. get/set the current visible line and cursor on line.
I‘m currently not at my pc, so I can’t post you sample code. But I posted my AHK project manager a few months ago in the script section. Part of that manager is a wrapper for the api. I believe the file is called NPPM.ahk just look for it in the Manager include files.
I‘m currently not at my pc, so I can’t post you sample code. But I posted my AHK project manager a few months ago in the script section. Part of that manager is a wrapper for the api. I believe the file is called NPPM.ahk just look for it in the Manager include files.
ciao
toralf
toralf
Re: Snapshot/History State in Notepad++ ?
The Scintilla API would be best, but you can also instantly jump to the line number you want like this:
Here it is implemented in your script:
The reason I left it in a loop is just in case it misfires, it will try again, but it will likely work the first time and immediately move to that line.
Code: Select all
Send, ^g
WinWaitActive, Go To... ahk_class #32770,, 1
if !ErrorLevel
Send, % Match1 "{Enter}"
Code: Select all
#IfWinActive, ahk_class Notepad++
^k:: ; take snapshot
;get the position of the caret(cursor):
StatusBarGetText, StatusPt3, 3, ahk_exe notepad++.exe
StatusPt3 := StrReplace(StatusPt3, ",")
RegExMatch(StatusPt3, "Ln : (\d+) *Col : (\d+)", Match)
Tooltip, SNAPSHOT TAKEN
SetTimer, TooltipOff, 500
ControlGetText, tx, Scintilla1, ahk_class Notepad++
return
^m:: ; restore snapshot
Tooltip, SNAPSHOT RESTORED
SetTimer, TooltipOff, 500
ClipSaved := ClipBoardAll
ClipBoard := tx
Sleep, 100
ControlSend, Scintilla1, ^a^v, ahk_class Notepad++ ;select all, then paste
Sleep, 500
ClipBoard := ClipSaved
sleep, 500
winactivate, ahk_class Notepad++
sleep, 250
sendinput, {ctrl down}
sendinput, {home}
sendinput, {ctrl up}
sleep, 50
Loop
{
StatusBarGetText, StatusPt3, 3, ahk_exe notepad++.exe
StatusPt3 := StrReplace(StatusPt3, ",")
RegExMatch(StatusPt3, "Ln : (\d+) *Col : (\d+)", Lighter)
Send, ^g
WinWaitActive, Go To... ahk_class #32770,, 1
if !ErrorLevel
Send, % Match1 "{Enter}"
if (Match1 = Lighter1)
{
Match2-=1
sendinput, {right %Match2%}
winactivate, ahk_class Notepad++ ; moved this line up one since it wouldn't get executed after the break line (but it's not needed anyway)
break
}
else
sendinput, {down}
}
return
#If
TooltipOff:
tooltip,
Return
-
- Posts: 844
- Joined: 21 Dec 2015, 02:34
Re: Snapshot/History State in Notepad++ ?
thanks guys!
Well it looks like this script is working now. All the sleep commands are in there just to safeguard against any problems, I'm sure they can be adjusted or maybe eliminated altogether depending on each individual's system. Yeah it's a little hack-ish but hey what can you do lol.
Well it looks like this script is working now. All the sleep commands are in there just to safeguard against any problems, I'm sure they can be adjusted or maybe eliminated altogether depending on each individual's system. Yeah it's a little hack-ish but hey what can you do lol.
Code: Select all
#IfWinActive, ahk_class Notepad++
^k:: ; take snapshot
;get the position of the caret(cursor):
StatusBarGetText, StatusPt3, 3, ahk_exe notepad++.exe
StatusPt3 := StrReplace(StatusPt3, ",")
RegExMatch(StatusPt3, "Ln : (\d+) *Col : (\d+)", Match)
Tooltip, SNAPSHOT TAKEN
SetTimer, TooltipOff, 500
ControlGetText, tx, Scintilla1, ahk_class Notepad++
return
^m:: ; restore snapshot
Tooltip, SNAPSHOT RESTORED
SetTimer, TooltipOff, 500
ClipSaved := ClipBoardAll
ClipBoard := tx
Sleep, 100
ControlSend, Scintilla1, ^a^v, ahk_class Notepad++ ;select all, then paste
Sleep, 250
ClipBoard := ClipSaved
sleep, 250
winactivate, ahk_class Notepad++
sleep, 250
sendinput, {ctrl down}
sendinput, {home}
sendinput, {ctrl up}
sleep, 50
StatusBarGetText, StatusPt3, 3, ahk_exe notepad++.exe
StatusPt3 := StrReplace(StatusPt3, ",")
RegExMatch(StatusPt3, "Ln : (\d+) *Col : (\d+)", Lighter)
Send, ^g
WinWaitActive, Go To...
Sendinput, %Match1%
sleep, 250
Sendinput, {Enter}
sleep, 250
Match2-=1
sendinput, {right %Match2%}
return
#If
TooltipOff:
tooltip,
Return
Re: Snapshot/History State in Notepad++ ?
Hello,
regarding get current line and jump back to it, you can also use this function:
By the way, does anybody know how to find text by using such a function?
I found this:
SCI_FINDTEXT
SCI_SEARCHINTARGET
https://www.scintilla.org/ScintillaDoc.html#SCI_SEARCHINTARGET
But got no idea how to implement it.
Cheers!
regarding get current line and jump back to it, you can also use this function:
Code: Select all
;NPP-Minimal
#SingleInstance, force
F1::
currentLineNumber := NPPM_GETCURRENTLINE()
return
F2::
SCI_GotoLine(currentLineNumber)
return
NPPM_GETCURRENTLINE() ; 4032
{
return 1 + DllCall("SendMessage", "Ptr", Nppm_Hwnd(), "UInt", 4032 , "Int", 0, "Int", 0) ; Force 1 based line-system
}
SCI_GotoLine(Line)
{
DllCall("SendMessage", "Ptr", SCI_HWND(), "UInt", 2024 , "Int", Line - 1, "Int", 0)
}
Nppm_HWND(Title := "Notepad++")
{
return DllCall("FindWindow", "Str", Title, "Int", 0, "Ptr")
}
SCI_HWND()
{
ControlGet hSci, Hwnd,, Scintilla1, % "ahk_id" Nppm_HWND() ; If it doesn't work, replace Scintilla1 by Scintilla2
return hSci
}
I found this:
SCI_FINDTEXT
SCI_SEARCHINTARGET
https://www.scintilla.org/ScintillaDoc.html#SCI_SEARCHINTARGET
But got no idea how to implement it.
Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Who is online
Users browsing this forum: FanaticGuru and 150 guests