Skip to content

Commit

Permalink
Add test before remapping plugin's maps
Browse files Browse the repository at this point in the history
The plugin maps the some keys to run the commands of the plugin
automatically by themselves.
Until now, those commands were always mapped, regardless of the state of
the plugin and the mapping themselves.

This caused two problems:
* When the plugin was not enabled the mapping still existed.
* When the mapping was empty, an error massage was generated.

To fix both of those problems, I added two tests before running the
mappings: first, it checks that the plugins is indeed enabled, and then
it checks that the mapping is not empty. Only in case both of those
tests passes, the commands are mapped.
  • Loading branch information
omrisarig13 committed Jul 26, 2019
1 parent e914728 commit 044f327
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plugin/winresizer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,18 @@ let s:codeList = {
\ 'mode' : g:winresizer_keycode_mode,
\}

exe 'nnoremap ' . g:winresizer_start_key .' :WinResizerStartResize<CR>'
if g:winresizer_enable != 0 && !empty(g:winresizer_start_key)
exe 'nnoremap ' . g:winresizer_start_key .' :WinResizerStartResize<CR>'
endif

com! WinResizerStartResize call s:startResize(s:tuiResizeCommands())
com! WinResizerStartMove call s:startResize(s:moveCommands())
com! WinResizerStartFocus call s:startResize(s:focusCommands())

if has("gui_running") && g:winresizer_gui_enable != 0
exe 'nnoremap ' . g:winresizer_gui_start_key .' :WinResizerStartResizeGUI<CR>'
if has("gui_running") && g:winresizer_gui_enable != 0 && g:winresizer_enable != 0
if !empty(g:winresizer_gui_start_key)
exe 'nnoremap ' . g:winresizer_gui_start_key .' :WinResizerStartResizeGUI<CR>'
endif
com! WinResizerStartResizeGUI call s:startResize(s:guiResizeCommands())
endif

Expand Down

0 comments on commit 044f327

Please sign in to comment.