--- a/mercurial/crecord.py Thu Apr 28 10:37:47 2016 -0400
+++ b/mercurial/crecord.py Fri May 06 19:52:21 2016 +0800
@@ -111,17 +111,12 @@
def parentitem(self):
raise NotImplementedError("method must be implemented by subclass")
- def nextitem(self, constrainlevel=True, skipfolded=True):
+ def nextitem(self, skipfolded=True):
"""
- If constrainLevel == True, return the closest next item
- of the same type where there are no items of different types between
- the current item and this closest item.
+ Try to return the next item closest to this item, regardless of item's
+ type (header, hunk, or hunkline).
- If constrainLevel == False, then try to return the next item
- closest to this item, regardless of item's type (header, hunk, or
- HunkLine).
-
- If skipFolded == True, and the current item is folded, then the child
+ If skipfolded == True, and the current item is folded, then the child
items that are hidden due to folding will be skipped when determining
the next item.
@@ -131,9 +126,7 @@
itemfolded = self.folded
except AttributeError:
itemfolded = False
- if constrainlevel:
- return self.nextsibling()
- elif skipfolded and itemfolded:
+ if skipfolded and itemfolded:
nextitem = self.nextsibling()
if nextitem is None:
try:
@@ -164,39 +157,31 @@
except AttributeError: # parent and/or grandparent was None
return None
- def previtem(self, constrainlevel=True):
+ def previtem(self):
"""
- If constrainLevel == True, return the closest previous item
- of the same type where there are no items of different types between
- the current item and this closest item.
-
- If constrainLevel == False, then try to return the previous item
- closest to this item, regardless of item's type (header, hunk, or
- HunkLine).
+ Try to return the previous item closest to this item, regardless of
+ item's type (header, hunk, or hunkline).
If it is not possible to get the previous item, return None.
"""
- if constrainlevel:
- return self.prevsibling()
- else:
- # try previous sibling's last child's last child,
- # else try previous sibling's last child, else try previous sibling
- prevsibling = self.prevsibling()
- if prevsibling is not None:
- prevsiblinglastchild = prevsibling.lastchild()
- if ((prevsiblinglastchild is not None) and
- not prevsibling.folded):
- prevsiblinglclc = prevsiblinglastchild.lastchild()
- if ((prevsiblinglclc is not None) and
- not prevsiblinglastchild.folded):
- return prevsiblinglclc
- else:
- return prevsiblinglastchild
+ # try previous sibling's last child's last child,
+ # else try previous sibling's last child, else try previous sibling
+ prevsibling = self.prevsibling()
+ if prevsibling is not None:
+ prevsiblinglastchild = prevsibling.lastchild()
+ if ((prevsiblinglastchild is not None) and
+ not prevsibling.folded):
+ prevsiblinglclc = prevsiblinglastchild.lastchild()
+ if ((prevsiblinglclc is not None) and
+ not prevsiblinglastchild.folded):
+ return prevsiblinglclc
else:
- return prevsibling
+ return prevsiblinglastchild
+ else:
+ return prevsibling
- # try parent (or None)
- return self.parentitem()
+ # try parent (or None)
+ return self.parentitem()
class patch(patchnode, list): # todo: rename patchroot
"""
@@ -603,7 +588,7 @@
"""
currentitem = self.currentselecteditem
- nextitem = currentitem.previtem(constrainlevel=False)
+ nextitem = currentitem.previtem()
if nextitem is None:
# if no parent item (i.e. currentitem is the first header), then
@@ -619,8 +604,8 @@
parent-item of the currently selected item.
"""
currentitem = self.currentselecteditem
- nextitem = currentitem.previtem()
- # if there's no previous item on this level, try choosing the parent
+ nextitem = currentitem.prevsibling()
+ # if there's no previous sibling, try choosing the parent
if nextitem is None:
nextitem = currentitem.parentitem()
if nextitem is None:
@@ -641,7 +626,7 @@
#self.startprintline += 1 #debug
currentitem = self.currentselecteditem
- nextitem = currentitem.nextitem(constrainlevel=False)
+ nextitem = currentitem.nextitem()
# if there's no next item, keep the selection as-is
if nextitem is None:
nextitem = currentitem
@@ -655,17 +640,16 @@
same level as the parent item of the currently selected item.
"""
currentitem = self.currentselecteditem
- nextitem = currentitem.nextitem()
- # if there's no next item on this level, try choosing the parent's
- # nextitem.
+ nextitem = currentitem.nextsibling()
+ # if there's no next sibling, try choosing the parent's nextsibling
if nextitem is None:
try:
- nextitem = currentitem.parentitem().nextitem()
+ nextitem = currentitem.parentitem().nextsibling()
except AttributeError:
- # parentitem returned None, so nextitem() can't be called
+ # parentitem returned None, so nextsibling() can't be called
nextitem = None
if nextitem is None:
- # if no next item on parent-level, then no change...
+ # if parent has no next sibling, then no change...
nextitem = currentitem
self.currentselecteditem = nextitem