@@ -179,7 +179,7 @@ def keyPressEvent(self, e):
179
179
self .cursor = self .textCursor ()
180
180
# if the cursor isn't in the edition zone, don't do anything except Ctrl+C
181
181
if not self .isCursorInEditionZone ():
182
- if e .modifiers () == Qt .ControlModifier or e .modifiers () == Qt .MetaModifier :
182
+ if e .modifiers () & Qt .ControlModifier or e .modifiers () & Qt .MetaModifier :
183
183
if e .key () == Qt .Key_C or e .key () == Qt .Key_A :
184
184
QTextEdit .keyPressEvent (self , e )
185
185
else :
@@ -201,38 +201,22 @@ def keyPressEvent(self, e):
201
201
QTextEdit .keyPressEvent (self , e )
202
202
# if the left key is pressed, move left until we get to the prompt
203
203
elif e .key () == Qt .Key_Left and self .cursor .position () > self .document ().lastBlock ().position () + self .currentPromptLength :
204
- if e .modifiers () == Qt .ShiftModifier :
205
- anchor = QTextCursor .KeepAnchor
206
- else :
207
- anchor = QTextCursor .MoveAnchor
208
- if (e .modifiers () == Qt .ControlModifier or e .modifiers () == Qt .MetaModifier ):
209
- self .cursor .movePosition (QTextCursor .WordLeft , anchor )
210
- else :
211
- self .cursor .movePosition (QTextCursor .Left , anchor )
204
+ anchor = QTextCursor .KeepAnchor if e .modifiers () & Qt .ShiftModifier else QTextCursor .MoveAnchor
205
+ move = QTextCursor .WordLeft if e .modifiers () & Qt .ControlModifier or e .modifiers () & Qt .MetaModifier else QTextCursor .Left
206
+ self .cursor .movePosition (move , anchor )
212
207
# use normal operation for right key
213
208
elif e .key () == Qt .Key_Right :
214
- if e .modifiers () == Qt .ShiftModifier :
215
- anchor = QTextCursor .KeepAnchor
216
- else :
217
- anchor = QTextCursor .MoveAnchor
218
- if (e .modifiers () == Qt .ControlModifier or e .modifiers () == Qt .MetaModifier ):
219
- self .cursor .movePosition (QTextCursor .WordRight , anchor )
220
- else :
221
- self .cursor .movePosition (QTextCursor .Right , anchor )
209
+ anchor = QTextCursor .KeepAnchor if e .modifiers () & Qt .ShiftModifier else QTextCursor .MoveAnchor
210
+ move = QTextCursor .WordRight if e .modifiers () & Qt .ControlModifier or e .modifiers () & Qt .MetaModifier else QTextCursor .Right
211
+ self .cursor .movePosition (move , anchor )
222
212
# if home is pressed, move cursor to right of prompt
223
213
elif e .key () == Qt .Key_Home :
224
- if e .modifiers () == Qt .ShiftModifier :
225
- anchor = QTextCursor .KeepAnchor
226
- else :
227
- anchor = QTextCursor .MoveAnchor
214
+ anchor = QTextCursor .KeepAnchor if e .modifiers () & Qt .ShiftModifier else QTextCursor .MoveAnchor
228
215
self .cursor .movePosition (QTextCursor .StartOfBlock , anchor , 1 )
229
216
self .cursor .movePosition (QTextCursor .Right , anchor , self .currentPromptLength )
230
217
# use normal operation for end key
231
218
elif e .key () == Qt .Key_End :
232
- if e .modifiers () == Qt .ShiftModifier :
233
- anchor = QTextCursor .KeepAnchor
234
- else :
235
- anchor = QTextCursor .MoveAnchor
219
+ anchor = QTextCursor .KeepAnchor if e .modifiers () & Qt .ShiftModifier else QTextCursor .MoveAnchor
236
220
self .cursor .movePosition (QTextCursor .EndOfBlock , anchor , 1 )
237
221
# use normal operation for all remaining keys
238
222
else :
@@ -253,6 +237,7 @@ def insertFromMimeData(self, source):
253
237
254
238
def entered (self ):
255
239
self .cursor .movePosition (QTextCursor .End , QTextCursor .MoveAnchor )
240
+ self .setTextCursor (self .cursor )
256
241
self .runCommand ( unicode (self .currentCommand ()) )
257
242
258
243
def runCommand (self , cmd ):
0 commit comments