Skip to content

Commit

Permalink
Avoid exponential number of cursores in typing tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbueno committed Sep 23, 2021
1 parent 5fc65e9 commit a793ea5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions terminedia_paint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def handle_key(self, key):
self.advance_cursores()

def advance_cursores(self):
new_cursores = []
new_cursores = set()
for i, cursor in enumerate(self.cursores or (self.parent.pos,)):
if self.mode == "line":
new_cursores.append(cursor + self.direction)
new_cursores.add(cursor + self.direction)
else:
# the two cursores sub-list strategy is to avoid duplicating the cursores in
# a stepped corner in a single line: that is, if there is at least one straight path,
Expand All @@ -158,9 +158,9 @@ def advance_cursores(self):
new_pos = cursor + delta
if self.shape[new_pos].value == TM.values.FULL_BLOCK:
(new_cursores_straight if 0 in delta else new_cursores_diag).append(new_pos)
new_cursores.extend(new_cursores_straight or new_cursores_diag)
new_cursores.update(new_cursores_straight or new_cursores_diag)

self.cursores = new_cursores
self.cursores = list(new_cursores)

def backspace(self):
if not self.rendered:
Expand Down

0 comments on commit a793ea5

Please sign in to comment.