From fadcb09b0a6bfb3050ee3bd1f76df727c0aac130 Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 25 Oct 2024 12:06:53 -0400 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- spyder/widgets/mixins.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/spyder/widgets/mixins.py b/spyder/widgets/mixins.py index 29b25a60b6f..aa9577bda52 100644 --- a/spyder/widgets/mixins.py +++ b/spyder/widgets/mixins.py @@ -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):