def select_span(self, r): self._unmap_select_mode_mapping() delta = r.end - r.start lineno, col = r.start.line, r.start.col set_vim_cursor(lineno + 1, col) if delta.line == delta.col == 0: if col == 0 or vim.eval("mode()") != 'i' and \ col < len(as_unicode(vim.current.buffer[lineno])): feedkeys(r"\<Esc>i") else: feedkeys(r"\<Esc>a") else: # If a tabstop immediately starts with a newline, the selection # must start after the last character in the current line. But if # we are in insert mode and <Esc> out of it, we cannot go past the # last character with move_one_right and therefore cannot # visual-select this newline. We have to hack around this by adding # an extra space which we can select. Note that this problem could # be circumvent by selecting the tab backwards (that is starting # at the end); one would not need to modify the line for this. if col >= len(as_unicode(vim.current.buffer[lineno])): vim.current.buffer[lineno] += " " if delta.line: move_lines = "%ij" % delta.line else: move_lines = "" # Depending on the current mode and position, we # might need to move escape out of the mode and this # will move our cursor one left if col != 0 and vim.eval("mode()") == 'i': move_one_right = "l" else: move_one_right = "" # After moving to the correct line, we go back to column 0 # and select right from there. Note that the we have to select # one column less since vim's visual selection is including the # ending while Python slicing is excluding the ending. if r.end.col == 0 and not len(as_unicode(vim.current.buffer[r.end.line])): # Selecting should end on an empty line -> Select the previous # line till its end do_select = "k$" elif r.end.col > 1: do_select = "0%il" % (r.end.col-1) else: do_select = "0" move_cmd = LangMapTranslator().translate( r"\<Esc>%sv%s%s\<c-g>" % (move_one_right, move_lines, do_select) ) feedkeys(move_cmd)
def _update_vim_buffer(self, del_more_lines = 0): if not len(self._csnippets): return s = self._csnippets[0] sline = s.abs_start.line dlines = s.end.line - s.start.line s.update() # Replace if self._vstate.buf_changed: dlines += self._vstate.moved.line dlines += del_more_lines self._vb.replace_lines(sline, sline + dlines, s._current_text) ct_end = self._ctab.abs_end set_vim_cursor(ct_end.line + 1, ct_end.col) self._vstate.update()