(self, increase, withSpace=False)
Tab or Space pressed and few blocks are selected, or Shift+Tab pressed
        Insert or remove text from the beginning of blocks
Tab or Space pressed and few blocks are selected, or Shift+Tab pressed
        Insert or remove text from the beginning of blocks
Tab or Space pressed and few blocks are selected or Shift + Tab pressed Insert or remove text from the beginning of blocks
def onChangeSelectedBlocksIndent(self, increase, withSpace=False):
        """Tab or Space pressed and few blocks are selected, or Shift+Tab pressed
        Insert or remove text from the beginning of blocks
        """

        def blockIndentation(block):
            text = block.text()
            return text[:len(text) - len(text.lstrip())]

        def cursorAtSpaceEnd(block):
            cursor = QTextCursor(block)
            cursor.setPosition(block.position() + len(blockIndentation(block)))
            return cursor

        def indentBlock(block):
            cursor = cursorAtSpaceEnd(block)
            cursor.insertText(' ' if withSpace else self.text())

        def spacesCount(text):
            return len(text) - len(text.rstrip(' '))

        def unIndentBlock(block):
            currentIndent = blockIndentation(block)

            if currentIndent.endswith('\t'):
                charsToRemove = 1
            elif withSpace:
                charsToRemove = 1 if currentIndent else 0
            else:
                if self.useTabs:
                    charsToRemove = min(spacesCount(currentIndent), self.width)
                else:  # spaces
                    if currentIndent.endswith(self.text()):  # remove indent level
                        charsToRemove = self.width
                    else:  # remove all spaces
                        charsToRemove = min(spacesCount(currentIndent), self.width)

            if charsToRemove:
                cursor = cursorAtSpaceEnd(block)
                cursor.setPosition(cursor.position() - charsToRemove, QTextCursor.KeepAnchor)
                cursor.removeSelectedText()

        cursor = self._qpart.textCursor()

        startBlock = self._qpart.document().findBlock(cursor.selectionStart())
        endBlock = self._qpart.document().findBlock(cursor.selectionEnd())
        if (cursor.selectionStart() != cursor.selectionEnd() and
                endBlock.position() == cursor.selectionEnd() and
                endBlock.previous().isValid()):
            # do not indent not selected line if indenting multiple lines
            endBlock = endBlock.previous()

        indentFunc = indentBlock if increase else unIndentBlock

        if startBlock != endBlock:  # indent multiply lines
            stopBlock = endBlock.next()

            block = startBlock

            with self._qpart:
                while block != stopBlock:
                    indentFunc(block)
                    block = block.next()

            newCursor = QTextCursor(startBlock)
            newCursor.setPosition(endBlock.position() + len(endBlock.text()),
                                  QTextCursor.KeepAnchor)
            self._qpart.setTextCursor(newCursor)
        else:  # indent 1 line
            indentFunc(startBlock)
def onChangeSelectedBlocksIndent ( self , increase , withSpace = False ) : def blockIndentation ( block ) : text = block . text ( ) return text [ : len ( text ) - len ( text . lstrip ( ) ) ] def cursorAtSpaceEnd ( block ) : cursor = QTextCursor ( block ) cursor . setPosition ( block . position ( ) + len ( blockIndentation ( block ) ) ) return cursor def indentBlock ( block ) : cursor = cursorAtSpaceEnd ( block ) cursor . insertText ( ' ' if withSpace else self . text ( ) ) def spacesCount ( text ) : return len ( text ) - len ( text . rstrip ( ' ' ) ) def unIndentBlock ( block ) : currentIndent = blockIndentation ( block ) if currentIndent . endswith ( '\t' ) : charsToRemove = 1 elif withSpace : charsToRemove = 1 if currentIndent else 0 else : if self . useTabs : charsToRemove = min ( spacesCount ( currentIndent ) , self . width ) else : # spaces if currentIndent . endswith ( self . text ( ) ) : # remove indent level charsToRemove = self . width else : # remove all spaces charsToRemove = min ( spacesCount ( currentIndent ) , self . width ) if charsToRemove : cursor = cursorAtSpaceEnd ( block ) cursor . setPosition ( cursor . position ( ) - charsToRemove , QTextCursor . KeepAnchor ) cursor . removeSelectedText ( ) cursor = self . _qpart . textCursor ( ) startBlock = self . _qpart . document ( ) . findBlock ( cursor . selectionStart ( ) ) endBlock = self . _qpart . document ( ) . findBlock ( cursor . selectionEnd ( ) ) if ( cursor . selectionStart ( ) != cursor . selectionEnd ( ) and endBlock . position ( ) == cursor . selectionEnd ( ) and endBlock . previous ( ) . isValid ( ) ) : # do not indent not selected line if indenting multiple lines endBlock = endBlock . previous ( ) indentFunc = indentBlock if increase else unIndentBlock if startBlock != endBlock : # indent multiply lines stopBlock = endBlock . next ( ) block = startBlock with self . _qpart : while block != stopBlock : indentFunc ( block ) block = block . next ( ) newCursor = QTextCursor ( startBlock ) newCursor . setPosition ( endBlock . position ( ) + len ( endBlock . text ( ) ) , QTextCursor . KeepAnchor ) self . _qpart . setTextCursor ( newCursor ) else : # indent 1 line indentFunc ( startBlock )