iguanacucumber / highlight-actions.nvim

Highlight changed text after an operation. Purely lua / Nvim API implementation, no external dependencies needed.
MIT License
14 stars 0 forks source link

Pasting from registers don't work #1

Open JockeM opened 2 months ago

JockeM commented 2 months ago

Pasting now always uses the normal reg So "0p wont work

NVIM v0.11.0-dev-725+g738a84de0
Build type: RelWithDebInfo
LuaJIT 2.1.1724512491
iguanacucumber commented 2 months ago

This is fixed, and this is the new default config for the Pasted action:

Pasted = {
  keymap = "p",
  cmd = "put",
  cmd_args = function() -- This function needs to return a string as a parameter to cmd
    return vim.v.register -- Return the register
  end,
},

I'm not closing the issue right now, because keymap = "P" still doesnt work ( well it works without highlighting or it behave like keymap = "p" )

iguanacucumber commented 2 months ago

I've got something working but it highlights the whole line:

InlinePasted = {
  keymap = "P",
  cmd = function()
    local line = vim.api.nvim_get_current_line() -- Get the current line
    local cursor_pos = vim.api.nvim_win_get_cursor(0) -- Get the cursor position (row, col)
    local col = cursor_pos[2]

    local clipboard_data = vim.fn.getreg(vim.v.register)

    -- Insert clipboard data at the cursor position
    local new_line = line:sub(1, col) .. clipboard_data .. line:sub(col + 1)
    vim.api.nvim_set_current_line(new_line)
  end,
},
iguanacucumber commented 1 month ago

fixed by the original author of highlight-undo, made some changes to what he did. Here's the new default config:

{
  "iguanacucumber/highlight-actions.nvim",
  keys = { "p", "P", "u", "<C-r>" },
  opts = {
    duration = 300,
    keymaps = {
      {
        fg = "#dcd7ba", -- default
        bg = "#2d4f67", -- default
        hlgroup = "HighlightUndo", -- Automatically set by "Highlight" .. lhs
        mode = "n", -- default
        lhs = "u", -- Only thing that's mandatory here
        rhs = "u", -- if not set rhs = lhs, can also be a function
        callback = function() -- do something after rhs
          openFoldsOnUndo()
        end,
        opts = { desc = "HighlightUndo" }, -- opts to vim.keymap.set()
      },
      {
        lhs = "<C-r>",
        callback = function()
          openFoldsOnUndo()
        end,
        opts = { desc = "HighlightRedo" },
      },
      { opts = { desc = "HighlightPaste" }, lhs = "p" },
      { opts = { desc = "HighlightInlinePaste" }, lhs = "P" },
      -- you also can add an action as simply as this:
      -- { lhs = 'p' }
    },
  },
},