def _do_ys(view, edit, mode=None, motion=None, replacement='"', count=1): def surround(view, edit, s, replacement): open_, close_ = _get_punctuation_mark_replacements(replacement) # Takes <q class="foo"> and produces: <q class="foo">text</q> if open_.startswith('<'): name = open_[1:].strip()[:-1].strip() name = name.split(' ', 1)[0] view.insert(edit, s.b, "</{0}>".format(name)) view.insert(edit, s.a, replacement) return view.insert(edit, s.end(), close_) view.insert(edit, s.begin(), open_) def f(view, s): if mode == INTERNAL_NORMAL: surround(view, edit, s, replacement) return Region(s.begin()) elif mode in (VISUAL, VISUAL_BLOCK): surround(view, edit, s, replacement) return Region(s.begin()) return s if not motion and not view.has_non_empty_selection_region(): enter_normal_mode(view, mode) raise ValueError('motion required') if mode == INTERNAL_NORMAL: run_motion(view, motion) if replacement: _rsynced_regions_transformer(view, f) enter_normal_mode(view, mode)
def _do_C(view, edit, mode, count=1, motion=None): def f(view, s): return Region(s.begin()) if motion: run_motion(view, motion) elif mode not in (VISUAL, VISUAL_LINE): return ui_bell() view.run_command('toggle_comment', {'block': True}) regions_transformer(view, f) enter_normal_mode(view, mode)
def on_activated(self, view): # Clear any visual selections in the view we are leaving. This mirrors # Vim behaviour. We can't put this functionality in the # view.on_deactivate() event, because that event is triggered when the # user right button clicks the view with the mouse, and we don't want # visual selections to be cleared on mouse right button clicks. if not view.settings().get('is_widget'): window = view.window() if window: active_group = window.active_group() for group in range(window.num_groups()): if group != active_group: other_view = window.active_view_in_group(group) if other_view and other_view != view: sel = other_view.sel() if len(sel) > 0 and any([not s.empty() for s in sel]): enter_normal_mode(other_view, State(other_view).mode) # Initialise view state. init_state(view)
def _goto_modification(action, view, mode, count): if int(version()) >= 3189: for i in range(count): view.run_command(action + '_modification') a = view.sel()[0].a if view.substr(a) == '\n': a += 1 view.sel().clear() view.sel().add(a) enter_normal_mode(view, mode) else: # TODO Remove DEPRECATED code, deprecated since build 3189 view.run_command('git_gutter_' + action + '_change', {'count': count, 'wrap': False}) line = view.line(view.sel()[0].b) if line.size() > 0: pt = view.find('^\\s*', line.begin()).end() if pt != line.begin(): view.sel().clear() view.sel().add(pt)
def _do_c(view, edit, mode, count=1, motion=None): def f(view, s): return Region(s.begin()) if motion: run_motion(view, motion) elif mode not in (VISUAL, VISUAL_LINE): return ui_bell() view.run_command('toggle_comment', {'block': False}) regions_transformer(view, f) line = view.line(view.sel()[0].begin()) pt = line.begin() if line.size() > 0: line = view.find('^\\s*', line.begin()) pt = line.end() set_selection(view, pt) enter_normal_mode(view, mode)
def goto_prev_change(view, mode, count): if int(version()) >= 3189: for i in range(count): view.run_command('prev_modification') a = view.sel()[0].a if view.substr(a) == '\n': a += 1 view.sel().clear() view.sel().add(a) enter_normal_mode(view, mode) else: view.run_command('git_gutter_prev_change', { 'count': count, 'wrap': False }) line = view.line(view.sel()[0].b) if line.size() > 0: pt = view.find('^\\s*', line.begin()).end() if pt != line.begin(): view.sel().clear() view.sel().add(pt)
def _do_c(view, edit, mode, count=1, motion=None): def f(view, s): return Region(s.begin()) if motion: view.run_command(motion['motion'], motion['motion_args']) elif mode not in (VISUAL, VISUAL_LINE): return ui_blink() view.run_command('toggle_comment', {'block': False}) regions_transformer(view, f) line = view.line(view.sel()[0].begin()) pt = line.begin() if line.size() > 0: line = view.find('^\\s*', line.begin()) pt = line.end() view.sel().clear() view.sel().add(pt) enter_normal_mode(view, mode)
def _do_ys(view, edit, mode: str = None, motion=None, replacement: str = '"', count: int = 1) -> None: def _surround(view, edit, s, replacement: str) -> None: replacement_open, replacement_close = _get_punctuation_mark_replacements( replacement) if replacement_open.startswith('<'): view.insert(edit, s.b, replacement_close) view.insert(edit, s.a, replacement_open) return view.insert(edit, s.end(), replacement_close) view.insert(edit, s.begin(), replacement_open) def f(view, s): if mode == INTERNAL_NORMAL: _surround(view, edit, s, replacement) return Region(s.begin()) elif mode in (VISUAL, VISUAL_BLOCK): _surround(view, edit, s, replacement) return Region(s.begin()) return s if not motion and not view.has_non_empty_selection_region(): enter_normal_mode(view, mode) raise ValueError('motion required') if mode == INTERNAL_NORMAL: run_motion(view, motion) if replacement: _rsynced_regions_transformer(view, f) enter_normal_mode(view, mode)
def _goto_modification(action: str, view, mode: str, count: int) -> None: with wrapscan(view, forward=(action == 'next')): if int(version()) >= 3189: for i in range(count): view.run_command(action + '_modification') a = view.sel()[0].a if view.substr(a) == '\n': if not view.line(a).empty(): a += 1 set_selection(view, a) enter_normal_mode(view, mode) else: # TODO Remove DEPRECATED code, deprecated since build 3189 view.run_command('git_gutter_' + action + '_change', { 'count': count, 'wrap': False }) line = view.line(view.sel()[0].b) if line.size() > 0: pt = view.find('^\\s*', line.begin()).end() if pt != line.begin(): set_selection(view, pt)