Skip to content

Commit 16983a8

Browse files
author
wonder
committedFeb 1, 2010
Fixed few problems in console:
- pressing enter if the cursor was not at the end - ctrl+shift to select words didn't work git-svn-id: http://svn.osgeo.org/qgis/trunk@12858 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent de4b239 commit 16983a8

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed
 

‎python/console.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def keyPressEvent(self, e):
179179
self.cursor = self.textCursor()
180180
# if the cursor isn't in the edition zone, don't do anything except Ctrl+C
181181
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:
183183
if e.key() == Qt.Key_C or e.key() == Qt.Key_A:
184184
QTextEdit.keyPressEvent(self, e)
185185
else:
@@ -201,38 +201,22 @@ def keyPressEvent(self, e):
201201
QTextEdit.keyPressEvent(self, e)
202202
# if the left key is pressed, move left until we get to the prompt
203203
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)
212207
# use normal operation for right key
213208
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)
222212
# if home is pressed, move cursor to right of prompt
223213
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
228215
self.cursor.movePosition(QTextCursor.StartOfBlock, anchor, 1)
229216
self.cursor.movePosition(QTextCursor.Right, anchor, self.currentPromptLength)
230217
# use normal operation for end key
231218
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
236220
self.cursor.movePosition(QTextCursor.EndOfBlock, anchor, 1)
237221
# use normal operation for all remaining keys
238222
else:
@@ -253,6 +237,7 @@ def insertFromMimeData(self, source):
253237

254238
def entered(self):
255239
self.cursor.movePosition(QTextCursor.End, QTextCursor.MoveAnchor)
240+
self.setTextCursor(self.cursor)
256241
self.runCommand( unicode(self.currentCommand()) )
257242

258243
def runCommand(self, cmd):

0 commit comments

Comments
 (0)
Please sign in to comment.