#NEWLINE# def _on_key_pressed( self , event ) : #NEWLINE# #INDENT# '\n        Auto indent if the released key is the return key.\n        :param event: the key event\n        ' #NEWLINE# if ( not event . isAccepted ( ) ) : #NEWLINE# #INDENT# if ( ( event . key ( ) == Qt . Key_Return ) or ( event . key ( ) == Qt . Key_Enter ) ) : #NEWLINE# #INDENT# cursor = self . editor . textCursor ( ) #NEWLINE# ( pre , post ) = self . _get_indent ( cursor ) #NEWLINE# cursor . beginEditBlock ( ) #NEWLINE# cursor . insertText ( ( '%s\n%s' % ( pre , post ) ) ) #NEWLINE# cursor . movePosition ( cursor . WordRight , cursor . KeepAnchor ) #NEWLINE# txt = cursor . selectedText ( ) #NEWLINE# if txt . startswith ( ' ' ) : #NEWLINE# #INDENT# new_txt = txt . replace ( ' ' , '' ) #NEWLINE# if ( len ( txt ) > len ( new_txt ) ) : #NEWLINE# #INDENT# cursor . insertText ( new_txt ) #NEWLINE# #UNINDENT# #UNINDENT# cursor . endEditBlock ( ) #NEWLINE# event . accept ( )