示例#1
0
def filter_thru_shell(view, edit, regions, cmd):
    # XXX: make this a ShellFilter class instead
    if plat.HOST_PLATFORM == plat.WINDOWS:
        filter_func = plat.windows.filter_region
    elif plat.HOST_PLATFORM == plat.LINUX:
        filter_func = plat.linux.filter_region
    elif plat.HOST_PLATFORM == plat.OSX:
        filter_func = plat.osx.filter_region
    else:
        raise NotImplementedError

    # Maintain text size delta as we replace each selection going forward.
    # We can't simply go in reverse because cursor positions will be incorrect.
    accumulated_delta = 0
    new_points = []
    for r in regions:
        r_shifted = Region(r.begin() + accumulated_delta,
                           r.end() + accumulated_delta)
        rv = filter_func(view, view.substr(r_shifted), cmd).rstrip() + '\n'
        view.replace(edit, r_shifted, rv)
        new_points.append(r_shifted.a)
        accumulated_delta += len(rv) - r_shifted.size()

    # Switch to normal mode and move cursor(s) to beginning of replacement(s)
    view.run_command('_enter_normal_mode')
    view.sel().clear()
    view.sel().add_all(new_points)
示例#2
0
def _get_text_object_big_word(view, s: Region, inclusive: bool,
                              count: int) -> Region:
    w = a_big_word(view, s.b, inclusive=inclusive, count=count)
    if s.size() <= 1:
        return w

    return Region(s.a, w.b)
示例#3
0
def _get_text_object_word(view, s: Region, inclusive: bool,
                          count: int) -> Region:
    if s.size() == 1:
        pt = get_insertion_point_at_b(s)
    else:
        if s.b < s.a:
            pt = max(0, s.b - 1)
        else:
            pt = s.b

    w = _a_word(view, pt, inclusive=inclusive, count=count)
    if s.size() <= 1:
        return w

    if s.b >= s.a:
        return Region(s.a, w.b)
    else:
        return Region(s.a, w.a)

    return s
示例#4
0
def filter_thru_shell(view, edit, regions, cmd: str) -> None:
    # Maintain text size delta as we replace each selection going forward. We
    # can't simply go in reverse because cursor positions will be incorrect.
    accumulated_delta = 0
    new_points = []
    for r in regions:
        r_shifted = Region(r.begin() + accumulated_delta, r.end() + accumulated_delta)
        rv = _shell.filter_region(view, view.substr(r_shifted), cmd).rstrip() + '\n'
        view.replace(edit, r_shifted, rv)
        new_points.append(r_shifted.a)
        accumulated_delta += len(rv) - r_shifted.size()

    # Switch to normal mode and move cursor(s) to beginning of replacement(s).
    view.run_command('_enter_normal_mode')
    set_selection(view, new_points)
示例#5
0
 def __init__(self, update_region: sublime.Region, value: str) -> None:
     self._pos_changes = len(value) - update_region.size()
     self.region = update_region
     self.new_text = value