def move(self): view = self.view doc = view.document y, x = view.cursor_pos if x == len(doc.get_line(y)): last_line = doc.num_lines - 1 if y < last_line: view.cursor_pos = (y+1, 0) view.last_x_pos = 0 else: line = doc.get_line(y) span = get_word_range(line, x) if span: view.cursor_pos = (y, span[1]) view.last_x_pos = char_pos_to_tab_pos(line, span[1], doc.tab_size)
def move(self): view = self.view doc = view.document y, x = view.cursor_pos if x == 0: if y > 0: line = doc.get_line(y-1) lx = len(line) view.cursor_pos = (y-1, lx) view.last_x_pos = char_pos_to_tab_pos(line, lx, doc.tab_size) else: line = doc.get_line(y) span = get_word_range(line, x-1) if span: view.cursor_pos = (y, span[0]) view.last_x_pos = char_pos_to_tab_pos(line, span[0], doc.tab_size)
def execute(self): view = self.view doc = view.document y, x = view.cursor_pos if view.selection: # typically select word only occurs when you double-click and # click will probably clear the selection, but you never know... view.selection = None view.invalidate() line = doc.get_line(y) span = get_word_range(line, x) if span: start_index = span[0] end_index = span[1] start_offset = doc.cursor_pos_to_offset((y, start_index)) end_offset = doc.cursor_pos_to_offset((y, end_index)) view.selection = Selection(doc, start_offset, end_offset) view.invalidate() view.last_x_pos = char_pos_to_tab_pos(line, end_index, doc.tab_size) view.cursor_pos = (y, end_index)
def test_get_word_range_symbol(): text = 'monkey != banana' start, end = get_word_range(text, 8) # before the = assert start == 7 assert end == 9
def test_get_word_range_whitespace(): text = 'hello there' start, end = get_word_range(text, 5) # the space between the words assert start == 5 assert end == 6
def test_get_word_range_word_before(): text = "hello there" start, end = get_word_range(text, 6) # just before 'there' assert start == 6 assert end == 11
def test_get_word_range_word_middle(): text = "hello there" start, end = get_word_range(text, 8) # somewhere inside 'there' assert start == 6 assert end == 11