def retro_everything(translator: Translator, stroke: Stroke, cmdline: str): print("\n\n\nRetro everything invoked with: " + str(stroke) + ", " + cmdline) args = cmdline.split(",") left_char = args[0] right_char = args[1] all_translations = translator.get_state().translations affected_translation_cnt = len( list( itertools.takewhile(lambda x: x.strokes[-1] == stroke, reversed(all_translations)))) # translations that _will_ be affected affected_translations = all_translations[-(affected_translation_cnt + 1):] affected_strokes = flatten([x.strokes for x in affected_translations]) affected_string = " ".join( flatten([ recursively_get_old_english(stroke, t) for t in affected_translations ])) resulting_translation = left_char + affected_string + right_char my_trans = Translation(affected_strokes + [stroke], resulting_translation) my_trans.replaced = affected_translations translator.translate_translation(my_trans)
def insert_space(translator, stroke, cmdline): # Retrospective insert space translations = translator.get_state().translations if not translations: return replaced = translations[-1] if replaced.is_retrospective_command: return lookup_stroke = replaced.strokes[-1] english = [t.english or '/'.join(t.rtfcre) for t in replaced.replaced] if english: english.append(translator.lookup([lookup_stroke]) or lookup_stroke.rtfcre) t = Translation([stroke], ' '.join(english)) t.replaced = [replaced] t.is_retrospective_command = True translator.translate_translation(t)
def insert_space(translator, stroke, cmdline): # Retrospective insert space translations = translator.get_state().translations if not translations: return replaced = translations[-1] if replaced.is_retrospective_command: return lookup_stroke = replaced.strokes[-1] english = [t.english or '/'.join(t.rtfcre) for t in replaced.replaced] if english: english.append( translator.lookup([lookup_stroke]) or lookup_stroke.rtfcre) t = Translation([stroke], ' '.join(english)) t.replaced = [replaced] t.is_retrospective_command = True translator.translate_translation(t)
def delete_space(translator, stroke, cmdline): # Retrospective delete space translations = translator.get_state().translations if len(translations) < 2: return replaced = translations[-2:] if replaced[1].is_retrospective_command: return english = [] for t in replaced: if t.english is not None: english.append(t.english) elif len(t.rtfcre) == 1 and t.rtfcre[0].isdigit(): english.append('{&%s}' % t.rtfcre[0]) if len(english) > 1: t = Translation([stroke], '{^~|^}'.join(english)) t.replaced = replaced t.is_retrospective_command = True translator.translate_translation(t)