Skip to content

Commit

Permalink
Merge 7cda53c into 8e6be35
Browse files Browse the repository at this point in the history
  • Loading branch information
battaglia01 committed Jun 28, 2021
2 parents 8e6be35 + 7cda53c commit 9bcdf1f
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions qtconsole/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,21 @@ def _event_filter_console_keypress(self, event):
alt_down = event.modifiers() & QtCore.Qt.AltModifier
shift_down = event.modifiers() & QtCore.Qt.ShiftModifier

cmd_down = (
sys.platform == "darwin" and
self._control_key_down(event.modifiers(), include_command=True)
)
if cmd_down:
if key == QtCore.Qt.Key_Left:
key = QtCore.Qt.Key_Home
elif key == QtCore.Qt.Key_Right:
key = QtCore.Qt.Key_End
elif key == QtCore.Qt.Key_Up:
ctrl_down = True
key = QtCore.Qt.Key_Home
elif key == QtCore.Qt.Key_Down:
ctrl_down = True
key = QtCore.Qt.Key_End
#------ Special modifier logic -----------------------------------------

if key in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter):
Expand Down Expand Up @@ -1363,7 +1378,6 @@ def callback(complete, indent):

elif key == QtCore.Qt.Key_Up:
self._control.verticalScrollBar().setValue(0)

#------ Alt modifier ---------------------------------------------------

elif alt_down:
Expand Down Expand Up @@ -1415,14 +1429,14 @@ def callback(complete, indent):
self._keyboard_quit()
intercepted = True

elif key == QtCore.Qt.Key_Up:
elif key == QtCore.Qt.Key_Up and not shift_down:
if self._reading or not self._up_pressed(shift_down):
intercepted = True
else:
prompt_line = self._get_prompt_cursor().blockNumber()
intercepted = cursor.blockNumber() <= prompt_line

elif key == QtCore.Qt.Key_Down:
elif key == QtCore.Qt.Key_Down and not shift_down:
if self._reading or not self._down_pressed(shift_down):
intercepted = True
else:
Expand All @@ -1439,7 +1453,7 @@ def callback(complete, indent):
self._indent(dedent=True)
intercepted = True

elif key == QtCore.Qt.Key_Left:
elif key == QtCore.Qt.Key_Left and not shift_down:

# Move to the previous line
line, col = cursor.blockNumber(), cursor.columnNumber()
Expand All @@ -1455,7 +1469,7 @@ def callback(complete, indent):
else:
intercepted = not self._in_buffer(position - 1)

elif key == QtCore.Qt.Key_Right:
elif key == QtCore.Qt.Key_Right and not shift_down:
#original_block_number = cursor.blockNumber()
if position == self._get_line_end_pos():
cursor.movePosition(QtGui.QTextCursor.NextBlock, mode=anchormode)
Expand Down Expand Up @@ -1552,7 +1566,9 @@ def callback(complete, indent):
# position is still valid due to text truncation).
if not (self._control_key_down(event.modifiers(), include_command=True)
or key in (QtCore.Qt.Key_PageUp, QtCore.Qt.Key_PageDown)
or (self._executing and not self._reading)):
or (self._executing and not self._reading)
or (event.text() == "" and not
(not shift_down and key in (QtCore.Qt.Key_Up, QtCore.Qt.Key_Down)))):
self._keep_cursor_in_buffer()

return intercepted
Expand Down Expand Up @@ -2191,13 +2207,13 @@ def _insert_plain_text_into_buffer(self, cursor, text):
cursor.endEditBlock()

def _in_buffer(self, position):
"""
Returns whether the specified position is inside the editing region.
"""
Returns whether the specified position is inside the editing region.
"""
return position == self._move_position_in_buffer(position)

def _move_position_in_buffer(self, position):
"""
"""
Return the next position in buffer.
"""
cursor = self._control.textCursor()
Expand All @@ -2222,6 +2238,7 @@ def _keep_cursor_in_buffer(self):
"""
cursor = self._control.textCursor()
endpos = cursor.selectionEnd()

if endpos < self._prompt_pos:
cursor.setPosition(endpos)
line = cursor.blockNumber()
Expand Down

0 comments on commit 9bcdf1f

Please sign in to comment.