No longer cache the whole buffer, only the last range
This commit is contained in:
parent
2dc4148f0f
commit
0f37d62f8a
@ -1,9 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
# TODO: Currently Caches whole buffer. Is this really needed?
|
|
||||||
# TODO: Currently searches whole buffer. Is this really needed?
|
|
||||||
# TODO: hijack two marks instead of running through the whole buffer
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import glob
|
import glob
|
||||||
import hashlib
|
import hashlib
|
||||||
@ -594,20 +591,22 @@ class SnippetManager(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self._csnippets:
|
if self._csnippets:
|
||||||
|
cstart = self._csnippets[0].start.line
|
||||||
ct = _vim.buf[:]
|
cend = self._csnippets[0].end.line + len(_vim.buf) - self._lvb_len
|
||||||
|
ct = _vim.buf[cstart:cend + 1]
|
||||||
lt = self._lvb[:]
|
lt = self._lvb[:]
|
||||||
pos = _vim.buf.cursor
|
pos = _vim.buf.cursor
|
||||||
|
|
||||||
lt_span = [0, len(lt)]
|
lt_span = [0, len(lt)]
|
||||||
ct_span = [0, len(ct)]
|
ct_span = [0, len(ct)]
|
||||||
initial_line = 0
|
initial_line = cstart
|
||||||
|
|
||||||
debug("lt: %r" % (lt))
|
debug("lt: %r" % (lt))
|
||||||
debug("ct: %r" % (ct))
|
debug("ct: %r" % (ct))
|
||||||
# Cut down on lines searched for changes. Start from behind and
|
# Cut down on lines searched for changes. Start from behind and
|
||||||
# remove all equal lines. Then do the same from the front.
|
# remove all equal lines. Then do the same from the front.
|
||||||
while (lt[lt_span[1]-2] == ct[ct_span[1]-2] and
|
while (lt[lt_span[1]-1] == ct[ct_span[1]-1] and
|
||||||
|
self._lpos.line < lt_span[1] and pos.line < ct_span[1] and
|
||||||
(lt_span[0] < lt_span[1]) and
|
(lt_span[0] < lt_span[1]) and
|
||||||
(ct_span[0] < ct_span[1])):
|
(ct_span[0] < ct_span[1])):
|
||||||
ct_span[1] -= 1
|
ct_span[1] -= 1
|
||||||
@ -615,6 +614,7 @@ class SnippetManager(object):
|
|||||||
debug("1 lt_span: %r, ct_span: %r" % (lt_span ,ct_span))
|
debug("1 lt_span: %r, ct_span: %r" % (lt_span ,ct_span))
|
||||||
try:
|
try:
|
||||||
while (lt[lt_span[0]] == ct[ct_span[0]] and
|
while (lt[lt_span[0]] == ct[ct_span[0]] and
|
||||||
|
self._lpos.line <= lt_span[0] and pos.line <= ct_span[0] and
|
||||||
(lt_span[0] < lt_span[1]) and
|
(lt_span[0] < lt_span[1]) and
|
||||||
(ct_span[0] < ct_span[1])):
|
(ct_span[0] < ct_span[1])):
|
||||||
ct_span[0] += 1
|
ct_span[0] += 1
|
||||||
@ -625,7 +625,7 @@ class SnippetManager(object):
|
|||||||
debug("2 lt_span: %r, ct_span: %r" % (lt_span ,ct_span))
|
debug("2 lt_span: %r, ct_span: %r" % (lt_span ,ct_span))
|
||||||
ct_span[0] = max(0, ct_span[0] - 1)
|
ct_span[0] = max(0, ct_span[0] - 1)
|
||||||
lt_span[0] = max(0, lt_span[0] - 1)
|
lt_span[0] = max(0, lt_span[0] - 1)
|
||||||
initial_line = max(0, initial_line - 1)
|
initial_line = max(cstart, initial_line - 1)
|
||||||
|
|
||||||
lt = lt[lt_span[0]:lt_span[1]]
|
lt = lt[lt_span[0]:lt_span[1]]
|
||||||
ct = ct[ct_span[0]:ct_span[1]]
|
ct = ct[ct_span[0]:ct_span[1]]
|
||||||
@ -645,9 +645,11 @@ class SnippetManager(object):
|
|||||||
self._check_if_still_inside_snippet()
|
self._check_if_still_inside_snippet()
|
||||||
if self._csnippets:
|
if self._csnippets:
|
||||||
self._csnippets[0].update_textobjects()
|
self._csnippets[0].update_textobjects()
|
||||||
self._lvb = _vim.buf[:]
|
self._lvb = _vim.buf[self._csnippets[0].start.line:self._csnippets[0].end.line + 1]
|
||||||
|
self._lvb_len = len(_vim.buf)
|
||||||
self._lpos = _vim.buf.cursor
|
self._lpos = _vim.buf.cursor
|
||||||
|
|
||||||
|
|
||||||
def leaving_window(self):
|
def leaving_window(self):
|
||||||
"""
|
"""
|
||||||
Called when the user switches tabs. It basically means that all
|
Called when the user switches tabs. It basically means that all
|
||||||
@ -806,17 +808,18 @@ class SnippetManager(object):
|
|||||||
|
|
||||||
si = snippet.launch(text_before, self._visual_content,
|
si = snippet.launch(text_before, self._visual_content,
|
||||||
self._cs.find_parent_for_new_to(start), start, end)
|
self._cs.find_parent_for_new_to(start), start, end)
|
||||||
self._visual_content.reset()
|
|
||||||
|
|
||||||
self._csnippets.append(si)
|
|
||||||
else:
|
else:
|
||||||
start = Position(_vim.buf.cursor.line, len(text_before))
|
start = Position(_vim.buf.cursor.line, len(text_before))
|
||||||
end = Position(_vim.buf.cursor.line, len(before))
|
end = Position(_vim.buf.cursor.line, len(before))
|
||||||
self._csnippets.append(snippet.launch(text_before, self._visual_content, None, start, end))
|
si = snippet.launch(text_before, self._visual_content, None, start, end)
|
||||||
|
|
||||||
self._visual_content.reset()
|
self._visual_content.reset()
|
||||||
|
self._csnippets.append(si)
|
||||||
|
|
||||||
self._ignore_movements = True
|
self._ignore_movements = True
|
||||||
self._lvb = _vim.buf[:]
|
# TODO: move this back into VimState
|
||||||
|
self._lvb = _vim.buf[self._csnippets[0].start.line:self._csnippets[0].end.line + 1]
|
||||||
|
self._lvb_len = len(_vim.buf)
|
||||||
self._lpos = _vim.buf.cursor
|
self._lpos = _vim.buf.cursor
|
||||||
|
|
||||||
self._jump()
|
self._jump()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user