Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Cordoba <ccordoba12@gmail.com>
  • Loading branch information
athompson673 and ccordoba12 authored Oct 25, 2024
1 parent 82835d7 commit fadcb09
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions spyder/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,20 +1504,24 @@ def _enter_array(self, inline):

# ---- Qt methods
def mouseDoubleClickEvent(self, event):
"""select NUMBER tokens to select numeric literals on double click"""
cur = self.cursorForPosition(event.pos())
block = cur.block()
"""Select NUMBER tokens to select numeric literals on double click."""
cursor = self.cursorForPosition(event.pos())
block = cursor.block()
text = block.text()
pos = block.position()
pos_in_block = cur.positionInBlock()
pos_in_block = cursor.positionInBlock()

for t_type, _, start, end, _ in generate_tokens(StringIO(text).read):
if t_type == NUMBER and start[1] <= pos_in_block <= end[1]:
cur.setPosition(pos + start[1])
cur.setPosition(pos + end[1], QTextCursor.MoveMode.KeepAnchor)
self.setTextCursor(cur)
cursor.setPosition(pos + start[1])
cursor.setPosition(
pos + end[1], QTextCursor.MoveMode.KeepAnchor
)
self.setTextCursor(cursor)
return
elif start[1] > pos_in_block:
break

if isinstance(self, QPlainTextEdit):
QPlainTextEdit.mouseDoubleClickEvent(self, event)
elif isinstance(self, QTextEdit):
Expand Down

0 comments on commit fadcb09

Please sign in to comment.