Skip to content

Commit

Permalink
Fix insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
grierson committed Aug 15, 2023
1 parent c914c41 commit a934709
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 48 deletions.
19 changes: 6 additions & 13 deletions fnl/formedit/insertion.fnl
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
(local find (require :formedit.find))

(fn range [form]
(let [[start-row start-col end-row end-col] [(form:range)]]
[(+ start-row 1) start-col (+ end-row 1) end-col]))

(fn head []
(let [form (find.form)
start-offset (. find.start-offset (form:type))
insert-offset (. find.insert-offset (form:type))
[start-row start-col _ _] (range form)]
(vim.api.nvim_win_set_cursor 0 [start-row (+ start-col start-offset)])
(vim.api.nvim_command "normal! a ")
(vim.api.nvim_win_set_cursor 0 [start-row (+ start-col insert-offset)])
[start-row start-col] [(form:start)]
start-col (+ start-col insert-offset)]
(vim.api.nvim_buf_set_text 0 start-row start-col start-row start-col [" "])
(vim.api.nvim_feedkeys :i :n true)))

(fn tail []
(let [form (find.form)
[_ _ end-row end-col] (range form)]
(vim.api.nvim_win_set_cursor 0 [end-row (- end-col 1)])
(vim.api.nvim_command "normal! i ")
(vim.api.nvim_win_set_cursor 0 [end-row end-col])
[end-row end-col] [(form:end_)]
end-col (- end-col 1)]
(vim.api.nvim_buf_set_text 0 end-row end-col end-row end-col [" "])
(vim.api.nvim_feedkeys :i :n true)))

{: head : tail}
10 changes: 5 additions & 5 deletions fnl/spec/insertion_spec.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
(fn []
(h.setup {:content "(1)" :cursor [1 0]})
(h.feedkeys head-keymap)
(h.expect {:content "( 1)" :cursor [1 1]})))
(h.expect {:content "( 1)" :cursor [1 0]})))
(it :set
(fn []
(h.setup {:content "#{1}" :cursor [1 0]})
(h.feedkeys head-keymap)
(h.expect {:content "#{ 1}" :cursor [1 2]})))
(h.expect {:content "#{ 1}" :cursor [1 0]})))
(it "sub form"
(fn []
(h.setup {:content "(1 (2))" :cursor [1 3]})
(h.feedkeys head-keymap)
(h.expect {:content "(1 ( 2))" :cursor [1 4]})))))
(h.expect {:content "(1 ( 2))" :cursor [1 2]})))))

(describe "tail insertion"
(fn []
Expand All @@ -35,9 +35,9 @@
(fn []
(h.setup {:content "(1)" :cursor [1 0]})
(h.feedkeys tail-keymap)
(h.expect {:content "(1 )" :cursor [1 2]})))
(h.expect {:content "(1 )" :cursor [1 0]})))
(it :sub
(fn []
(h.setup {:content "(1 (2))" :cursor [1 4]})
(h.feedkeys tail-keymap)
(h.expect {:content "(1 (2 ))" :cursor [1 5]})))))
(h.expect {:content "(1 (2 ))" :cursor [1 3]})))))
35 changes: 10 additions & 25 deletions lua/formedit/insertion.lua

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

10 changes: 5 additions & 5 deletions lua/spec/insertion_spec.lua

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

0 comments on commit a934709

Please sign in to comment.