Skip to content

Commit

Permalink
Allow customization of all floating window borders (dense-analysis#4215)
Browse files Browse the repository at this point in the history
* Allow customization of all floating window borders

Users may not necessarily want the same border character for top+bottom
or left+right, so allow all eight border characters to be configured in
g:ale_floating_window_border.

For backwards compatibility, the old rules are still applied if only six
elements are given.

* Reorder popup border array for compatibility
  • Loading branch information
djpohly authored and cyyever committed Jul 11, 2022
1 parent 25ea77a commit 15af2b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,14 @@ 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 = ['│', '─', '╭', '╮', '╯', '╰']
let g:ale_floating_window_border = ['│', '─', '╭', '╮', '╯', '╰', '│', '─']
```

Since vim's default uses nice unicode characters when possible, you can trick
ale into using that default with

```vim
let g:ale_floating_window_border = repeat([''], 6)
let g:ale_floating_window_border = repeat([''], 8)
```

<a name="faq-vim-lsp"></a>
Expand Down
34 changes: 18 additions & 16 deletions autoload/ale/floating_preview.vim
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,28 @@ function! s:NvimPrepareWindowContent(lines) abort
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:left = get(g:ale_floating_window_border, 0, '|')
let l:top = get(g:ale_floating_window_border, 1, '-')
let l:top_left = get(g:ale_floating_window_border, 2, '+')
let l:top_right = get(g:ale_floating_window_border, 3, '+')
let l:bottom_right = get(g:ale_floating_window_border, 4, '+')
let l:bottom_left = get(g:ale_floating_window_border, 5, '+')
let l:right = get(g:ale_floating_window_border, 6, l:left)
let l:bottom = get(g:ale_floating_window_border, 7, l:top)

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)
let l:lines = add(l:lines, l:left . l:line . repeat(' ', l:width - l:line_width - 2). l:right)
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)
let l:lines = add(l:lines, l:bottom_left . repeat(l:bottom, l:width - 2) . l:bottom_right)

return [l:lines, l:width, l:height]
endfunction
Expand Down Expand Up @@ -158,14 +160,14 @@ function! s:VimCreate(options) abort
\ 'padding': [0, 1, 0, 1],
\ 'border': [],
\ 'borderchars': empty(g:ale_floating_window_border) ? [' '] : [
\ g:ale_floating_window_border[1],
\ g:ale_floating_window_border[0],
\ g:ale_floating_window_border[1],
\ g:ale_floating_window_border[0],
\ g:ale_floating_window_border[2],
\ g:ale_floating_window_border[3],
\ g:ale_floating_window_border[4],
\ g:ale_floating_window_border[5],
\ get(g:ale_floating_window_border, 1, '-'),
\ get(g:ale_floating_window_border, 6, '|'),
\ get(g:ale_floating_window_border, 7, '-'),
\ get(g:ale_floating_window_border, 0, '|'),
\ get(g:ale_floating_window_border, 2, '+'),
\ get(g:ale_floating_window_border, 3, '+'),
\ get(g:ale_floating_window_border, 4, '+'),
\ get(g:ale_floating_window_border, 5, '+'),
\ ],
\ 'moved': 'any',
\ })
Expand Down
16 changes: 11 additions & 5 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@ Hover information can be displayed in the preview window instead by setting

When using Neovim or Vim with |popupwin|, 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. And |g:ale_floating_window_border| for the border setting.
floating window. The borders of the floating preview window can be customized
by setting |g:ale_floating_window_border|.

For Vim 8.1+ terminals, mouse hovering is disabled by default. Enabling
|balloonexpr| commands in terminals can cause scrolling issues in terminals,
Expand Down Expand Up @@ -1236,14 +1237,19 @@ g:ale_floating_preview *g:ale_floating_preview*
g:ale_floating_window_border *g:ale_floating_window_border*

Type: |List|
Default: `['|', '-', '+', '+', '+', '+']`
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.
the the characters for the left side, top, top-left corner, top-right
corner, bottom-right corner, bottom-left corner, right side, and bottom of
the floating window, respectively.

If the terminal supports Unicode, you might try setting the value to
` ['│', '─', '╭', '╮', '╯', '╰']`, to make it look nicer.
` ['│', '─', '╭', '╮', '╯', '╰', '│', '─']`, to make it look nicer.

NOTE: For compatibility with previous versions, if the list does not have
elements for the right side and bottom, the left side and top will be used
instead.


g:ale_history_enabled *g:ale_history_enabled*
Expand Down
9 changes: 5 additions & 4 deletions plugin/ale.vim
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,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', ['|', '-', '+', '+', '+', '+'])
" Border setting for floating preview windows
" The elements in the list set the characters for the left, top, top-left,
" top-right, bottom-right, bottom-left, right, and bottom of the border
" respectively
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)
Expand Down

0 comments on commit 15af2b7

Please sign in to comment.