1. Henning Schröder
  2. codeaide

Source

codeaide / codeaide / modes / indenter.py

from codeaide.base import *


class IndenterBase(ModeBase):


    def correct_indentation(self, line_number=-1):
        if line_number == -1:
            cursor = self.textedit.textCursor()
            line_number = cursor.blockNumber()


    def entering_new_line(self, line_number=-1):
        if line_number == -1:
            cursor = self.textedit.textCursor()
            line_number = cursor.blockNumber()



    def dedent(self):
        cursor = self.textedit.textCursor()
        text = unicode(cursor.block().text())
        col = cursor.columnNumber()
        if col > 0 and text[:col].strip() == "":
            line_number = self.textCursor().blockNumber()
            return True



    def indent(self):
        self.indenter.correct_indentation()



    keyboard_hooks = {
        Qt.Key_Return: indent, 
        Qt.Key_Enter:  indent,
        Qt.Key_Tab: indent,
        Qt.Key_Backspace: dedent,
        Qt.Key_Backtab: dedent,
        }