stevearc / dressing.nvim

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

fix: take into account prompt size in nui and builtin selects #135

Closed AlexJF closed 5 months ago

AlexJF commented 5 months ago

Context

Width calculation logic in nui and builtin selects ignores prompt size. This makes it very easy to lose crucial information required to make a decision.

For example, here's what I see when running LspStart with the vtsls language server with master of stevearc/dressing.nvim:

image image

And here's what I see with this PR:

image image

Description

Initialize max_width (builtin) or line_width (nui) to the prompt length if it exists. Otherwise fallback to previous value of 1.

Test Plan

Used the manual select test with the following configuration:

-- Run this test with :source %

local function run_test(backend)
  local config = require("dressing.config")
  local prev_backend = config.select.backend
  config.select.backend = backend
  vim.ui.select({
    "first",
    "second",
    "third",
  }, {
    prompt = "Make a very informed selection after having collected all data and considered all viewpoints and opinions: ",
    kind = "test",
  }, function(item, lnum)
    if item and lnum then
      vim.notify(string.format("selected '%s' (idx %d)", item, lnum), vim.log.levels.INFO)
    else
      vim.notify("Selection canceled", vim.log.levels.INFO)
    end
    config.select.backend = prev_backend
  end)
end

-- Replace this with the desired backend to test
run_test("builtin")
--run_test("nui")

Before

image image

After

image image
stevearc commented 5 months ago

Thanks for the PR!