Skip to content

Commit 9760e69

Browse files
committed
Update positions of empty nodes when regular nodes are shifted.
1 parent a905028 commit 9760e69

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

udapi/core/node.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ def remove(self, children=None):
574574
def _shift_before_ord(self, reference_ord, without_children=False):
575575
"""Internal method for changing word order."""
576576
all_nodes = self._root._descendants
577+
empty_nodes = self._root.empty_nodes
577578

578579
# Moving a single node can be faster than nodes_to_move = [self]
579580
if without_children or not self._children:
@@ -584,14 +585,22 @@ def _shift_before_ord(self, reference_ord, without_children=False):
584585
all_nodes[i_ord - 1]._ord = i_ord
585586
all_nodes[reference_ord - 2] = self
586587
self._ord = reference_ord - 1
588+
for en in empty_nodes:
589+
if en._ord > my_ord and en._ord < reference_ord:
590+
en._ord -= 1
587591
elif reference_ord < my_ord:
588592
for i_ord in range(my_ord, reference_ord, -1):
589593
all_nodes[i_ord - 1] = all_nodes[i_ord - 2]
590594
all_nodes[i_ord - 1]._ord = i_ord
591595
all_nodes[reference_ord - 1] = self
592596
self._ord = reference_ord
597+
for en in empty_nodes:
598+
###!!! Empty nodes before the first overt token (ID=0.X) will be never moved this way. We cannot know whether the caller wanted to place the shifted node before or after them.
599+
if en._ord < my_ord and en._ord > reference_ord:
600+
en._ord += 1
593601
return
594602

603+
###!!! Updating ords of empty nodes is implemented for the simple case above but it has to be implemented also for the complex case below!
595604
nodes_to_move = self.descendants(add_self=True)
596605
first_ord, last_ord = nodes_to_move[0]._ord, nodes_to_move[-1]._ord
597606

0 commit comments

Comments
 (0)