def test(c): m = Mocker() regundo = m.replace(mod, 'register_undo_callback') convert = m.replace(mod, 'change_indentation') doc = m.mock(TextDocument) with m.off_the_record(): dv = Editor(None, document=doc) tv = dv.text_view = m.mock(ak.NSTextView) if c.convert: old_indent = "\t" if c.oldm is TAB else (" " * c.olds) new_indent = "\t" if c.newm is TAB else (" " * c.news) convert(tv, old_indent, new_indent, c.news) if c.oldm != c.newm: doc.props.indent_mode = c.newm if c.olds != c.news: doc.props.indent_size = c.news if c.convert or c.convert is None: undo_change = m.mock(); undo_change(c.newm, c.news, c.oldm, c.olds, None) def _undo(undoman, undo): dv.change_indentation = undo_change undo() undoman = doc.undo_manager >> m.mock(fn.NSUndoManager) expect(regundo(undoman, ANY)).call(_undo) with m: dv.change_indentation(c.oldm, c.olds, c.newm, c.news, c.convert)
def test(c): def end(): with m: doc.reload_document() eq_(doc.text, text) text = "edit" config = " ".join("project" for x in c.view_state) with make_file(content="disk") as path, test_app(config) as app: if c.url_is_none: path = "not-saved" elif not c.exists: path += "-not-found" m = Mocker() call_later = m.replace(mod, "call_later") doc = TextDocument(app, path) reset_text_attributes = m.method(doc.reset_text_attributes) doc.text = text if c.url_is_none or not c.exists: return end() undo = doc.undo_manager = m.mock(UndoManager) if not c.read2_success: os.remove(path) os.mkdir(path) return end() text = "disk" tv = m.mock(TextView) for i, text_view_exists in enumerate(c.view_state): project = app.windows[0].projects[i] with m.off_the_record(): editor = Editor(project, document=doc) editor.text_view = (tv if text_view_exists else None) project.editors.append(editor) reset_text_attributes() if not any(c.view_state): # TODO reload without undo #doc_ts.replaceCharactersInRange_withString_(range, text) undo.removeAllActions() return end() range = fn.NSRange(0, 4) tv.shouldChangeTextInRange_replacementString_(range, text) >> True # TODO get edit_state of each document view # TODO diff the two text blocks and change chunks of text # throughout the document (in a single undo group if possible) # also adjust edit states if possible # see http://www.python.org/doc/2.5.2/lib/module-difflib.html #doc_ts.replaceCharactersInRange_withString_(range, text) tv.didChangeText() tv.breakUndoCoalescing() # TODO restore edit states # HACK use timed invocation to allow didChangeText notification # to update change count before _clearUndo is invoked call_later(0, doc.clear_dirty) tv.select((0, 0)) reset_text_attributes() m.method(doc.update_syntaxer)() end()
def create_editor(self, state=None): from editxt.editor import EditorWindowController, Editor wc = EditorWindowController.alloc().initWithWindowNibName_( "EditorWindow") ed = Editor(self, wc, state) wc.editor = ed self.editors.append(ed) wc.showWindow_(self) return ed
def test(app, c): m = Mocker() doc = m.mock(TextDocument) project = app.windows[0].projects[0] with m.off_the_record(): dv = Editor(project, document=doc) m.property(dv, "soft_wrap") m.property(dv, "file_path") doc.updates_path_on_file_move >> True if c.tv_is_none: if c.set_state: dv.edit_state = state = dict(key="value") else: state = {} state["soft_wrap"] = const.WRAP_NONE else: dv.text_view = m.mock(ak.NSTextView) dv.scroll_view = m.mock(ak.NSScrollView) sel = m.mock(fn.NSRange) sp = m.mock(fn.NSPoint) dv.text_view.selectedRange() >> sel dv.scroll_view.documentVisibleRect().origin >> sp sel.location >> "<sel.location>" sel.length >> "<sel.length>" sp.x >> "<sp.x>" sp.y >> "<sp.y>" dv.soft_wrap >> c.soft_wrap state = dict( selection=["<sel.location>", "<sel.length>"], scrollpoint=["<sp.x>", "<sp.y>"], soft_wrap=c.soft_wrap, ) (dv.file_path << "<path>").count(1, 2) state["path"] = "<path>" with m: result = dv.edit_state eq_(result, state) if c.tv_is_none and c.set_state: assert result is not state, \ "identity check should fail: must be a new (mutable) dict"
def test_insert_items(app): proj = Project(None) doc = Editor(proj, document=app.document_with_path(None)) doc.project = proj proj.insert_items([doc]) assert doc in proj.editors