コード例 #1
0
ファイル: test_textcommand.py プロジェクト: youngrok/editxt
 def test(c):
     if c.eol != u"\n":
         c.input = c.input.replace(u"\n", c.eol)
         c.output = c.output.replace(u"\n", c.eol)
     result = []
     m = Mocker()
     tv = m.mock(NSTextView)
     reset = (c.new == u"\t")
     if c.old != c.new or reset:
         tv.string() >> c.input
         rng = NSMakeRange(0, len(c.input))
         tv.shouldChangeTextInRange_replacementString_(rng, c.output) >> True
         if reset:
             doc = tv.doc_view.document >> m.mock(TextDocument)
             doc.reset_text_attributes(c.size)
         if c.input != c.output:
             sel = tv.selectedRange() >> NSRange(*c.sel)
             ts = tv.textStorage() >> m.mock(NSTextStorage)
             ts.replaceCharactersInRange_withString_(rng, c.output)
             if sel.location > len(c.output):
                 sel = NSRange(len(c.output), 0)
             elif sel.location + sel.length > len(c.output):
                 sel = NSRange(sel.location, len(c.output) - sel.location)
             tv.setSelectedRange_(sel)
         tv.didChangeText()
     with m:
         change_indentation(tv, c.old, c.new, c.size)
コード例 #2
0
ファイル: document.py プロジェクト: youngrok/editxt
    def change_indentation(self, old_mode, old_size, new_mode, new_size, convert_text):
        if convert_text:
            old_indent = u"\t" if old_mode == const.INDENT_MODE_TAB else (u" " * old_size)
            new_indent = u"\t" if new_mode == const.INDENT_MODE_TAB else (u" " * new_size)
            change_indentation(self.text_view, old_indent, new_indent, new_size)
        if old_mode != new_mode:
            self.document.props.indent_mode = new_mode
        if old_size != new_size:
            self.document.props.indent_size = new_size
        if convert_text or convert_text is None:

            def undo():
                self.change_indentation(new_mode, new_size, old_mode, old_size, None)

            register_undo_callback(self.document.undoManager(), undo)