From 7dab75f4116ede48ca94380a813d8cb91b61c2af Mon Sep 17 00:00:00 2001 From: Kyle Grierson Date: Fri, 18 Aug 2023 09:57:25 +0100 Subject: [PATCH] Fix tail insertion --- fnl/formedit/insertion.fnl | 2 +- fnl/spec/insertion_spec.fnl | 8 +++----- lua/formedit/insertion.lua | 2 +- lua/spec/insertion_spec.lua | 9 ++++----- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/fnl/formedit/insertion.fnl b/fnl/formedit/insertion.fnl index e56a94e..98167e5 100644 --- a/fnl/formedit/insertion.fnl +++ b/fnl/formedit/insertion.fnl @@ -14,7 +14,7 @@ [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_win_set_cursor 0 [(+ end-row 1) end-row]) + (vim.api.nvim_win_set_cursor 0 [(+ end-row 1) (+ end-col 1)]) (vim.api.nvim_feedkeys :i :n true))) {: head : tail} diff --git a/fnl/spec/insertion_spec.fnl b/fnl/spec/insertion_spec.fnl index add4dec..2c006a7 100644 --- a/fnl/spec/insertion_spec.fnl +++ b/fnl/spec/insertion_spec.fnl @@ -3,7 +3,7 @@ (local insertion (require :formedit.insertion)) (local head-keymap :h) -(local tail-keymap :t) +(local tail-keymap :H) (describe "head insertion" (fn [] @@ -35,11 +35,9 @@ (fn [] (h.setup {:content "(1)" :cursor [1 0]}) (h.feedkeys tail-keymap) - (h.expect {:content "(1 )" :cursor [1 3]}))) + (h.expect {:content "(1 )" :cursor [1 2]}))) (it :sub (fn [] (h.setup {:content "(1 (2))" :cursor [1 3]}) (h.feedkeys tail-keymap) - (h.expect {:content "(1 (2 ))" :cursor [1 6]}))))) - -(print "foo") + (h.expect {:content "(1 (2 ))" :cursor [1 5]}))))) diff --git a/lua/formedit/insertion.lua b/lua/formedit/insertion.lua index f29529b..e6a1aa3 100644 --- a/lua/formedit/insertion.lua +++ b/lua/formedit/insertion.lua @@ -18,7 +18,7 @@ local function tail() local end_col = _let_2_[2] local end_col0 = (end_col - 1) vim.api.nvim_buf_set_text(0, end_row, end_col0, end_row, end_col0, {" "}) - vim.api.nvim_win_set_cursor(0, {(end_row + 1), end_row}) + vim.api.nvim_win_set_cursor(0, {(end_row + 1), (end_col0 + 1)}) return vim.api.nvim_feedkeys("i", "n", true) end return {head = head, tail = tail} diff --git a/lua/spec/insertion_spec.lua b/lua/spec/insertion_spec.lua index b8e83e8..b6ad634 100644 --- a/lua/spec/insertion_spec.lua +++ b/lua/spec/insertion_spec.lua @@ -6,7 +6,7 @@ local before_each = _local_1_["before_each"] local h = require("spec.helper") local insertion = require("formedit.insertion") local head_keymap = "h" -local tail_keymap = "t" +local tail_keymap = "H" local function _2_() local function _3_() vim.g.maplocalleader = "," @@ -42,15 +42,14 @@ local function _7_() local function _9_() h.setup({content = "(1)", cursor = {1, 0}}) h.feedkeys(tail_keymap) - return h.expect({content = "(1 )", cursor = {1, 3}}) + return h.expect({content = "(1 )", cursor = {1, 2}}) end it("form", _9_) local function _10_() h.setup({content = "(1 (2))", cursor = {1, 3}}) h.feedkeys(tail_keymap) - return h.expect({content = "(1 (2 ))", cursor = {1, 6}}) + return h.expect({content = "(1 (2 ))", cursor = {1, 5}}) end return it("sub", _10_) end -describe("tail insertion", _7_) -return print("foo") +return describe("tail insertion", _7_)