From 214ca3c3e2c27ec1f66d6f2cd338ac5b68097da5 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 29 May 2022 13:14:43 +0800 Subject: [PATCH] feat(font): add `SPC z .` key binding --- autoload/SpaceVim/layers/ui.vim | 45 +++++++++++++++++++++++++++++++++ docs/documentation.md | 14 ++++++++++ 2 files changed, 59 insertions(+) diff --git a/autoload/SpaceVim/layers/ui.vim b/autoload/SpaceVim/layers/ui.vim index ed35fb966..6bc2387bb 100644 --- a/autoload/SpaceVim/layers/ui.vim +++ b/autoload/SpaceVim/layers/ui.vim @@ -283,6 +283,10 @@ function! SpaceVim#layers#ui#config() abort \ 'toggle-highlight-tail-spaces', 1) nnoremap :call toggle_full_screen() + let g:_spacevim_mappings_space.z = get(g:_spacevim_mappings_space, 'z', {'name' : '+Fonts'}) + call SpaceVim#mapping#space#def('nnoremap', ['z', '.'], 'call call(' + \ . string(s:_function('s:fonts_transient_state')) . ', [])', + \ 'font-transient-state', 1) endfunction let s:fullscreen_flag = 0 @@ -637,3 +641,44 @@ function! SpaceVim#layers#ui#get_options() abort \ 'cursorword_exclude_filetypes'] endfunction + +function! s:fonts_transient_state() abort + let state = SpaceVim#api#import('transient_state') + call state.set_title('Fonts Transient State') + call state.defind_keys( + \ { + \ 'layout' : 'vertical split', + \ 'left' : [ + \ { + \ 'key' : '+', + \ 'desc' : 'increase the font', + \ 'func' : '', + \ 'exit' : 0, + \ 'cmd' : 'call call(' . string(s:_function('s:increase_font')) . ', [])', + \ }, + \ ], + \ 'right' : [ + \ { + \ 'key' : '-', + \ 'desc' : 'reduce the font', + \ 'func' : '', + \ 'exit' : 0, + \ 'cmd' : 'call call(' . string(s:_function('s:reduce_font')) . ', [])', + \ }, + \ ], + \ } + \ ) + call state.open() +endfunction + +function! s:increase_font() abort + let font_size = str2nr(matchstr(matchstr(&guifont, ':h\d\+'), '\d\+')) + let font_size += 1 + let &guifont = substitute(&guifont, ':h\d\+', ':h' . font_size, '') +endfunction + +function! s:reduce_font() abort + let font_size = str2nr(matchstr(matchstr(&guifont, ':h\d\+'), '\d\+')) + let font_size -= 1 + let &guifont = substitute(&guifont, ':h\d\+', ':h' . font_size, '') +endfunction diff --git a/docs/documentation.md b/docs/documentation.md index b983a052a..a32747796 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -555,6 +555,20 @@ guifont = "SourceCodePro Nerd Font Mono:h11" If the specified font is not found, the fallback one will be used (depends on your system). Also note that changing this value has no effect if you are running Vim/Neovim in terminal. +**Increase/Decrease fonts** + +| Key Bindings | Descriptions | +| ------------ | ------------------------- | +| `SPC z .` | open font transient state | + +In font transient state: + +| Key Bindings | Descriptions | +| ------------- | ------------------------- | +| `+` | increase the font size | +| `-` | decrease the font size | +| Any other key | leave the transient state | + ### Mouse Mouse support is enabled in Normal mode and Visual mode by default.