Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input: newlines in contents #119

Closed
emmanueltouzery opened this issue Sep 29, 2023 · 1 comment
Closed

input: newlines in contents #119

emmanueltouzery opened this issue Sep 29, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@emmanueltouzery
Copy link
Contributor

emmanueltouzery commented Sep 29, 2023

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

  • OS: linux
  • Neovim version: 0.9.1
  • Is this related to a specific vim.ui.select backend? If so, which one? no (it's input related)
  • Dressing config:
    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
Copy link
Owner

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

emmanueltouzery added a commit to emmanueltouzery/nvim_config that referenced this issue Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants