From 6774ec04252973d6f863ee9073fb00e960ccd1ae Mon Sep 17 00:00:00 2001 From: Kyle Grierson Date: Tue, 15 Aug 2023 14:34:28 +0100 Subject: [PATCH] Fix cursor placement for wrap --- fnl/formedit/wrap.fnl | 2 +- fnl/spec/wrap_spec.fnl | 7 +++---- lua/formedit/wrap.lua | 2 +- lua/spec/wrap_spec.lua | 9 ++++----- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/fnl/formedit/wrap.fnl b/fnl/formedit/wrap.fnl index a93bdc9..c86c325 100644 --- a/fnl/formedit/wrap.fnl +++ b/fnl/formedit/wrap.fnl @@ -7,7 +7,7 @@ (vim.api.nvim_buf_set_text 0 end-row end-col end-row end-col [")"]) (vim.api.nvim_buf_set_text 0 start-row start-col start-row start-col ["( "]) (vim.api.nvim_win_set_cursor 0 - [(+ start-row 1) (+ start-col insert-offset)]) + [(+ start-row 1) (+ start-col insert-offset 1)]) (vim.api.nvim_feedkeys :i :n true))) {: head} diff --git a/fnl/spec/wrap_spec.fnl b/fnl/spec/wrap_spec.fnl index 3508d74..6ad1d52 100644 --- a/fnl/spec/wrap_spec.fnl +++ b/fnl/spec/wrap_spec.fnl @@ -13,11 +13,10 @@ (fn [] (h.setup {:content "(1)" :cursor [1 0]}) (h.feedkeys keymap) - (h.expect {:content "( (1))" :cursor [1 0]}))) + (h.expect {:content "( (1))" :cursor [1 1]}))) (it "sub form" (fn [] - (h.setup {:content "(1 (2))" :cursor [1 4]}) + (h.setup {:content "(1 (2))" :cursor [1 3]}) (h.feedkeys keymap) - (h.expect {:content "(1 ( (2)))" :cursor [1 3]}))))) + (h.expect {:content "(1 ( (2)))" :cursor [1 4]}))))) -(print :foo) diff --git a/lua/formedit/wrap.lua b/lua/formedit/wrap.lua index 771a5b8..0b61552 100644 --- a/lua/formedit/wrap.lua +++ b/lua/formedit/wrap.lua @@ -10,7 +10,7 @@ local function head() local end_col = _let_1_[4] vim.api.nvim_buf_set_text(0, end_row, end_col, end_row, end_col, {")"}) vim.api.nvim_buf_set_text(0, start_row, start_col, start_row, start_col, {"( "}) - vim.api.nvim_win_set_cursor(0, {(start_row + 1), (start_col + insert_offset)}) + vim.api.nvim_win_set_cursor(0, {(start_row + 1), (start_col + insert_offset + 1)}) return vim.api.nvim_feedkeys("i", "n", true) end return {head = head} diff --git a/lua/spec/wrap_spec.lua b/lua/spec/wrap_spec.lua index 202228d..b538ebd 100644 --- a/lua/spec/wrap_spec.lua +++ b/lua/spec/wrap_spec.lua @@ -15,15 +15,14 @@ local function _2_() local function _4_() h.setup({content = "(1)", cursor = {1, 0}}) h.feedkeys(keymap) - return h.expect({content = "( (1))", cursor = {1, 0}}) + return h.expect({content = "( (1))", cursor = {1, 1}}) end it("form head", _4_) local function _5_() - h.setup({content = "(1 (2))", cursor = {1, 4}}) + h.setup({content = "(1 (2))", cursor = {1, 3}}) h.feedkeys(keymap) - return h.expect({content = "(1 ( (2)))", cursor = {1, 3}}) + return h.expect({content = "(1 ( (2)))", cursor = {1, 4}}) end return it("sub form", _5_) end -describe("wrap", _2_) -return print("foo") +return describe("wrap", _2_)