def format(self, undo, do, prev): """Format the given translations. This duplicates Formatter's logic - it would be better if there was a render(old, new) method that could be overridden. """ for t in do: last_action = _get_last_action(prev.formatting if prev else None) if t.english: t.formatting = _translation_to_actions(t.english, last_action, False) else: t.formatting = _raw_to_actions(t.rtfcre[0], last_action, False) prev = t old = [a for t in undo for a in t.formatting] new = [a for t in do for a in t.formatting] print "old:", old print "new:", new min_length = min(len(old), len(new)) for i in xrange(min_length): if old[i] != new[i]: break else: i = min_length self.render(old[i:], new[i:])
def format(self, undo, do, prev): """Format the given translations. This duplicates Formatter's logic - it would be better if there was a render(old, new) method that could be overridden. """ for t in do: last_action = _get_last_action(prev.formatting if prev else None) if t.english: t.formatting = _translation_to_actions(t.english, last_action, False) else: t.formatting = _raw_to_actions(t.rtfcre[0], last_action, False) prev = t old = [a for t in undo for a in t.formatting] new = [a for t in do for a in t.formatting] print "old:", old print "new:", new min_length = min(len(old), len(new)) for i in xrange(min_length): if old[i] != new[i]: break else: i = min_length self.render(old[i:], new[i:])
def test_raw_to_actions(stroke, last_action, expected): ctx = formatting._Context([], action()) ctx.translated(last_action) assert formatting._raw_to_actions(stroke, ctx) == expected
def test_raw_to_actions(stroke, last_action, expected): ctx = formatting._Context([], action()) ctx.translated(last_action) assert formatting._raw_to_actions(stroke, ctx) == expected
def test_raw_to_actions(stroke, last_action, spaces_after, expected): assert formatting._raw_to_actions(stroke, last_action, spaces_after) == expected