Skip to content

Commit

Permalink
Zones: Support rules matching multiple results
Browse files Browse the repository at this point in the history
Also fixes a rare issue where an async doc update moves the zone
away from the caret without canceling zone restriction.
  • Loading branch information
JulienCochuyt committed Oct 15, 2024
1 parent 427a6b5 commit f5c4d03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions addon/globalPlugins/webAccess/ruleHandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ def update(self, nodeManager=None, force=False):
self._ready = True
self.nodeManagerIdentifier = self.nodeManager.identifier
if self.zone is not None:
if not self.zone.update():
if not self.zone.update() or not self.zone.containsTextInfo(
self.nodeManager.treeInterceptor.makeTextInfo(textInfos.POSITION_CARET)
):
self.zone = None
#logTime("update marker", t)
if self.isReady:
Expand Down Expand Up @@ -577,14 +579,14 @@ def _getIncrementalResult(
or (
(
not respectZone
or self.zone.containsNode(result.node)
or self.zone.containsResult(result)
)
and not (
# If respecting zone restriction or iterating
# backwards relative to the caret position,
# avoid returning the current zone itself.
self.zone.name == result.rule.name
and self.zone.startOffset == result.node.offset
and self.zone.containsResult(result)
)
)
)
Expand Down Expand Up @@ -1489,6 +1491,7 @@ def __init__(self, result):
rule = result.rule
self._ruleManager = weakref.ref(rule.ruleManager)
self.name = rule.name
self.index = result.index
super().__init__(startOffset=None, endOffset=None)
self._update(result)

Expand Down Expand Up @@ -1575,8 +1578,9 @@ def restrictTextInfo(self, info):

def update(self):
try:
result = next(self.ruleManager.iterResultsByName(self.name))
except StopIteration:
# Result index is 1-based
result = self.ruleManager.iterResultsByName(self.name)[self.index - 1]
except IndexError:
self.startOffset = self.endOffset = None
return False
return self._update(result)
Expand Down
2 changes: 1 addition & 1 deletion addon/globalPlugins/webAccess/ruleHandler/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class PropertySpec(Enum):
isRestrictedChoice=True
)
multiple = PropertySpecValue(
ruleTypes=("marker",),
ruleTypes=("marker", "zone"),
valueType=bool,
default=False,
# Translators: The display name for a rule property
Expand Down

0 comments on commit f5c4d03

Please sign in to comment.