Range is now Span

This commit is contained in:
Holger Rapp 2009-07-09 14:24:43 +02:00
parent 5935131a2a
commit 4acf520a94
3 changed files with 28 additions and 33 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
__all__ = [ "Position", "Range" ] __all__ = [ "Position", "Span" ]
class Position(object): class Position(object):
@ -48,7 +48,7 @@ class Position(object):
def __repr__(self): def __repr__(self):
return "(%i,%i)" % (self._line, self._col) return "(%i,%i)" % (self._line, self._col)
class Range(object): class Span(object):
def __init__(self, start, end): def __init__(self, start, end):
self._s = start self._s = start
self._e = end self._e = end

View File

@ -4,7 +4,7 @@
import re import re
from PySnipEmu.Buffer import TextBuffer from PySnipEmu.Buffer import TextBuffer
from PySnipEmu.Geometry import Range, Position from PySnipEmu.Geometry import Span, Position
__all__ = [ "Mirror", "Transformation", "SnippetInstance", "StartMarker" ] __all__ = [ "Mirror", "Transformation", "SnippetInstance", "StartMarker" ]
@ -38,11 +38,13 @@ class TextObject(object):
self._current_text = initial_text self._current_text = initial_text
# TODO: span or range. To use both is not clever def __cmp__(self, other):
def span(self): return cmp(self._start, other._start)
return Range(self._start, self._end)
span = property(span)
##############
# PROPERTIES #
##############
def abs_start(self): def abs_start(self):
if self._parent: if self._parent:
ps = self._parent.abs_start ps = self._parent.abs_start
@ -64,12 +66,21 @@ class TextObject(object):
return self._end return self._end
abs_end = property(abs_end) abs_end = property(abs_end)
def abs_range(self): def span(self):
return Range(self.abs_start, self.abs_end) return Span(self._start, self._end)
abs_range = property(abs_range) span = property(span)
def __cmp__(self, other): def start(self):
return cmp(self._start, other._start) return self._start
start = property(start)
def end(self):
return self._end
end = property(end)
def abs_span(self):
return Span(self.abs_start, self.abs_end)
abs_span = property(abs_span)
def _do_update(self): def _do_update(self):
pass pass
@ -222,22 +233,6 @@ class TextObject(object):
self._children.append(c) self._children.append(c)
self._children.sort() self._children.sort()
def parent():
doc = "The parent TextObject this TextObject resides in"
def fget(self):
return self._parent
def fset(self, value):
self._parent = value
return locals()
parent = property(**parent())
def start(self):
return self._start
start = property(start)
def end(self):
return self._end
end = property(end)
class ChangeableText(TextObject): class ChangeableText(TextObject):
def __init__(self, parent, start, end, initial = ""): def __init__(self, parent, start, end, initial = ""):

View File

@ -87,7 +87,7 @@ class VimState(object):
self._text_changed = self._lline != vim.current.buffer[line] self._text_changed = self._lline != vim.current.buffer[line]
self._lline = vim.current.buffer[line] self._lline = vim.current.buffer[line]
def select_range(self, r): def select_span(self, r):
delta = r.end - r.start delta = r.end - r.start
lineno, col = r.start.line, r.start.col lineno, col = r.start.line, r.start.col
@ -220,7 +220,7 @@ class SnippetManager(object):
self._expect_move_wo_change = True self._expect_move_wo_change = True
self._ctab = self._csnippet.select_next_tab(backwards) self._ctab = self._csnippet.select_next_tab(backwards)
if self._ctab: if self._ctab:
self._vstate.select_range(self._ctab.abs_range) self._vstate.select_span(self._ctab.abs_span)
self._tab_selected = True self._tab_selected = True
else: else:
self._csnippet = None self._csnippet = None
@ -279,7 +279,7 @@ class SnippetManager(object):
self._ctab = self._csnippet.select_next_tab() self._ctab = self._csnippet.select_next_tab()
if self._ctab is not None: if self._ctab is not None:
self._tab_selected = True self._tab_selected = True
self._vstate.select_range(self._ctab.abs_range) self._vstate.select_span(self._ctab.abs_span)
self._vstate.update() self._vstate.update()
@ -294,7 +294,7 @@ class SnippetManager(object):
# Did we leave the snippet with this movement? # Did we leave the snippet with this movement?
if self._csnippet and not \ if self._csnippet and not \
(self._vstate.pos in self._csnippet.abs_range): (self._vstate.pos in self._csnippet.abs_span):
self.reset() self.reset()
if not self._ctab: if not self._ctab:
@ -354,7 +354,7 @@ class SnippetManager(object):
if self._csnippet and self._tab_selected: if self._csnippet and self._tab_selected:
# This only happens when a default value is delted using backspace # This only happens when a default value is delted using backspace
old_range = self._csnippet.abs_range old_span = self._csnippet.abs_span
vim.command(r'call feedkeys("i")') vim.command(r'call feedkeys("i")')
self._chars_entered('') self._chars_entered('')