much better cursor behaviour on line insert / delete

This commit is contained in:
Jeremy Penner 2020-08-02 00:35:44 -04:00
parent 8ce0a6438c
commit 43a66bebeb

View file

@ -344,8 +344,8 @@ class SyntBlock(Synt):
with pcur.Indent(2 if pcur.pwHoriz != None else 0): with pcur.Indent(2 if pcur.pwHoriz != None else 0):
pcur.EndLine() pcur.EndLine()
def OnInsertNewLine(syntAfter, psel): def OnInsertNewLine(syntAfter, psel):
self.InsertLineAfter(syntAfter, None) self.InsertLineAfter(syntAfter)
# psel.Inc(pcur.pwVert) # does nothing because we need to reproject psel.Inc(pcur.Reset().Project().pwVert)
PwButtonHidden(pcur.pwVert, "[insert new line]", None, OnInsertNewLine, pcur.dxindent) PwButtonHidden(pcur.pwVert, "[insert new line]", None, OnInsertNewLine, pcur.dxindent)
for syntLine in self.rgsynt: for syntLine in self.rgsynt:
pwKey = PwKeyHandler(pcur.pwVert, self.HandleKey) pwKey = PwKeyHandler(pcur.pwVert, self.HandleKey)
@ -355,9 +355,8 @@ class SyntBlock(Synt):
def StypeForChild(self, syntChild): def StypeForChild(self, syntChild):
return StypeStmt() return StypeStmt()
def InsertLineAfter(self, syntAfter, syntStmt): def InsertLineAfter(self, syntAfter):
if syntStmt == None: syntStmt = SyntHole()
syntStmt = SyntHole()
if syntAfter == None: if syntAfter == None:
self.rgsynt.insert(0, syntStmt) self.rgsynt.insert(0, syntStmt)
else: else:
@ -370,7 +369,10 @@ class SyntBlock(Synt):
def HandleKey(self, pwKey, pov, psel, key): def HandleKey(self, pwKey, pov, psel, key):
if ansi.FEnter(key): if ansi.FEnter(key):
self.InsertLineAfter(pwKey.pwChild.Value(), None) self.InsertLineAfter(pwKey.pwChild.Value())
clevelVert = psel.CLevelChild(pwKey.PwParent())
pwVert = psel.PwSelected(pov.PwProjected(), clevelVert - 1)
psel.Inc(pwVert)
return True return True
elif key == ansi.K_DEL and pwKey.pwChild.RgpwChild()[0] == psel.PwSelected(pwKey): elif key == ansi.K_DEL and pwKey.pwChild.RgpwChild()[0] == psel.PwSelected(pwKey):
self.RemoveLine(pwKey.pwChild.Value()) self.RemoveLine(pwKey.pwChild.Value())
@ -497,18 +499,27 @@ class Pcur(object):
@staticmethod @staticmethod
def PwProjected(defs, synt, dgDone): def PwProjected(defs, synt, dgDone):
pcur = Pcur(defs, synt) pcur = Pcur(defs, synt)
synt.Project(pcur) pcur.Project(dgDone)
PwStatic(pcur.pwVert, ' ')
PwButton(pcur.pwVert, 'Save and go back to editor', defs, dgDone)
return pcur.pwSplit return pcur.pwSplit
def __init__(self, defs, synt): def __init__(self, defs, synt):
self.defs = defs self.defs = defs
self.synt = synt
self.Reset()
def Reset(self):
self.pwSplit = PwSplit(None, 80) self.pwSplit = PwSplit(None, 80)
self.pwVert = PwBlock(self.pwSplit, synt, 0) self.pwVert = PwBlock(self.pwSplit, self.synt, 0)
self.pwHoriz = None self.pwHoriz = None
self.pwTooltip = PwTooltip(self.pwSplit) self.pwTooltip = PwTooltip(self.pwSplit)
self.dxindent = 0 self.dxindent = 0
return self
def Project(self, dgDone = None):
self.synt.Project(self)
PwStatic(self.pwVert, ' ')
PwButton(self.pwVert, 'Save and go back to editor', self.defs, dgDone)
return self
@contextmanager @contextmanager
def Indent(self, dxindent = 2): def Indent(self, dxindent = 2):
@ -903,6 +914,9 @@ class Psel(TPrs):
pw = pw.PwParent() pw = pw.PwParent()
return (clevelChild, pw) return (clevelChild, pw)
def CLevelChild(self, pw):
return self.CLevelChild_PwRoot(pw)[0]
def PwRoot(self, pw): def PwRoot(self, pw):
return self.CLevelChild_PwRoot(pw)[1] return self.CLevelChild_PwRoot(pw)[1]
@ -959,8 +973,6 @@ class Pov(TokenClient):
def run(self): def run(self):
while True: while True:
key = self.EvKey().receive(self) key = self.EvKey().receive(self)
if key == ansi.K_PGDN:
self.block.Eval(Vm(self.defs))
psel = self.pselstate.PselByClient(self.client) psel = self.pselstate.PselByClient(self.client)
pwSel = psel.PwSelected(self.PwProjected()) pwSel = psel.PwSelected(self.PwProjected())
while pwSel != None: while pwSel != None: