andymass / vim-matchup

vim match-up: even better % :facepunch: navigate and highlight matching words :facepunch: modern matchit and matchparen. Supports both vim and neovim + tree-sitter.
https://www.vim.org/scripts/script.php?script_id=5624
MIT License
1.7k stars 72 forks source link

Horizontal misalignment when nowrap and text is beyond left window border #257

Open Aster89 opened 1 year ago

Aster89 commented 1 year ago

Explain the issue

Most issues are related to bugs or problems. In these cases, you should include a minimal working example and a minimal vimrc file (see below), as well as:

  1. What vim version are you using? Terminal Vim, v. 9.0, patch 1-813
  2. Steps to reproduce: see screencast below (my vimrc is first shown, then the demo of the issue; you can copy and paste text if you like)
  3. Expected behavior: see screencast below
  4. Observed behavior: see screencast below

asciicast

If your issue is instead a feature request or anything else, please consider if minimal examples and vimrc files might still be relevant.

Minimal working example

Please provide a minimal working example, e.g.,

In the demo I used this, but you can use anything else fits

#include <array>
#include <iostream>
#include <utility>
#include <vector>
#include <optional>

int main()
{
    std::vector<std::array<std::optional<std::pair<std::string, std::string>>, 2>> v1{
        {std::make_pair("k1", "k2"), std::make_pair("k1", "k2")},
        {std::make_pair("k1", "k2"), std::nullopt},
        {std::nullopt, std::make_pair("k1", "k2")},
        {std::nullopt, std::nullopt}
    };
    std::vector<std::array<std::pair<std::string, std::string>, 2>> v2{
        {std::make_pair("k1", "k2"), std::make_pair("k1", "k2")},
        {std::make_pair("k1", "k2"), std::make_pair("", "")},
        {std::make_pair("", ""), std::make_pair("k1", "k2")},
        {std::make_pair("", ""), std::make_pair("", "")}
    };
    std::cout << "ciao" << std::endl;
}

Minimal vimrc file

Please provide a minimal vimrc file that reproduces the issue. The following should often suffice:

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  au VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')

Plug 'junegunn/vim-plug'
Plug 'andymass/vim-matchup'
call plug#end()
let g:matchup_matchparen_offscreen = {'method': 'popup', 'highlight': 'OffscreenPopup', 'fullwidth': 1, 'syntax_hl': 1}
let g:matchup_matchparen_stopline = 1500
let g:matchup_delim_stopline = 9000
set nowrap
Aster89 commented 1 year ago

As an unrelated question, would you point me at the part of your code that makes it possible to have syntax highlight equal to the one used by the current buffer also in the off-screen popup?

andymass commented 1 year ago

With syntax_hl: 1 the code should be here: https://github.com/andymass/vim-matchup/blob/09576fd767cc55ca934a95f9bdcf91aa12c32cd0/autoload/matchup/matchparen.vim#L705

You can see this code uses the function originally meant to build the status line string, and converts the highlight group to text properties for the popup. The reason it is done this way is at one time (and perhaps still) it was not possible to display an existing buffer in a popup window. Maybe we can check whether this can be rewritten now. On the other hand, I think this would make relativenumber impossible. There is also a feature where long function declarations will be shortened (like int func(int x... {), which will not work with buffer popup.

This code also suggests what the problem might be- clearly we are constructing a string which is too large for the present popup.