Skip to content

Commit

Permalink
Create a new method to handle close parens
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Jun 15, 2015
1 parent 7013d91 commit 16c5e6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
11 changes: 2 additions & 9 deletions spyderlib/widgets/sourcecode/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,8 @@ def keyPressEvent(self, event):
if self.type_list[self.currentRow()] not in ['class', 'function',
'method']:
return
edit = self.textedit
s_trailing_text = edit.get_text('cursor', 'eol').strip()
if edit.close_parentheses_enabled and \
(len(s_trailing_text) == 0 or \
s_trailing_text[0] in (',', ')', ']', '}')):
edit.insert_text('()')
cursor = edit.textCursor()
cursor.movePosition(QTextCursor.PreviousCharacter)
edit.setTextCursor(cursor)
if self.textedit.close_parentheses_enabled:
self.textedit.handle_close_parentheses('')
elif key in (Qt.Key_Return, Qt.Key_Enter,
Qt.Key_Left, Qt.Key_Right) or text in ('.', ':'):
self.hide()
Expand Down
32 changes: 18 additions & 14 deletions spyderlib/widgets/sourcecode/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2572,20 +2572,8 @@ def keyPressEvent(self, event):
self.stdkey_end(shift, ctrl)
elif text == '(' and not self.has_selected_text():
self.hide_completion_widget()
position = self.get_position('cursor')
s_trailing_text = self.get_text('cursor', 'eol').strip()
if self.close_parentheses_enabled and \
(len(s_trailing_text) == 0 or \
s_trailing_text[0] in (',', ')', ']', '}')):
self.insert_text('()')
cursor = self.textCursor()
cursor.movePosition(QTextCursor.PreviousCharacter)
self.setTextCursor(cursor)
else:
self.insert_text(text)
if self.is_python_like() and self.get_text('sol', 'cursor') and \
self.calltips:
self.sig_show_object_info.emit(position)
if self.close_parentheses_enabled:
self.handle_close_parentheses(text)
elif text in ('[', '{') and not self.has_selected_text() \
and self.close_parentheses_enabled:
s_trailing_text = self.get_text('cursor', 'eol').strip()
Expand Down Expand Up @@ -2654,6 +2642,22 @@ def keyPressEvent(self, event):
if self.is_completion_widget_visible() and text:
self.completion_text += text

def handle_close_parentheses(self, text):
if not self.close_parentheses_enabled:
return
position = self.get_position('cursor')
rest = self.get_text('cursor', 'eol').rstrip()
if (len(rest) == 0 or rest[0] in (',', ')', ']', '}')):
self.insert_text('()')
cursor = self.textCursor()
cursor.movePosition(QTextCursor.PreviousCharacter)
self.setTextCursor(cursor)
else:
self.insert_text(text)
if self.is_python_like() and self.get_text('sol', 'cursor') and \
self.calltips:
self.sig_show_object_info.emit(position)

def mouseMoveEvent(self, event):
"""Underline words when pressing <CONTROL>"""
if self.has_selected_text():
Expand Down

0 comments on commit 16c5e6e

Please sign in to comment.