def next(self): if self.matching: if self.forwards: utils.repeat(partial(vx.move_right_window, self.attached_to), times=self.match_length) else: utils.repeat(partial(vx.move_left_window, self.attached_to), times=self.match_length) vx.move_left_window(self.attached_to)
def search(self): self.set_color(-1, -1) search_for = self.contents if not search_for: self.clear_color() return l, c, o, length = self.dosearch(self.attached_to, search_for, int(self.forwards)) if o == -1: self.attached_to.cursor = (self.original_cursor[0], self.original_cursor[1]) self.clear_color() self.set_color(-1, 11) self.matching = False return self.attached_to.ensure_visible(l, c + length) self.matching = True self.match_length = length self.attached_to.cursor = (l, c) self.clear_color() self.attached_to.add_color_tag('search', l, c, length, 1, 10) all_matches = self.attached_to.get_all_regex_linecoloffsetlengths_of( search_for, self.forwards) if not self.forwards: # quick and ugly, this should be fixed with better overlap # color tag detection all_matches = [None] + list(all_matches) for l, c, _, length in list(all_matches)[1:]: self.attached_to.add_color_tag('search', l, c, length, 1, 9) if not self.forwards: utils.repeat(partial(vx.move_right_window, self.attached_to), times=length)
def getout(self): if self.matching: if self.forwards: utils.repeat(partial(vx.move_right_window, self.attached_to), times=self.match_length) if self.remove_callback: self.remove_callback(self) self.remove(force=True) unregister_key_listener(self.isearch) self.clear_color()
def grab(self, buffer): with buffer.cursor_wander(): la, ca = buffer.cursor for _ in range(self.how_many): offset = text.get_offset_regex(buffer, r'^$', forwards=self.forward) if offset is None: move.end(buffer) if self.forward else move.end(buffer) else: utils.repeat(move.right if self.forward else move.left, times=offset) lb, cb = buffer.cursor return la, ca, lb, cb
def move(self): if not self._stack: move.right() else: i = self._stack.pop(0) if i == PlaceModifier.backward: move.left() elif isinstance(i, Times): utils.repeat(self.move, times=i.i) else: _, _, lb, cb = i.grab(self.for_window) self.for_window.cursor = lb, cb
def grab(self, buffer): with buffer.cursor_wander(): la, ca = buffer.cursor breaks = (' ', '\n') for _ in range(self.how_many): offset = text.get_offset_regex(buffer, '[{}]'.format(''.join(breaks)), forwards=self.forward) if offset is None: move.eol(buffer) if self.forward else move.bol(buffer) else: utils.repeat(move.right if self.forward else move.left, times=offset) lb, cb = buffer.cursor return la, ca, lb, cb
def search(self): self.set_color(-1, -1) search_for = self.contents if not search_for: self.clear_color(); return l, c, o, length = self.dosearch(self.attached_to, search_for, int(self.forwards)) if o == -1: self.attached_to.cursor = (self.original_cursor[0], self.original_cursor[1]) self.clear_color() self.set_color(-1, 11) self.matching = False return self.attached_to.ensure_visible(l, c + length) self.matching = True self.match_length = length self.attached_to.cursor = (l, c) self.clear_color() self.attached_to.add_color_tag("search", l, c, length, 1, 10) if not self.forwards: utils.repeat(partial(vx.move_right_window, self.attached_to), times=length)
def grab(self, buffer): with buffer.cursor_wander(): la, ca = buffer.cursor utils.repeat(move.right if self.forward else move.left, times=self.how_many) lb, cb = buffer.cursor return la, ca, lb, cb