def apply_particle(context: _Context, rule_info: Optional[ParticleRuleInfo]) -> _Action: """Creates an action based on the particle rule info. The action will replace the last word in the context with the word plus the chosen particle based on the particle rule info. Args: context: The context of actions in Plover. rule_info: The particle rule information to use. Returns: An action with a particle attached to the last word in the context. If the rule info is invalid, a blank new action will be returned. """ action: _Action = context.copy_last_action() if rule_info is None: return action last_word = ''.join(context.last_words(1)) action.prev_replace = last_word action.prev_attach = True action.next_attach = False action.word = None action.text = attach_particle(last_word, rule_info) return action
def __retro_surround(ctx: _Context, cmdline: str) -> _Action: action: _Action = ctx.copy_last_action() args = cmdline.split(":") word_cnt = int(args[0]) left_char = args[1] right_char = args[2] last_words = "".join(ctx.last_fragments(count=word_cnt)) action.prev_replace = last_words action.text = left_char + last_words + right_char action.word = None action.prev_attach = True return action
def repeat_last_translation(context: _Context, args: str) -> _Action: ''' Meta to repeat the last translation(s) in Plover. :param context: The context of actions in Plover. :param args: Optional arguments provided to the meta as a comma-delimited string. Piece 1: The number of previous translations to repeat. Default is 1. :return: The next action for Plover to perform. ''' # Process input try: num_to_repeat = int(args.split(DELIM_ARGS)[0]) except: num_to_repeat = 1 output = '' translations: List[Translation] = context.previous_translations[-num_to_repeat:] for translation in translations: actions: List[_Action] = reversed(translation.formatting) for action in actions: output = output + action.text # Create the new action action: _Action = context.new_action() action.text = output return action
def fancy_set(self, ctx: _Context, cmdline) -> _Action: args = cmdline.split(':') mode = args.pop(0) if mode in self.transformers: self.formatter = self.transformers[mode](*args) else: self.formatter = None return ctx.new_action()
def fancy_set(self, ctx: _Context, cmdline): if cmdline in self.transformers: new_formatter = self.transformers[cmdline] else: new_formatter = None old_formatter = self.formatter self.formatter = new_formatter if new_formatter: self.format_start = new_formatter.format_start() if old_formatter: self.format_end = old_formatter.format_end() return ctx.new_action()
def repeat_last_character(context: _Context, args: str) -> _Action: ''' Meta to repeat the last character(s) in Plover. :param context: The context of actions in Plover. :param args: Optional arguments provided to the meta as a comma-delimited string. Piece 1: The number of previous characters to repeat. Default is 1. :return: The next action for Plover to perform. ''' # Process input try: num_to_repeat = int(args.split(DELIM_ARGS)[0]) except: num_to_repeat = 1 text = context.last_text(num_to_repeat) # Create the new action action: _Action = context.new_action() action.text = text return action