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 Jul 25, 2024
1 parent 09f4662 commit edc58eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion addon/globalPlugins/webAccess/gui/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
ruleTypes.PAGE_TITLE_2: "customValue",
ruleTypes.ZONE:
(
"autoAction", "formMode",
"autoAction", "multiple", "formMode",
"skip", "sayName",
"customName", "customValue",
"mutation", "subModule"
Expand Down
16 changes: 10 additions & 6 deletions addon/globalPlugins/webAccess/ruleHandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# See the file COPYING.txt at the root of this distribution for more details.


__version__ = "2024.07.19"
__version__ = "2024.07.22"
__author__ = "Frédéric Brugnot <[email protected]>"


Expand Down Expand Up @@ -381,7 +381,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 @@ -570,14 +572,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 @@ -1597,6 +1599,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 @@ -1683,8 +1686,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
1 change: 1 addition & 0 deletions addon/globalPlugins/webAccess/ruleHandler/ruleTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
),
ZONE: (
"autoAction",
"multiple",
"formMode",
"skip",
"sayName",
Expand Down

0 comments on commit edc58eb

Please sign in to comment.