From 4e445b485977dc3ad8896c60d0bce4eb7598bf37 Mon Sep 17 00:00:00 2001 From: Artem Medeu Date: Mon, 14 Aug 2023 16:59:10 +0600 Subject: [PATCH] revert last 4 commits --- lua/nvim-paredit/api/barfing.lua | 40 ++++++++++++++++++------------- lua/nvim-paredit/api/slurping.lua | 34 ++++++++++---------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/lua/nvim-paredit/api/barfing.lua b/lua/nvim-paredit/api/barfing.lua index 264f957..d1409ea 100644 --- a/lua/nvim-paredit/api/barfing.lua +++ b/lua/nvim-paredit/api/barfing.lua @@ -26,9 +26,16 @@ function M.barf_forwards(opts) return end - local child = traversal.get_last_child_ignoring_comments(form, { - lang = lang, - }) + local child + if opts.reversed then + child = traversal.get_first_child_ignoring_comments(form, { + lang = lang, + }) + else + child = traversal.get_last_child_ignoring_comments(form, { + lang = lang, + }) + end if not child then return end @@ -128,24 +135,14 @@ function M.barf_backwards(opts) local buf = vim.api.nvim_get_current_buf() local text = edges.left.text - local edge_len = 0 - local range = edges.left.range - local is_separate_row = range[1] ~= end_pos[1] - if is_separate_row then - edge_len = string.len(text) - end -- stylua: ignore - vim.api.nvim_buf_set_text(buf, - end_pos[1], end_pos[2] - edge_len, - end_pos[1], end_pos[2] - edge_len, - {text} - ) vim.api.nvim_buf_set_text(buf, end_pos[1], end_pos[2], - end_pos[1], end_pos[2] + edge_len, - {} + end_pos[1], end_pos[2], + { text } ) + local range = edges.left.range -- stylua: ignore vim.api.nvim_buf_set_text( buf, @@ -154,6 +151,17 @@ function M.barf_backwards(opts) {} ) + indentation.handle_indentation({ + type = "barf", + from = range, + to = { end_pos[1], end_pos[2], end_pos[1], end_pos[2] }, + child = child, + parent = form, + + indent_behaviour = opts.indent_behaviour or config.config.indent_behaviour, + lang = lang, + }) + local cursor_behaviour = opts.cursor_behaviour or config.config.cursor_behaviour if cursor_behaviour == "auto" or cursor_behaviour == "follow" then local cursor_pos = vim.api.nvim_win_get_cursor(0) diff --git a/lua/nvim-paredit/api/slurping.lua b/lua/nvim-paredit/api/slurping.lua index b5ee5be..9482543 100644 --- a/lua/nvim-paredit/api/slurping.lua +++ b/lua/nvim-paredit/api/slurping.lua @@ -67,38 +67,28 @@ local function slurp(opts) ) local offset = 0 - local edge_len = string.len(left_or_right_edge.text) if opts.reversed and row == left_or_right_edge.range[1] then - offset = edge_len + offset = string.len(left_or_right_edge.text) end - - local token - if opts.reversed and offset == 0 then - token = string.rep(" ", edge_len) - elseif offset > 0 then - token = "" - end -- stylua: ignore vim.api.nvim_buf_set_text( buf, left_or_right_edge.range[1], left_or_right_edge.range[2] + offset, left_or_right_edge.range[3], left_or_right_edge.range[4] + offset, - {token} + {} ) - if not opts.reversed then - indentation.handle_indentation({ - type = "slurp", - from = left_or_right_edge.range, - to = { row, col, row, col }, - child = sibling, - parent = form, - reversed = opts.reversed, - indent_behaviour = opts.indent_behaviour or config.config.indent_behaviour, - lang = lang, - }) - end + indentation.handle_indentation({ + type = "slurp", + from = left_or_right_edge.range, + to = { row, col, row, col }, + child = sibling, + parent = form, + + indent_behaviour = opts.indent_behaviour or config.config.indent_behaviour, + lang = lang, + }) local cursor_behaviour = opts.cursor_behaviour or config.config.cursor_behaviour if cursor_behaviour == "follow" then