Skip to content

Commit eb93ab5

Browse files
committed
editor: Fix regression in handling Shift+Up/Shift+Down
1 parent 0561475 commit eb93ab5

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ReText/editor.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,39 +318,46 @@ def surroundText(self, cursor, event, key):
318318

319319
def keyPressEvent(self, event):
320320
key = event.key()
321+
modifiers = event.modifiers()
321322
cursor = self.textCursor()
322-
if key == Qt.Key.Key_Backspace and event.modifiers() & Qt.KeyboardModifier.GroupSwitchModifier:
323+
if key == Qt.Key.Key_Backspace and modifiers & Qt.KeyboardModifier.GroupSwitchModifier:
323324
# Workaround for https://bugreports.qt.io/browse/QTBUG-49771
324325
event = QKeyEvent(event.type(), event.key(),
325-
event.modifiers() ^ Qt.KeyboardModifier.GroupSwitchModifier)
326+
modifiers ^ Qt.KeyboardModifier.GroupSwitchModifier)
326327
if key == Qt.Key.Key_Tab:
327328
documentIndentMore(self.document(), cursor)
328329
elif key == Qt.Key.Key_Backtab:
329330
documentIndentLess(self.document(), cursor)
330331
elif key == Qt.Key.Key_Return:
331332
markupClass = self.tab.getActiveMarkupClass()
332-
if event.modifiers() & Qt.KeyboardModifier.ControlModifier:
333+
if modifiers & Qt.KeyboardModifier.ControlModifier:
333334
cursor.insertText('\n')
334335
self.ensureCursorVisible()
335336
elif self.tableModeEnabled and tablemode.handleReturn(cursor, markupClass,
336-
newRow=(event.modifiers() & Qt.KeyboardModifier.ShiftModifier)):
337+
newRow=(modifiers & Qt.KeyboardModifier.ShiftModifier)):
337338
self.setTextCursor(cursor)
338339
self.ensureCursorVisible()
339340
else:
340-
if event.modifiers() & Qt.KeyboardModifier.ShiftModifier and markupClass == MarkdownMarkup:
341+
if modifiers & Qt.KeyboardModifier.ShiftModifier and markupClass == MarkdownMarkup:
341342
# Insert Markdown-style line break
342343
cursor.insertText(' ')
343344
self.handleReturn(cursor)
344345
elif key == Qt.Key.Key_Up:
346+
mode = QTextCursor.MoveMode.MoveAnchor
347+
if modifiers & Qt.KeyboardModifier.ShiftModifier:
348+
mode = QTextCursor.MoveMode.KeepAnchor
345349
oldPos = cursor.position()
346-
self.moveCursor(QTextCursor.MoveOperation.Up)
350+
self.moveCursor(QTextCursor.MoveOperation.Up, mode)
347351
if self.textCursor().position() == oldPos:
348-
self.moveCursor(QTextCursor.MoveOperation.Start)
352+
self.moveCursor(QTextCursor.MoveOperation.Start, mode)
349353
elif key == Qt.Key.Key_Down:
354+
mode = QTextCursor.MoveMode.MoveAnchor
355+
if modifiers & Qt.KeyboardModifier.ShiftModifier:
356+
mode = QTextCursor.MoveMode.KeepAnchor
350357
oldPos = cursor.position()
351-
self.moveCursor(QTextCursor.MoveOperation.Down)
358+
self.moveCursor(QTextCursor.MoveOperation.Down, mode)
352359
if self.textCursor().position() == oldPos:
353-
self.moveCursor(QTextCursor.MoveOperation.End)
360+
self.moveCursor(QTextCursor.MoveOperation.End, mode)
354361
elif cursor.selectedText() and self.isSurroundKey(key):
355362
self.surroundText(cursor, event, key)
356363
else:

0 commit comments

Comments
 (0)