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

Scrollview hides text at the end of a line #132

Open
lostl1ght opened this issue Jun 28, 2024 · 7 comments
Open

Scrollview hides text at the end of a line #132

lostl1ght opened this issue Jun 28, 2024 · 7 comments

Comments

@lostl1ght
Copy link

Hello!

I'm not sure if it is a bug or not but the scrollbar hides text at the end of a line. Is there any way to wrap text before scrollbar?

Steps to reproduce

  • nvim -u min.lua
  • :e somefile.txt
  • Add a window or resize it so that text is wrapped.
  • Observe how letters at the end of a line are hidden behind the scrollbar (screenshot below).
Minimal config
local root = '/tmp/nvim'

for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

local lazy_path = root .. '/plugins/lazy.nvim'
if not vim.uv.fs_stat(lazy_path) then
  vim.api.nvim_cmd({
    cmd = '!',
    args = {
      'git',
      'clone',
      '--filter=blob:none',
      '--single-branch',
      'https://github.com/folke/lazy.nvim.git',
      lazy_path,
    },
  }, {})
end
vim.opt.runtimepath:prepend(lazy_path)

local plugins = {
  { 'folke/lazy.nvim' },
  { 'rebelot/kanagawa.nvim' },
  -- plugins
  {
    'dstein64/nvim-scrollview',
    dependencies = { 'lewis6991/gitsigns.nvim', config = true },
    config = function()
      vim.cmd([[let g:scrollview_mode = 'proper']])
      require('scrollview.contrib.gitsigns').setup()
    end,
  },
}

vim.g.mapleader = ' '

require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

vim.opt.termguicolors = true
vim.cmd({ cmd = 'colorscheme', args = { 'kanagawa' } })

Below the letters ex are hidden:
image

@dstein64
Copy link
Owner

dstein64 commented Jun 29, 2024

Hi @lostl1ght. I don't know of a Neovim option for specifying where text should wrap when wrap is set.

The plugin has options for controlling the transparency of its windows. If you're using termguicolors or a GUI, the option is scrollview_winblend_gui, otherwise the option is scrollview_winblend. They can be set between 0 and 100 (0 for full opacity and 100 for full transparency).

However, transparency only works if there is no text (on scrollbars and/or signs). By default, the scrollbar has no text (this can be changed with the scrollview_character option). By default, the built-in signs all include text. To make them transparent, they'd have to be configured to have no symbol, and a highlight that has a background color (the foreground highlight would only be applied to text).

Here's an example showing how the scrollbar and search signs could be made partially transparent.

let g:scrollview_winblend = 80
let g:scrollview_winblend_gui = 80
highlight ScrollViewSearch ctermbg=159 guibg=LightCyan
let g:scrollview_search_symbol = ''

But removing the text from signs makes them less useful. They'd have to be differentiated based on their color only.

@lostl1ght
Copy link
Author

So, it appears that there's no option to wrap before EOL. And, unfortunately, the suggested plugin setting are not ideal.

Other option is to toggle the scrollbar on InsertEnter & InsertLeave, so that it does not obstruct text in insert mode, but, again, it's not ideal.

You can close as not planned if you'd like.

@Andrew15-5
Copy link

Andrew15-5 commented Oct 3, 2024

I think we are missing this feature: neovim/neovim#4386.

Other option is to toggle the scrollbar on InsertEnter & InsertLeave, so that it does not obstruct text in insert mode

That's interesting, I will try this, but sometimes I have to edit in normal mode, so this can still be a problem, but less. Yeah, not ideal.

BTW, my problem is that sometimes some signs (?) are blocking the cell completely, like here:

image

So the fact that I have a transparent scrollbar doesn't mean anything. But now that I disable diagnostics on InsertEnter:

image

So at least entering and leaving the insert mode is much easier than pure pain of not seeing what is behind there. And I think this problem will only happen in text files (plain, Typst, Markdown etc.) and not in code files. Basically in half of the cases for me. ;)

@dstein64
Copy link
Owner

dstein64 commented Oct 12, 2024

I've added a new option, scrollview_hide_for_insert, for hiding scrollbars and signs for insert mode.

Vimscript:

let g:scrollview_hide_for_insert = v:true

Lua:

vim.g.scrollview_hide_for_insert = true

-- Or with a setup function:
require('scrollview').setup({
  ...
  hide_for_insert = true,
  ...
})

Another workaround could be to use a mapping that toggles the plugin. For example, the following sets <ctrl-v> to toggle the plugin, including in insert mode.

noremap <c-v> <Plug>(ScrollViewToggle)
inoremap <c-v> <Plug>(ScrollViewToggle)

@Andrew15-5
Copy link

Andrew15-5 commented Oct 12, 2024

That's a good addition, but can you expand it to be able to customize which part gets hidden? I tried it, and I don't like that it also hides an already semitransparent scrollbar.

Instead, I use:

local scrollview_group = vim.api.nvim_create_augroup("scrollview", {})
vim.api.nvim_create_autocmd({ "InsertEnter" }, {
  callback = function()
    vim.cmd [[silent ScrollViewDisable diagnostics]]
  end,
  group = scrollview_group,
})
vim.api.nvim_create_autocmd({ "InsertLeave" }, {
  callback = function()
    vim.cmd [[silent ScrollViewEnable diagnostics]]
  end,
  group = scrollview_group,
})

Like, it can be true for everything or can be a table with a list of things to disable individually. So for me, it would be:

require("scrollview").setup {
  hide_for_insert = { "diagnostics" },
}

@dstein64
Copy link
Owner

Hi @Andrew15-5. I've replaced scrollview_hide_for_insert with two separate options, scrollview_signs_hidden_for_insert and scrollview_hide_bar_for_insert. The first specifies a list of sign groups that will be hidden for insert mode. 'all' can be used to represent all sign groups. The second option uses a boolean to indicate whether the scrollbar will be hidden for insert mode.

The following examples will hide all signs and the scrollbar.

Vimscript:

let g:scrollview_signs_hidden_for_insert = ['all']
let g:scrollview_hide_bar_for_insert = v:true

Lua:

vim.g.scrollview_signs_hidden_for_insert = {'all'}
vim.g.scrollview_hide_bar_for_insert = true

-- Or with a setup function:
require('scrollview').setup({
  ...
  signs_hidden_for_insert = {'all'},
  hide_bar_for_insert = true,
  ...
})

The following examples will hide just the diagnostics signs.

Vimscript:

let g:scrollview_signs_hidden_for_insert = ['diagnostics']

Lua:

vim.g.scrollview_signs_hidden_for_insert = {'diagnostics'}

-- Or with a setup function:
require('scrollview').setup({
  ...
  signs_hidden_for_insert = {'diagnostics'},
  ...
})

@Andrew15-5
Copy link

Thank you very much. My config is now much cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants