Skip to content

Commit

Permalink
Raise and move cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
grierson committed Sep 19, 2023
1 parent 9eb985b commit 5e7de4b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
6 changes: 4 additions & 2 deletions fnl/formedit/raise.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
parent (form:parent)
text (ts.get_node_text form 0)
[start-row start-col end-row end-col] [(parent:range)]]
(vim.api.nvim_buf_set_text 0 start-row start-col end-row end-col [text])))
(vim.api.nvim_buf_set_text 0 start-row start-col end-row end-col [text])
(vim.api.nvim_win_set_cursor 0 [(+ start-row 1) start-col])))

(fn element []
(let [element (find.element)
parent (element:parent)
text (ts.get_node_text element 0)
[start-row start-col end-row end-col] [(parent:range)]]
(vim.api.nvim_buf_set_text 0 start-row start-col end-row end-col [text])))
(vim.api.nvim_buf_set_text 0 start-row start-col end-row end-col [text])
(vim.api.nvim_win_set_cursor 0 [(+ start-row 1) start-col])))

{: form : element}
26 changes: 18 additions & 8 deletions fnl/spec/raise_spec.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
(local raise-form-keymap :<localleader>o)
(local raise-element-keymap :<localleader>O)


(describe :raise
(describe :raise-form
(fn []
(before_each (fn []
(set vim.g.maplocalleader localleader)
Expand All @@ -16,13 +15,24 @@
raise.element)))
(it :form
(fn []
(h.setup {:content "(1 (2))" :cursor [1 4]})
(h.setup {:content "(+ 1 (+ 2 3))" :cursor [1 5]})
(h.feedkeys raise-form-keymap)
(h.expect {:content "(2)" :cursor [1 2]})))
(it :element
(h.expect {:content "(+ 2 3)" :cursor [1 0]})))))

(describe :raise-element
(fn []
(before_each (fn []
(set vim.g.maplocalleader localleader)
(vim.keymap.set :n raise-form-keymap raise.form)
(vim.keymap.set :n raise-element-keymap
raise.element)))
(it :first-element
(fn []
(h.setup {:content "(+ 1 (+ 2 3))" :cursor [1 8]})
(h.feedkeys raise-element-keymap)
(h.expect {:content "(+ 1 2)" :cursor [1 6]})))))

(print "End")
(h.expect {:content "(+ 1 2)" :cursor [1 5]})))
(it :second-element
(fn []
(h.setup {:content "(+ 1 (+ 2 3))" :cursor [1 10]})
(h.feedkeys raise-element-keymap)
(h.expect {:content "(+ 1 3)" :cursor [1 5]})))))
6 changes: 4 additions & 2 deletions lua/formedit/raise.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 22 additions & 8 deletions lua/spec/raise_spec.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e7de4b

Please sign in to comment.