def resolve_line_reference(self, view, line_reference, current=0): ''' Calculates the line offset determined by @line_reference. @view The view where the calculation is made. @line_reference The sequence of tokens defining the line range to be calculated. @current Line number where we are now. ''' last_token = None # XXX: what happens if there is no selection in the view? current = row_at(view, first_sel(view).b) for token in line_reference: # Make sure a search forward doesn't overlap with a match obtained # right before this search. if isinstance(last_token, TokenOfSearch) and isinstance( token, TokenOfSearch): if isinstance(token, TokenSearchForward): current += 1 current = self.resolve_notation(view, token, current) last_token = token return current
def resolve_line_reference(self, view, line_reference, current=0): """ Calculates the line offset determined by @line_reference. @view The view where the calculation is made. @line_reference The sequence of tokens defining the line range to be calculated. @current Line number where we are now. """ last_token = None # XXX: what happens if there is no selection in the view? current = row_at(view, first_sel(view).b) for token in line_reference: # Make sure a search forward doesn't overlap with a match obtained # right before this search. if isinstance(last_token, TokenOfSearch) and isinstance(token, TokenOfSearch): if isinstance(token, TokenSearchForward): current += 1 current = self.resolve_notation(view, token, current) last_token = token return current
def get_visual_repeat_data(self): """Returns the data needed to restore visual selections before repeating a visual mode command in normal mode. """ if self.mode not in (modes.VISUAL, modes.VISUAL_LINE): return first = first_sel(self.view) lines = (utils.row_at(self.view, first.end()) - utils.row_at(self.view, first.begin())) if lines > 0: chars = utils.col_at(self.view, first.end()) else: chars = first.size() return (lines, chars, self.mode)
def restore_visual_data(self, data): rows, chars, old_mode = data first = first_sel(self.view) if old_mode == modes.VISUAL: if rows > 0: end = self.view.text_point(utils.row_at(self.view, first.b) + rows, chars) else: end = first.b + chars self.view.sel().add(sublime.Region(first.b, end)) self.mode = modes.VISUAL elif old_mode == modes.VISUAL_LINE: rows, _, old_mode = data begin = self.view.line(first.b).a end = self.view.text_point(utils.row_at(self.view, begin) + (rows - 1), 0) end = self.view.full_line(end).b self.view.sel().add(sublime.Region(begin, end)) self.mode = modes.VISUAL_LINE
def restore_visual_data(self, data): rows, chars, old_mode = data first = first_sel(self.view) if old_mode == modes.VISUAL: if rows > 0: end = self.view.text_point( utils.row_at(self.view, first.b) + rows, chars) else: end = first.b + chars self.view.sel().add(sublime.Region(first.b, end)) self.mode = modes.VISUAL elif old_mode == modes.VISUAL_LINE: rows, _, old_mode = data begin = self.view.line(first.b).a end = self.view.text_point( utils.row_at(self.view, begin) + (rows - 1), 0) end = self.view.full_line(end).b self.view.sel().add(sublime.Region(begin, end)) self.mode = modes.VISUAL_LINE