(self)
| 211 | return False |
| 212 | |
| 213 | def indent(self): |
| 214 | # tab key has been pressed. Indent current line or selected block by self.indent_width |
| 215 | |
| 216 | cursor = self.textCursor() |
| 217 | # is there a selection? |
| 218 | |
| 219 | selectionStart = cursor.selectionStart() |
| 220 | selectionEnd = cursor.selectionEnd() |
| 221 | |
| 222 | if selectionStart == selectionEnd and cursor.atBlockEnd(): |
| 223 | # ie no selection and don't insert in the middle of text |
| 224 | # something smarter might skip whitespace and add a tab in front of |
| 225 | # the next non whitespace character |
| 226 | cursor.insertText(" " * self.indent_width) |
| 227 | return |
| 228 | |
| 229 | cursor.setPosition(selectionStart) |
| 230 | startBlock = cursor.blockNumber() |
| 231 | cursor.setPosition(selectionEnd) |
| 232 | endBlock = cursor.blockNumber() |
| 233 | |
| 234 | cursor.movePosition(QTextCursor.MoveOperation.Start) |
| 235 | cursor.movePosition(QTextCursor.MoveOperation.NextBlock, n=startBlock) |
| 236 | |
| 237 | for i in range(0, endBlock - startBlock + 1): |
| 238 | if not self.isEmptyBlock(startBlock + i): # Don't insert whitespace on empty lines |
| 239 | cursor.movePosition(QTextCursor.MoveOperation.StartOfLine) |
| 240 | cursor.insertText(" " * self.indent_width) |
| 241 | |
| 242 | cursor.movePosition(QTextCursor.MoveOperation.NextBlock) |
| 243 | |
| 244 | # QT maintains separate cursors, so don't need to track or reset user's cursor |
| 245 | |
| 246 | def dedentBlock(self, blockNumber): |
| 247 | # dedent the line at blockNumber |
no test coverage detected