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