about summary refs log tree commit diff stats
path: root/zet.tlv
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-02-11 10:40:24 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-02-11 10:40:24 -0800
commitbbd47aaa5b0b6535fa967b4d397a7a9015f3d53c (patch)
tree14c935abb165949738cc30c8f996a89fd005bb0c /zet.tlv
parent2d3cad5945dcd84a6e3dff4de4ca2d187b087d83 (diff)
downloadteliva-bbd47aaa5b0b6535fa967b4d397a7a9015f3d53c.tar.gz
zet.tlv: yet another bugfix
Need for tests growing more acute..
Diffstat (limited to 'zet.tlv')
-rw-r--r--zet.tlv141
1 files changed, 141 insertions, 0 deletions
diff --git a/zet.tlv b/zet.tlv
index c7da813..fb79385 100644
--- a/zet.tlv
+++ b/zet.tlv
@@ -2368,3 +2368,144 @@
     >    -- We could silently fail to save.
     >  end
     >end
+- __teliva_timestamp:
+    >Fri Feb 11 07:51:42 2022
+  __teliva_note:
+    >bugfix in parent link when inserting child
+  update:
+    >function update(window)
+    >  local key = curses.getch()
+    >  local h, w = window:getmaxyx()
+    >  local curr = zettels[current_zettel_id]
+    >  assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id)))
+    >  -- move along the graph
+    >  if key == string.byte('j') then
+    >    if curr.child then
+    >      current_zettel_id = curr.child
+    >    elseif curr.next then
+    >      current_zettel_id = curr.next
+    >    elseif curr.parent and zettels[curr.parent].next then
+    >      current_zettel_id = zettels[curr.parent].next
+    >    end
+    >  elseif key == string.byte('k') then
+    >    if curr.parent then
+    >      current_zettel_id = curr.parent
+    >    end
+    >  elseif key == string.byte('h') then
+    >    if curr.prev then
+    >      current_zettel_id = curr.prev
+    >    elseif curr.parent then
+    >      current_zettel_id = curr.parent
+    >    end
+    >  elseif key == string.byte('l') then
+    >    if curr.next then
+    >      current_zettel_id = curr.next
+    >    elseif curr.parent and zettels[curr.parent].next then
+    >      current_zettel_id = zettels[curr.parent].next
+    >    end
+    >  -- move along the screen
+    >  elseif key == curses.KEY_UP then
+    >    if render_state.curr_h > 1 then
+    >      current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1]
+    >    end
+    >  elseif key == curses.KEY_DOWN then
+    >    if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then
+    >      current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1]
+    >    end
+    >  elseif key == curses.KEY_LEFT then
+    >    if render_state.curr_w > 1 then
+    >      current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h]
+    >    end
+    >  elseif key == curses.KEY_RIGHT then
+    >    if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then
+    >      current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h]
+    >    end
+    >  -- mutations
+    >  elseif key == string.byte('e') then
+    >    editz(window)
+    >  elseif key == string.byte('a') then
+    >    -- insert sibling after
+    >    local old = curr.next
+    >    curr.next = new_id()
+    >    local new = zettels[curr.next]
+    >    new.data = ''
+    >    new.next = old
+    >    new.prev = current_zettel_id
+    >    if old then
+    >      zettels[old].prev = curr.next
+    >      assert(curr.parent == zettels[old].parent, 'siblings should have same parent')
+    >    end
+    >    new.parent = curr.parent
+    >    current_zettel_id = curr.next
+    >    render(window) -- recompute render_state
+    >    editz(window)
+    >  elseif key == string.byte('b') then
+    >    -- insert sibling before
+    >    local old = curr.prev
+    >    curr.prev = new_id()
+    >    local new = zettels[curr.prev]
+    >    new.data = ''
+    >    new.prev = old
+    >    new.next = current_zettel_id
+    >    if old then
+    >      zettels[old].next = curr.prev
+    >      assert(curr.parent == zettels[old].parent, 'siblings should have same parent')
+    >    end
+    >    new.parent = curr.parent
+    >    current_zettel_id = curr.prev
+    >    render(window) -- recompute render_state
+    >    editz(window)
+    >  elseif key == string.byte('c') then
+    >    -- insert child
+    >    local old = curr.child
+    >    curr.child = new_id()
+    >    local new = zettels[curr.child]
+    >    new.data = ''
+    >    new.next = old
+    >    if old then
+    >      assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling")
+    >      zettels[old].prev = curr.child
+    >    end
+    >    new.parent = current_zettel_id
+    >    current_zettel_id = curr.child
+    >    render(window) -- recompute render_state
+    >    editz(window)
+    >  -- cross-links
+    >  elseif key == string.byte('s') then
+    >    -- save zettel to a stash
+    >    stash = current_zettel_id
+    >  elseif key == string.byte('t') then
+    >    -- cross-link a zettel bidirectionally with what's on the stash
+    >    local insert_crosslink =
+    >      function(a, rel, b_id)
+    >        if a.crosslinks == nil then
+    >          a.crosslinks = {}
+    >        end
+    >        a.crosslinks[rel] = b_id
+    >      end
+    >    insert_crosslink(curr, 'a', stash)
+    >    insert_crosslink(zettels[stash], 'a', current_zettel_id)
+    >    stash = nil
+    >  -- view settings
+    >  elseif key == string.byte('x') then
+    >    if view_settings.width > 5 then
+    >      view_settings.width = view_settings.width - 5
+    >    end
+    >  elseif key == string.byte('X') then
+    >    if view_settings.width < w-5 then
+    >      view_settings.width = view_settings.width + 5
+    >    end
+    >  elseif key == string.byte('y') then
+    >    if view_settings.height > 0 then
+    >      view_settings.height = view_settings.height - 1
+    >    end
+    >  elseif key == string.byte('Y') then
+    >    if view_settings.height < h-2 then
+    >      view_settings.height = view_settings.height + 1
+    >    end
+    >  elseif key == string.byte('z') then
+    >    -- scroll to show the current zettel at top of screen
+    >    -- often has the effect of zooming in on its hierarchy
+    >    view_settings.first_zettel = current_zettel_id
+    >  end
+    >end