def apply_transformation(self, transformation_input): buffer_control, document, lineno, source_to_display, fragments, _, _ = transformation_input.unpack( ) buff = buffer_control.buffer if vi_insert_multiple_mode(): cursor_positions = buff.multiple_cursor_positions fragments = explode_text_fragments(fragments) # If any cursor appears on the current line, highlight that. start_pos = document.translate_row_col_to_index(lineno, 0) end_pos = start_pos + len(document.lines[lineno]) fragment_suffix = ' class:multiple-cursors' for p in cursor_positions: if start_pos <= p <= end_pos: column = source_to_display(p - start_pos) # Replace fragment. try: style, text = fragments[column] except IndexError: # Cursor needs to be displayed after the current text. fragments.append((fragment_suffix, ' ')) else: style += fragment_suffix fragments[column] = (style, text) return Transformation(fragments) else: return Transformation(fragments)
def apply_transformation( self, transformation_input: TransformationInput) -> Transformation: buffer_control, document, lineno, source_to_display, fragments, _, _ = transformation_input.unpack() buff = buffer_control.buffer if vi_insert_multiple_mode(): cursor_positions = buff.multiple_cursor_positions fragments = explode_text_fragments(fragments) # If any cursor appears on the current line, highlight that. start_pos = document.translate_row_col_to_index(lineno, 0) end_pos = start_pos + len(document.lines[lineno]) fragment_suffix = ' class:multiple-cursors' for p in cursor_positions: if start_pos <= p <= end_pos: column = source_to_display(p - start_pos) # Replace fragment. try: style, text, *_ = fragments[column] except IndexError: # Cursor needs to be displayed after the current text. fragments.append((fragment_suffix, ' ')) else: style += fragment_suffix fragments[column] = (style, text) return Transformation(fragments) else: return Transformation(fragments)