Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def indent(self):
- # Grab the cursor
- cursor = self.text.textCursor()
- if cursor.hasSelection():
- # Store the current line/block number
- temp = cursor.blockNumber()
- direction = None
- diff = None
- # Determine cursor position relative to selection start/end
- # Move to opposite position
- # Set cursor movement direction
- # Calculate range of selection
- if cursor.position() == cursor.selectionStart():
- cursor.setPosition(cursor.selectionEnd())
- direction = QtGui.QTextCursor.Up
- diff = cursor.blockNumber() - temp
- elif cursor.position() == cursor.selectionEnd():
- cursor.setPosition(cursor.selectionStart())
- direction = QtGui.QTextCursor.Down
- diff = temp
- # Iterate over lines
- for n in range(diff + 1):
- # Move to start of each line
- cursor.movePosition(QtGui.QTextCursor.StartOfLine)
- # Insert tabbing
- cursor.insertText('\t')
- # And move to next line
- cursor.movePosition(direction)
- # If there is no selection just insert a tab
- else:
- cursor.insertText('\t')
- def dedent(self):
- # Grab the cursor
- cursor = self.text.textCursor()
- if cursor.hasSelection():
- # Store the current line/block number
- temp = cursor.blockNumber()
- direction = None
- diff = None
- # Determine cursor position relative to selection start/end
- # Move to opposite position
- # Set cursor movement direction
- # Calculate range of selection
- if cursor.position() == cursor.selectionStart():
- cursor.setPosition(cursor.selectionEnd())
- direction = QtGui.QTextCursor.Up
- diff = cursor.blockNumber() - temp
- elif cursor.position() == cursor.selectionEnd():
- cursor.setPosition(cursor.selectionStart())
- direction = QtGui.QTextCursor.Down
- diff = temp
- # Iterate over lines
- for n in range(diff + 1):
- self.handleDedent(cursor)
- # Move up
- cursor.movePosition(direction)
- # If there is no selection just insert a tab
- else:
- self.handleDedent(cursor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement