Exemple #1
0
 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)
Exemple #2
0
 def refreshDisplay_(self, line):
     #print line
     self.console_view.textStorage().mutableString().appendString_(line)
     need_scroll = NSMaxY(self.console_view.visibleRect()) >= NSMaxY(
         self.console_view.bounds())
     if need_scroll:
         range = NSMakeRange(
             len(self.console_view.textStorage().mutableString()), 0)
         self.console_view.scrollRangeToVisible_(range)
Exemple #3
0
 def suggest(self, fragment):
     l = self._language
     # XXX Both ways below work on OSX 10.6. It has not been tested on any
     #     other version, but it should work.
     try:
         # This is deprecated as of OSX 10.6, hence the try-except
         return list(l.guessesForWord_(fragment))
     except AttributeError:
         # From 10.6 onwards you're supposed to do it like this:
         checkrange = NSMakeRange(0, len(fragment))
         g = l.guessesForWordRange_inString_language_inSpellDocumentWithTag_(
             checkrange, fragment, l.language(), 0)
         # Right, this was much easier, Apple! :-)
         return list(g)
Exemple #4
0
 def test(c):
     result = []
     m = Mocker()
     tv = m.mock(NSTextView)
     tv.string() >> c.input
     sel = tv.selectedRange() >> m.mock(NSRange)
     if c.input != c.output:
         rng = NSMakeRange(0, len(c.input))
         tv.shouldChangeTextInRange_replacementString_(rng, ANY) >> True
         ts = tv.textStorage() >> m.mock(NSTextStorage)
         ts.replaceCharactersInRange_withString_(rng, c.output)
         tv.didChangeText()
         tv.setSelectedRange_(sel)
     with m:
         mod.replace_newlines(tv, c.eol)