@@ -318,39 +318,46 @@ def surroundText(self, cursor, event, key):
318
318
319
319
def keyPressEvent (self , event ):
320
320
key = event .key ()
321
+ modifiers = event .modifiers ()
321
322
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 :
323
324
# Workaround for https://bugreports.qt.io/browse/QTBUG-49771
324
325
event = QKeyEvent (event .type (), event .key (),
325
- event . modifiers () ^ Qt .KeyboardModifier .GroupSwitchModifier )
326
+ modifiers ^ Qt .KeyboardModifier .GroupSwitchModifier )
326
327
if key == Qt .Key .Key_Tab :
327
328
documentIndentMore (self .document (), cursor )
328
329
elif key == Qt .Key .Key_Backtab :
329
330
documentIndentLess (self .document (), cursor )
330
331
elif key == Qt .Key .Key_Return :
331
332
markupClass = self .tab .getActiveMarkupClass ()
332
- if event . modifiers () & Qt .KeyboardModifier .ControlModifier :
333
+ if modifiers & Qt .KeyboardModifier .ControlModifier :
333
334
cursor .insertText ('\n ' )
334
335
self .ensureCursorVisible ()
335
336
elif self .tableModeEnabled and tablemode .handleReturn (cursor , markupClass ,
336
- newRow = (event . modifiers () & Qt .KeyboardModifier .ShiftModifier )):
337
+ newRow = (modifiers & Qt .KeyboardModifier .ShiftModifier )):
337
338
self .setTextCursor (cursor )
338
339
self .ensureCursorVisible ()
339
340
else :
340
- if event . modifiers () & Qt .KeyboardModifier .ShiftModifier and markupClass == MarkdownMarkup :
341
+ if modifiers & Qt .KeyboardModifier .ShiftModifier and markupClass == MarkdownMarkup :
341
342
# Insert Markdown-style line break
342
343
cursor .insertText (' ' )
343
344
self .handleReturn (cursor )
344
345
elif key == Qt .Key .Key_Up :
346
+ mode = QTextCursor .MoveMode .MoveAnchor
347
+ if modifiers & Qt .KeyboardModifier .ShiftModifier :
348
+ mode = QTextCursor .MoveMode .KeepAnchor
345
349
oldPos = cursor .position ()
346
- self .moveCursor (QTextCursor .MoveOperation .Up )
350
+ self .moveCursor (QTextCursor .MoveOperation .Up , mode )
347
351
if self .textCursor ().position () == oldPos :
348
- self .moveCursor (QTextCursor .MoveOperation .Start )
352
+ self .moveCursor (QTextCursor .MoveOperation .Start , mode )
349
353
elif key == Qt .Key .Key_Down :
354
+ mode = QTextCursor .MoveMode .MoveAnchor
355
+ if modifiers & Qt .KeyboardModifier .ShiftModifier :
356
+ mode = QTextCursor .MoveMode .KeepAnchor
350
357
oldPos = cursor .position ()
351
- self .moveCursor (QTextCursor .MoveOperation .Down )
358
+ self .moveCursor (QTextCursor .MoveOperation .Down , mode )
352
359
if self .textCursor ().position () == oldPos :
353
- self .moveCursor (QTextCursor .MoveOperation .End )
360
+ self .moveCursor (QTextCursor .MoveOperation .End , mode )
354
361
elif cursor .selectedText () and self .isSurroundKey (key ):
355
362
self .surroundText (cursor , event , key )
356
363
else :
0 commit comments