예제 #1
0
파일: test_util.py 프로젝트: khairy/editxt
 def test(c):
     if c.eol != "\n":
         c.input = c.input.replace("\n", c.eol)
         c.output = c.output.replace("\n", c.eol)
     result = []
     m = Mocker()
     tv = m.mock(NSTextView)
     reset = (c.new == "\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:
         mod.change_indentation(tv, c.old, c.new, c.size)
예제 #2
0
파일: test_util.py 프로젝트: khairy/editxt
 def test(c):
     if c.eol != "\n":
         c.input = c.input.replace("\n", c.eol)
         c.output = c.output.replace("\n", c.eol)
     result = []
     m = Mocker()
     tv = m.mock(NSTextView)
     reset = (c.new == "\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:
         mod.change_indentation(tv, c.old, c.new, c.size)
예제 #3
0
 def change_indentation(self, old_mode, old_size, new_mode, new_size, convert_text):
     if convert_text:
         old_indent = "\t" if old_mode == const.INDENT_MODE_TAB else (" " * old_size)
         new_indent = "\t" if new_mode == const.INDENT_MODE_TAB else (" " * 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.undo_manager, undo)
예제 #4
0
파일: document.py 프로젝트: khairy/editxt
    def change_indentation(self, old_mode, old_size, new_mode, new_size,
                           convert_text):
        if convert_text:
            old_indent = "\t" if old_mode == const.INDENT_MODE_TAB else (
                " " * old_size)
            new_indent = "\t" if new_mode == const.INDENT_MODE_TAB else (
                " " * 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)