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

Truncated text in floating preview #8

Open
jswny opened this issue Oct 31, 2019 · 2 comments
Open

Truncated text in floating preview #8

jswny opened this issue Oct 31, 2019 · 2 comments

Comments

@jswny
Copy link

jswny commented Oct 31, 2019

I have the plugin installed, but the text is very truncated for some reason, and in addition, there is a ~ character at the bottom of the preview window for some reason. I'm using the plugin with Deoplete and LanguageClient-NeoVim.

Here is my config:

" Don't dock the preview window to the bottom of the window
let g:float_preview#docked = 0

Screen Shot 2019-10-31 at 2 29 28 PM

@jswny
Copy link
Author

jswny commented Oct 31, 2019

I've done some more digging and it looks like the completion source is adding those truncations. However, the question still remains about the ~ character at the end of the floating window. Any idea what I can do to fix that?

@jalvesaq
Copy link

I've written the following function while adapting Nvim-R's omnicompletion to avoid truncated text in the non docked float window created by float-preview.nvim:

function FormatTxt(text, splt, jn, maxl)
    let wlist = split(a:text, a:splt)
    let txt = ['']
    let ii = 0
    let maxlen = a:maxl - len(a:jn)
    for wrd in wlist
        if len(txt[ii] . a:splt . wrd) < maxlen
            let txt[ii] .= a:splt . wrd
        else
            let ii += 1
            let txt += [wrd]
        endif
    endfor
    let txt[0] = substitute(txt[0], '^' . a:splt, '', '')
    return join(txt, a:jn)
endfunction

The arguments received by FormatTxt are:

  • text: string with text to be formated.
  • splt: string to use as pattern for split().
  • jn: string to use as pattern for join().
  • maxl: maximum length of lines.

In the above example, the text in the float window would be more readable if modified by FormatTxt as:

FormatTxt(text, ', ', ",\n  ", g:float_preview#max_width)

The two spaces after the line break would indent the output.

Python documentation is complex to format because it mix function calls with normal text which require different split and join patterns. Perhaps float-preview.nvim could have an option to define the format function for each filetype (or none in the case of R), and apply a generic format function if no format function is defined to a filetype. The basic format function could at least strip the lines from leading and trailing spaces and add line breaks at the last blank space of lines before the window width is reached.

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

2 participants