parent
0646f6c9da
commit
9f22f9dbc1
|
@ -177,6 +177,8 @@ class Application(object):
|
||||||
for c in string.letters + string.digits + string.punctuation:
|
for c in string.letters + string.digits + string.punctuation:
|
||||||
obj = method.InsertString(c)
|
obj = method.InsertString(c)
|
||||||
self.methods[obj.name] = obj
|
self.methods[obj.name] = obj
|
||||||
|
obj = method.OverwriteChar(c)
|
||||||
|
self.methods[obj.name] = obj
|
||||||
|
|
||||||
# window/slot height/width
|
# window/slot height/width
|
||||||
height = self.y - 2
|
height = self.y - 2
|
||||||
|
|
|
@ -285,7 +285,10 @@ class Buffer(object):
|
||||||
p2 = Point(0, p.y + 1)
|
p2 = Point(0, p.y + 1)
|
||||||
else:
|
else:
|
||||||
p2 = Point(p.x + 1, p.y)
|
p2 = Point(p.x + 1, p.y)
|
||||||
self.delete(p, p2, act, force)
|
self.delete(p, p2, act=act, force=force)
|
||||||
|
def overwrite_char(self, p, c, act=ACT_NORM, force=False):
|
||||||
|
self.delete_char(p, act=act, force=force)
|
||||||
|
self.insert_string(p, c, act=act, force=force)
|
||||||
|
|
||||||
# random
|
# random
|
||||||
def count_leading_whitespace(self, y):
|
def count_leading_whitespace(self, y):
|
||||||
|
|
11
method.py
11
method.py
|
@ -352,12 +352,21 @@ class Exit(Method):
|
||||||
class InsertString(Method):
|
class InsertString(Method):
|
||||||
_is_method = False
|
_is_method = False
|
||||||
def __init__(self, s):
|
def __init__(self, s):
|
||||||
self.name = "insert-string-%s" % (s)
|
self.name = "insert-string-%s" % s
|
||||||
self.args = []
|
self.args = []
|
||||||
self.help = "Insert %r into the current buffer." % s
|
self.help = "Insert %r into the current buffer." % s
|
||||||
self.string = s
|
self.string = s
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.insert_string_at_cursor(self.string)
|
w.insert_string_at_cursor(self.string)
|
||||||
|
class OverwriteChar(Method):
|
||||||
|
_is_method = False
|
||||||
|
def __init__(self, c):
|
||||||
|
self.name = 'overwrite-char-%s' % c
|
||||||
|
self.args = []
|
||||||
|
self.help = "Overwrite %r into the current buffer." % c
|
||||||
|
self.char = c
|
||||||
|
def _execute(self, w, **vargs):
|
||||||
|
w.overwrite_char_at_cursor(self.char)
|
||||||
|
|
||||||
# killing/copying/etc.
|
# killing/copying/etc.
|
||||||
class Kill(Method):
|
class Kill(Method):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import string
|
||||||
import color, mode2
|
import color, mode2
|
||||||
from lex3 import Grammar, PatternRule, RegionRule
|
from lex3 import Grammar, PatternRule, RegionRule
|
||||||
|
|
||||||
|
@ -17,5 +18,13 @@ class Hex(mode2.Fundamental):
|
||||||
}
|
}
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
mode2.Fundamental.__init__(self, w)
|
mode2.Fundamental.__init__(self, w)
|
||||||
|
|
||||||
|
# create all the insert actions for the basic text input
|
||||||
|
for c in string.letters + string.digits + string.punctuation:
|
||||||
|
if c in string.hexdigits:
|
||||||
|
self.add_binding('overwrite-char-%s' % c.lower(), c)
|
||||||
|
else:
|
||||||
|
self.del_binding(c)
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return "Hex"
|
return "Hex"
|
||||||
|
|
15
window2.py
15
window2.py
|
@ -534,6 +534,21 @@ class Window(object):
|
||||||
self.application.push_kill(copied)
|
self.application.push_kill(copied)
|
||||||
return copied
|
return copied
|
||||||
|
|
||||||
|
# overwriting
|
||||||
|
def overwrite_char_at_cursor(self, c):
|
||||||
|
self.overwrite_char(self.logical_cursor(), c)
|
||||||
|
def overwrite_char(self, p, c):
|
||||||
|
line = self.buffer.lines[p.y]
|
||||||
|
if p.x >= len(line):
|
||||||
|
self.insert_string(p, c)
|
||||||
|
elif p.x == len(line) - 1:
|
||||||
|
self.buffer.overwrite_char(p, c)
|
||||||
|
if p.y < len(self.buffer.lines):
|
||||||
|
self.cursor = Point(0, p.y + 1)
|
||||||
|
else:
|
||||||
|
self.buffer.overwrite_char(p, c)
|
||||||
|
self.cursor = Point(p.x + 1, p.y)
|
||||||
|
|
||||||
# insertion
|
# insertion
|
||||||
def insert_string_at_cursor(self, s):
|
def insert_string_at_cursor(self, s):
|
||||||
self.insert_string(self.logical_cursor(), s)
|
self.insert_string(self.logical_cursor(), s)
|
||||||
|
|
Loading…
Reference in New Issue