Add borders for floating windows in Neovim (#3603)
* Add borders for floating windows in Neovim * Add docs for floating window border setting Co-authored-by: w0rp <w0rp@users.noreply.github.com>
This commit is contained in:
parent
680ba68d81
commit
1d76fd55a1
4 changed files with 78 additions and 6 deletions
17
README.md
17
README.md
|
@ -907,3 +907,20 @@ tools are well-integrated with ALE, and ALE is properly configured to run the
|
|||
correct commands and map filename paths between different file systems. See
|
||||
`:help ale-lint-other-machines` for the full documentation on how to configure
|
||||
ALE to support this.
|
||||
|
||||
### 5.xxi. How can I change the borders for floating preview windows?
|
||||
|
||||
Borders for floating preview windows are enabled by default. You can use the
|
||||
`g:ale_floating_window_border` setting to configure them.
|
||||
|
||||
You could disable the border with an empty list.
|
||||
|
||||
```vim
|
||||
let g:ale_floating_window_border = []
|
||||
```
|
||||
|
||||
If the terminal supports Unicode, you might try setting the value like below, to make it look nicer.
|
||||
|
||||
```vim
|
||||
let g:ale_floating_window_border = ['│', '─', '╭', '╮', '╯', '╰']
|
||||
```
|
||||
|
|
|
@ -47,16 +47,53 @@ function! ale#floating_preview#Show(lines, ...) abort
|
|||
endif
|
||||
augroup END
|
||||
|
||||
let l:width = max(map(copy(a:lines), 'strdisplaywidth(v:val)'))
|
||||
let l:height = min([len(a:lines), 10])
|
||||
let [l:lines, l:width, l:height] = s:PrepareWindowContent(a:lines)
|
||||
|
||||
call nvim_win_set_width(w:preview['id'], l:width)
|
||||
call nvim_win_set_height(w:preview['id'], l:height)
|
||||
|
||||
call nvim_buf_set_lines(w:preview['buffer'], 0, -1, v:false, a:lines)
|
||||
call nvim_buf_set_lines(w:preview['buffer'], 0, -1, v:false, l:lines)
|
||||
call nvim_buf_set_option(w:preview['buffer'], 'modified', v:false)
|
||||
call nvim_buf_set_option(w:preview['buffer'], 'modifiable', v:false)
|
||||
endfunction
|
||||
|
||||
function! s:PrepareWindowContent(lines) abort
|
||||
let l:max_height = 10
|
||||
|
||||
let l:width = max(map(copy(a:lines), 'strdisplaywidth(v:val)'))
|
||||
let l:height = min([len(a:lines), l:max_height])
|
||||
|
||||
if empty(g:ale_floating_window_border)
|
||||
return [a:lines, l:width, l:height]
|
||||
endif
|
||||
|
||||
" Add the size of borders
|
||||
let l:width += 2
|
||||
let l:height += 2
|
||||
|
||||
let l:hor = g:ale_floating_window_border[0]
|
||||
let l:top = g:ale_floating_window_border[1]
|
||||
let l:top_left = g:ale_floating_window_border[2]
|
||||
let l:top_right = g:ale_floating_window_border[3]
|
||||
let l:bottom_right = g:ale_floating_window_border[4]
|
||||
let l:bottom_left = g:ale_floating_window_border[5]
|
||||
|
||||
let l:lines = [l:top_left . repeat(l:top, l:width - 2) . l:top_right]
|
||||
|
||||
for l:line in a:lines
|
||||
let l:line_width = strchars(l:line)
|
||||
let l:lines = add(l:lines, l:hor . l:line . repeat(' ', l:width - l:line_width - 2). l:hor)
|
||||
endfor
|
||||
|
||||
" Truncate the lines
|
||||
if len(l:lines) > l:max_height + 1
|
||||
let l:lines = l:lines[0:l:max_height]
|
||||
endif
|
||||
|
||||
let l:lines = add(l:lines, l:bottom_left . repeat(l:top, l:width - 2) . l:bottom_right)
|
||||
|
||||
return [l:lines, l:width, l:height]
|
||||
endfunction
|
||||
|
||||
function! s:Create(options) abort
|
||||
let l:buffer = nvim_create_buf(v:false, v:false)
|
||||
let l:winid = nvim_open_win(l:buffer, v:false, {
|
||||
|
@ -88,4 +125,3 @@ function! s:Close() abort
|
|||
|
||||
unlet w:preview
|
||||
endfunction
|
||||
|
||||
|
|
16
doc/ale.txt
16
doc/ale.txt
|
@ -653,7 +653,8 @@ Hover information can be displayed in the preview window instead by setting
|
|||
|g:ale_hover_to_preview| to `1`.
|
||||
|
||||
When using Neovim, if |g:ale_hover_to_floating_preview| or |g:ale_floating_preview|
|
||||
is set to 1, the hover information will show in a floating window.
|
||||
is set to 1, the hover information will show in a floating window. And
|
||||
|g:ale_floating_window_border| for the border setting.
|
||||
|
||||
For Vim 8.1+ terminals, mouse hovering is disabled by default. Enabling
|
||||
|balloonexpr| commands in terminals can cause scrolling issues in terminals,
|
||||
|
@ -1205,6 +1206,19 @@ g:ale_floating_preview *g:ale_floating_preview*
|
|||
|g:ale_detail_to_floating_preview| to `1`.
|
||||
|
||||
|
||||
g:ale_floating_window_border *g:ale_floating_window_border*
|
||||
|
||||
Type: |List|
|
||||
Default: `['|', '-', '+', '+', '+', '+']`
|
||||
|
||||
When set to `[]`, window borders are disabled. The elements in the list
|
||||
set the horizontal, top, top-left, top-right, bottom-right
|
||||
and bottom-left border characters, respectively.
|
||||
|
||||
If the terminal supports Unicode, you might try setting the value to
|
||||
` ['│', '─', '╭', '╮', '╯', '╰']`, to make it look nicer.
|
||||
|
||||
|
||||
g:ale_history_enabled *g:ale_history_enabled*
|
||||
|
||||
Type: |Number|
|
||||
|
|
|
@ -150,6 +150,11 @@ let g:ale_hover_to_floating_preview = get(g:, 'ale_hover_to_floating_preview', 0
|
|||
" Detail uses floating windows in Neovim
|
||||
let g:ale_detail_to_floating_preview = get(g:, 'ale_detail_to_floating_preview', 0)
|
||||
|
||||
" Border setting for floating preview windows in Neovim
|
||||
" The element in the list presents - horizontal, top, top-left, top-right,
|
||||
" bottom-right and bottom-left
|
||||
let g:ale_floating_window_border = get(g:, 'ale_floating_window_border', ['|', '-', '+', '+', '+', '+'])
|
||||
|
||||
" This flag can be set to 0 to disable warnings for trailing whitespace
|
||||
let g:ale_warn_about_trailing_whitespace = get(g:, 'ale_warn_about_trailing_whitespace', 1)
|
||||
" This flag can be set to 0 to disable warnings for trailing blank lines
|
||||
|
|
Reference in a new issue