-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Changed History: Go to Next/Prev block #12248
Comments
A proof of concept in PythonScript: def gotoLine(line):
editor.setVisiblePolicy(CARETPOLICY.JUMPS | CARETPOLICY.EVEN, 0)
editor.ensureVisibleEnforcePolicy(line)
editor.gotoLine(line)
editor.setVisiblePolicy(CARETPOLICY.EVEN, 0)
editor.ensureVisibleEnforcePolicy(line)
def gotoNextChange(self):
line = -1
pos = editor.getCurrentPos()
searchStart = editor.lineFromPosition(pos)
### `markerNext` doesn't work on ChangeHistory:
# https://sourceforge.net/p/scintilla/bugs/2353/
lastLine = editor.lineFromPosition(editor.getTextLength())
consec = searchStart
for ln in range(searchStart+1, lastLine+1):
if editor.markerGet(ln) & self._mask:
if ln == consec + 1:
consec += 1
else:
line = ln
break
if line == -1:
for ln in range(0, searchStart):
if editor.markerGet(ln) & self._mask:
if ln == consec + 1:
consec += 1
else:
line = ln
break
if line != -1:
gotoLine(line)
def gotoPrevChange(self):
line = -1
pos = editor.getCurrentPos()
searchStart = editor.lineFromPosition(pos)
while True:
line = editor.markerPrevious(searchStart - 1, self._mask)
if line == -1:
break
if line == (searchStart - 1):
searchStart -= 1
else:
break
if line == -1:
end = editor.getLineCount()
line = editor.markerPrevious(end, self._mask)
if line != -1:
gotoLine(line) Cheers. |
Thank you for the nice script. 👍 |
Sorry, it's a proof of concept - extracted from my larger working script. I can try to make is fully functional: from Npp import editor, CARETPOLICY
class ChangeHistoryGoTo(object):
def __init__(self):
self._mask = (1 << 21) | (1 << 22) | (1 << 23) | (1 << 24)
def _goto_line(self, line):
editor.setVisiblePolicy(CARETPOLICY.JUMPS | CARETPOLICY.EVEN, 0)
editor.ensureVisibleEnforcePolicy(line)
editor.gotoLine(line)
editor.setVisiblePolicy(CARETPOLICY.EVEN, 0)
editor.ensureVisibleEnforcePolicy(line)
def gotoNextChange(self):
line = -1
pos = editor.getCurrentPos()
searchStart = editor.lineFromPosition(pos)
### `markerNext` doesn't work on ChangeHistory:
# https://sourceforge.net/p/scintilla/bugs/2353/
lastLine = editor.lineFromPosition(editor.getTextLength())
consec = searchStart
for ln in range(searchStart+1, lastLine+1):
if editor.markerGet(ln) & self._mask:
if ln == consec + 1:
consec += 1
else:
line = ln
break
if line == -1:
for ln in range(0, searchStart):
if editor.markerGet(ln) & self._mask:
if ln == consec + 1:
consec += 1
else:
line = ln
break
if line != -1:
self._goto_line(line)
def gotoPrevChange(self):
line = -1
pos = editor.getCurrentPos()
searchStart = editor.lineFromPosition(pos)
while True:
line = editor.markerPrevious(searchStart - 1, self._mask)
if line == -1:
break
if line == (searchStart - 1):
searchStart -= 1
else:
break
if line == -1:
end = editor.getLineCount()
line = editor.markerPrevious(end, self._mask)
if line != -1:
self._goto_line(line)
if __name__ == '__main__':
chgt = ChangeHistoryGoTo() Run from the PythonScript menu, then from the PythonScript console: chgt.gotoNextChange()
chgt.gotoPrevChange() Cheers. |
A-ha, I'm using 3.0.14 |
Well, I'll wait for the integration of the feature in NPP. Thanks again. |
Try again, I removed the |
It works like a charm! Thank you. |
Yes, that's key, otherwise it'll stop at every change line and if there are 20 new lines inserted in a row, you just want to stop at the top (next) or bottom (previous) - not each and every one. Cheers. |
Thanks again for the beautiful script. 👍 Slightly adapted for my personal use. :) # Based on https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12248#issuecomment-1258561261.
class ChangeHistoryGoTo():
def __init__(self):
self._mask = (1 << 21) | (1 << 22) | (1 << 23) | (1 << 24)
self._currentLine = editor.lineFromPosition(editor.getCurrentPos())
def _goto_line(self, line):
if line != -1 and line != self._currentLine:
editor.ensureVisibleEnforcePolicy(line)
editor.gotoLine(line)
else:
import winsound
winsound.MessageBeep()
#----------------#
def gotoNextOrFirstChange(self, gotoFirst):
line = -1
searchStartLine = self._currentLine
lastLine = editor.getLineCount()
if not gotoFirst:
for searchLine in range(self._currentLine, lastLine): # Start from currentLine (not currentLine + 1) in case currentLine is not-changed and the next line IS changed.
if editor.markerGet(searchLine) & self._mask:
if searchLine != searchStartLine: # changed-line found in a different block.
line = searchLine
break
else:
searchStartLine += 1
if line == -1:
for searchLine in range(0, lastLine if gotoFirst else self._currentLine): # Wrap around.
if editor.markerGet(searchLine) & self._mask:
line = searchLine
break
self._goto_line(line)
#----------------#
def gotoPrevChange(self):
line = -1
searchStartLine = self._currentLine
while True:
line = editor.markerPrevious(searchStartLine, self._mask)
if line == -1 or line != searchStartLine: # "line == -1": no changed-line found. "line != searchStartLine": changed-line found in a different block.
break
else:
searchStartLine -= 1
if line == -1:
line = editor.markerPrevious(editor.getLineCount(), self._mask) # Wrap around.
self._goto_line(line)
#-------------------------------------------------------------------------------#
changeHistory = ChangeHistoryGoTo()
if clickButton == 0:
changeHistory.gotoNextOrFirstChange(False) # Next.
elif clickButton == 1:
changeHistory.gotoNextOrFirstChange(True) # First.
else:
changeHistory.gotoPrevChange() |
@Yaron10 |
Yes, it is.
Yes, I think it should be per file. And we should jump from block to block: I've implemented it in C++. Please ignore my // Based on https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12248#issuecomment-1258561261.
void Notepad_plus::changedHistoryGoTo(int idGoTo)
{
int mask = (1 << 21) | (1 << 22) | (1 << 23) | (1 << 24);
intptr_t line = -1;
intptr_t blockIndicator = _pEditView->getCurrentLineNumber();
intptr_t lastLine = _pEditView->execute(SCI_GETLINECOUNT);
if (idGoTo != IDM_SEARCH_CHANGED_PREV) // Next or First.
{
intptr_t currentLine = blockIndicator;
if (idGoTo == IDM_SEARCH_CHANGED_NEXT)
{
// Start from currentLine (not currentLine + 1) in case currentLine is not-changed and the next line IS changed. lastLine is at least *1*.
for (intptr_t i = currentLine; i < lastLine; i++)
if (_pEditView->execute(SCI_MARKERGET, i) & mask)
{
if (i != blockIndicator) // Changed-line found in a different block.
{
line = i;
break;
}
else
blockIndicator++;
}
}
if (line == -1) // Wrap around.
{
intptr_t endRange = (idGoTo == IDM_SEARCH_CHANGED_NEXT) ? currentLine + 1 : lastLine; // "+ 1": currentLine might be *0*.
for (intptr_t i = 0; i < endRange; i++)
if (_pEditView->execute(SCI_MARKERGET, i) & mask)
{
line = i;
if (idGoTo == IDM_SEARCH_CHANGED_NEXT)
::MessageBeep(MB_OK);
else if (i == currentLine)
::MessageBeep(MB_ICONINFORMATION);
break;
}
}
}
else // Prev.
{
while (true)
{
line = _pEditView->execute(SCI_MARKERPREVIOUS, blockIndicator, mask);
// "line == -1": no changed-line found. "line != blockIndicator": changed-line found in a different block.
if (line == -1 || line != blockIndicator)
break;
else
blockIndicator--;
}
if (line == -1) // Wrap around.
{
line = _pEditView->execute(SCI_MARKERPREVIOUS, lastLine - 1, mask);
if (line != -1)
::MessageBeep(MB_OK);
}
}
if (line != -1)
{
_pEditView->execute(SCI_ENSUREVISIBLEENFORCEPOLICY, line);
_pEditView->execute(SCI_GOTOLINE, line);
}
else
::MessageBeep(MB_ICONEXCLAMATION);
} |
I would say "Go to Previous Change" & "Go to Next Change" - what do you think? I will integrate your code and do a PR - if you still don't want to do a PR. |
If you're planing to place the commands directly under Search, "Go to Next/Prev Change" would be better. It's @vinsworldcom's code. I'd be glad if you could do the PR. Thank you! |
Sorry, away this weekend no computer access.
Sounds like the example would be from
https://github.com/vinsworldcom/nppChangedLines
Cheers.
…On Sun, Jul 2, 2023, 4:50 PM Yaron10 ***@***.***> wrote:
@donho <https://github.com/donho>,
If you're planing to place the commands directly under Search, "Go to
Next/Prev Change" would be better.
If the commands should be under a "Change History" popup (before or after
"Bookmarks"?), "Go to Next/Prev Block" might be better.
As you understand.
It's @vinsworldcom <https://github.com/vinsworldcom>'s code. I'd be glad
if you could do the PR.
Thank you!
—
Reply to this email directly, view it on GitHub
<#12248 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJVWUMLJYUL336BKHSZRBDXOHNJ7ANCNFSM6AAAAAAQWDFD4M>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@vinsworldcom |
Most of the original code was from before changed. History was included in
notepad Plus Plus and I "borrowed" it from location navigate plugin.
…On Sun, Jul 2, 2023, 6:21 PM Don HO ***@***.***> wrote:
Sorry, away this weekend no computer access. Sounds like the example would
be from https://github.com/vinsworldcom/nppChangedLines
@vinsworldcom <https://github.com/vinsworldcom>
Nice plugin! Is there any reason for Changed Lines plugin not being
included in NppPluginList ?
—
Reply to this email directly, view it on GitHub
<#12248 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJVWUIJKHDXE4RNJ3AKIQTXOHX7DANCNFSM6AAAAAAQWDFD4M>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I think it's still worth to add it into plugin admin. Do you mind to add it? |
The Changed Lines plugin predates "Change History" in Scintilla/Notepad++. Now that change history is here, the plugin offers too much redundancy and should be retired. I believe @vinsworldcom agrees. Spreading the word about the plugin, i.e., offering via Plugins Admin is IMO a bad idea. |
@vinsworldcom @alankilborn |
There's a nice "Clear Change History" command in @vinsworldcom's plugin. |
Then this would be a good idea for a feature within Notepad++ itself. :-) |
If such feature can be in Change Lines plugin, it can be built-in feature in Notepad++. |
Great. 👍
How about putting it in a "Change History" popup under Search? Thank you. |
Another question: |
I'll see what I can do about it. |
popup = submenu
Disabled makes good sense. Beep is OK, but disabled is better IMO. |
👍 I just want to point out that the Bookmarks commands are enabled even if the margin is not displayed.
I was joking. I knew you and Don wouldn't like the beep. |
Are some new issues going in? :-) I'd say that the proposed new features should be done correctly from the start, i.e., don't use existing bad behavior as something to align with. |
👍 Actually my analogy was completely wrong: you can create and go-to bookmarks even if the margin is not displayed. "Clear History of the Current Document" or "Clear Current Document History"? |
Just be aware that to do that, you lose your undo buffer. |
The plugin does a little few things beyond the existing Notepad++ support for Scintilla Change History - that's why I kept it. I did strip out the entire change tracking that was implemented. The "extras" are:
All of this is described in the README. Most could be done with PythonScripts. Not sure how much appetite there is for porting any of this "natively" to Notepad++. I like the extra features and use them so will continue to use the plugin as more of an add-on to existing capability (something I usually do with PythonScripts) vs. adding a brand new unique capability - as this did before Scintilla Change History. As I said, the original code was "borrowed" from Location Navigate plugin, but since change tracking is out of the plugin now - most of the remaining code I wrote and you can do with it what you like. Happy to see some of all of this move to Notepad++. Cheers. |
Add Go to next/prev change & clear change history commands. Fix notepad-plus-plus#12248
Add Go to next/prev change & clear change history commands. Fix notepad-plus-plus#12248
"Changed History" margin was introduced in NPP 8.4.6.
Two menu commands "Go to Next/Prev block" would be a useful addition to that new feature.
Thank you.
The text was updated successfully, but these errors were encountered: