Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if alt and key == 'r':
target = mkstruct(u"null")
block = mkstruct(u"return:value", target)
return self.insert_inline_deep(target, block, expressions)
if text == '(':
target = mkstruct(u"null")
block = mkstruct(u"call:callee:arguments", target, mutable.List([]))
return self.insert_inline(target, block, expressions)
if key == 'space':
self.selection = next_selection(mutable.get_object(selection))
overlay.dirty = True
elif len(text) > 0 and not self.insert_text(text):
if text.isalpha():
target = mutable.String(u"")
if self.insert_object(mkstruct(u'variable:name', target)):
self.selection = mutable.Selection(target, 0)
self.insert_text(text)
elif text.isdigit():
target = mutable.String(u"")
if self.insert_object(mkstruct(u'number:value', target)):
self.selection = mutable.Selection(target, 0)
self.insert_text(text)
def enter_head(obj):
if mutable.isstruct(obj) and len(obj) > 0:
return enter_head(obj[0])
if mutable.isstruct(obj):
return obj
else:
return mutable.Selection(obj, 0)
if isinstance(obj, mutable.Selection):
if mutable.iscont(obj.container) and obj.head > 0:
return enter_tail(obj.container[obj.head-1])
else:
obj = obj.container
if isinstance(obj, mutable.Document):
return mutable.Selection(obj, 0)
index = obj.parent.index(obj)
if mutable.isstruct(obj.parent):
if index > 0:
nxt = obj.parent[index-1]
return enter_tail(nxt)
else:
return walk_prev_selection(obj.parent)
else:
return mutable.Selection(obj.parent, index)
def next_selection(obj):
if isinstance(obj, mutable.Document):
return mutable.Selection(obj, len(obj))
index = obj.parent.index(obj)
if mutable.isstruct(obj.parent):
if index + 1 < len(obj.parent):
nxt = obj.parent[index+1]
if mutable.islist(nxt):
return mutable.Selection(nxt, 0)
else:
return nxt
else:
return next_selection(obj.parent)
else:
return mutable.Selection(obj.parent, index+1)
def next_selection(obj):
if isinstance(obj, mutable.Document):
return mutable.Selection(obj, len(obj))
index = obj.parent.index(obj)
if mutable.isstruct(obj.parent):
if index + 1 < len(obj.parent):
nxt = obj.parent[index+1]
if mutable.islist(nxt):
return mutable.Selection(nxt, 0)
else:
return nxt
else:
return next_selection(obj.parent)
else:
return mutable.Selection(obj.parent, index+1)
def walk_next_selection(obj):
if isinstance(obj, mutable.Selection):
if mutable.iscont(obj.container) and obj.head < obj.last:
return enter_head(obj.container[obj.head])
else:
obj = obj.container
if isinstance(obj, mutable.Document):
return mutable.Selection(obj, len(obj))
index = obj.parent.index(obj)
if mutable.isstruct(obj.parent):
if index + 1 < len(obj.parent):
nxt = obj.parent[index+1]
return enter_head(nxt)
else:
return walk_next_selection(obj.parent)
else:
return mutable.Selection(obj.parent, index+1)
def walk_next_selection(obj):
if isinstance(obj, mutable.Selection):
if mutable.iscont(obj.container) and obj.head < obj.last:
return enter_head(obj.container[obj.head])
else:
obj = obj.container
if isinstance(obj, mutable.Document):
return mutable.Selection(obj, len(obj))
index = obj.parent.index(obj)
if mutable.isstruct(obj.parent):
if index + 1 < len(obj.parent):
nxt = obj.parent[index+1]
return enter_head(nxt)
else:
return walk_next_selection(obj.parent)
else:
return mutable.Selection(obj.parent, index+1)
def enter_tail(obj):
if mutable.isstruct(obj) and len(obj) > 0:
return enter_tail(obj[len(obj)-1])
if mutable.isstruct(obj):
return obj
else:
return mutable.Selection(obj, len(obj))
def prev_selection(obj):
if isinstance(obj, mutable.Document):
return mutable.Selection(obj, 0)
index = obj.parent.index(obj)
if mutable.isstruct(obj.parent):
if index > 0:
nxt = obj.parent[index-1]
if mutable.islist(nxt):
return mutable.Selection(nxt, len(nxt))
else:
return nxt
else:
return prev_selection(obj.parent)
else:
return mutable.Selection(obj.parent, index)
def on_mousedown(button, pos):
if frame.mode is None or frame.mode.on_mousedown(button, pos):
intron = frame.pick_intron(pos)
if intron is None:
set_mode( None )
return
if isinstance(intron.controller, LayoutController):
obj = intron.controller.obj
if isinstance(obj, (mutable.List, mutable.String, mutable.Document)):
head = intron.pick_offset(pos)
set_mode( EditMode(frame, mutable.Selection(obj, head)) )
else:
set_mode( EditMode(frame, mutable.normalize(obj)) )
# replace EditMode with grabber later.