stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.69k stars 32 forks source link

input: newlines in contents #119

Closed emmanueltouzery closed 9 months ago

emmanueltouzery commented 9 months ago

Describe the bug

so i stumbled on a problem with the input component when having multiline data... i had in my clipboard: "\ntext", so the first character is a newline. I got that by pasting something from discord.

I pasted that in the dressing input and the input showed "text" as if it was a single line. However when the callback is called, it receives "", so only the first line.

See: https://github.com/stevearc/dressing.nvim/blob/master/lua/dressing/input.lua#L141

I think dressing should make some effort to return the line that it's displaying, which apparently may not necessarily be the first one.

Note that I could reproduce by selecting character-wise the text with the newline from neovim (v and move the cursor) before copying. If I copied line-wise (shift-v) then dressing did display an empty line after pasting.

System information

    require('dressing').setup({
      input = {
        -- ESC won't close the modal, ability to use vim keys
        insert_only = false,
        get_config = function(opts)
          if opts.kind == 'center_win' then
            return {
              relative = 'editor',
            }
          end
        end
      },
      select = {
        get_config = function(opts)
          -- https://github.com/stevearc/dressing.nvim/issues/22#issuecomment-1067211863
          -- for codeaction, we want null-ls to be last
          -- https://github.com/jose-elias-alvarez/null-ls.nvim/issues/630
          -- for eslint, it's offering me options like "disable eslint rule" which
          -- are almost never what I want, and they appear before the more useful options
          -- from the LSP
          if opts.kind == 'codeaction' then
            return {
              telescope = {
                sorter = require'telescope.sorters'.Sorter:new {
                  scoring_function = function(_, _, line)
                    local order = tonumber(string.match(line, "^[%d]+"))
                    if string.find(line, escape_pattern('null-ls')) then
                      return order+100
                    else
                      return order
                    end
                  end,
                },
                cache_picker = false,
                -- copied from the telescope dropdown theme
                sorting_strategy = "ascending",
                layout_strategy = "center",
                layout_config = {
                  preview_cutoff = 1, -- Preview should always show (unless previewer = false)
                  width = 80,
                  height = 15,
                },
                borderchars = {
                  prompt = { "─", "│", " ", "│", "╭", "╮", "│", "│" },
                  results = { "─", "│", "─", "│", "├", "┤", "╯", "╰" },
                  preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
                },
              }
            }
          end
        end,
      },
    })

To Reproduce Steps to reproduce the behavior:

  1. put in the clipboard [newline]text
  2. open a dressing input dialog
  3. paste
stevearc commented 9 months ago

To match the behavior of :help input(), I've updated it to only accept a single line of input. If you paste in a multiline string, it will now trim whitespace and remove trailing lines until there is only one line