Skip to content

Commit

Permalink
Standardizes glyph padding and makes more options configurable (fixes #…
Browse files Browse the repository at this point in the history
…227, fixes #231, fixes #213
  • Loading branch information
ryanoasis committed Mar 10, 2018
1 parent 8998fe2 commit 40040ba
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 31 deletions.
58 changes: 42 additions & 16 deletions nerdtree_plugin/webdevicons.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ endif
" Temporary (hopefully) fix for glyph issues in gvim (proper fix is with the
" actual font patcher)
if !exists('g:webdevicons_gui_glyph_fix')
let g:webdevicons_gui_glyph_fix = 1
if has('gui_running')
let g:webdevicons_gui_glyph_fix = 1
else
let g:webdevicons_gui_glyph_fix = 0
endif
endif

if !exists('g:DevIconsEnableNERDTreeRedraw')
if has('gui_running')
let g:DevIconsEnableNERDTreeRedraw = 1
else
let g:DevIconsEnableNERDTreeRedraw = 0
endif
endif

if g:webdevicons_enable_nerdtree == 1
Expand Down Expand Up @@ -85,21 +97,25 @@ function! WebDevIconsNERDTreeChangeRootHandler(node)
call b:NERDTree.changeRoot(a:node)
call NERDTreeRender()
call a:node.putCursorHere(0, 0)
redraw!
if g:DevIconsEnableNERDTreeRedraw #== 1
redraw!
endif
endfunction

" NERDTree-u
" scope: global
function! WebDevIconsNERDTreeUpDirCurrentRootClosedHandler()
call nerdtree#ui_glue#upDir(0)
redraw!
if g:DevIconsEnableNERDTreeRedraw #== 1
redraw!
endif
endfunction

function! WebDevIconsNERDTreeDirUpdateFlags(node, glyph)
let path = a:node.path
let isOpen = a:node.isOpen
let padding = g:WebDevIconsNerdTreeAfterGlyphPadding
let prePadding = ''
let postPadding = g:WebDevIconsNerdTreeAfterGlyphPadding
let prePadding = g:WebDevIconsNerdTreeBeforeGlyphPadding
let hasGitFlags = (len(path.flagSet._flagsForScope('git')) > 0)
let hasGitNerdTreePlugin = (exists('g:loaded_nerdtree_git_status') == 1)
let collapsesToSameLine = (exists('g:NERDTreeCascadeSingleChildDir') == 1)
Expand All @@ -117,19 +133,19 @@ function! WebDevIconsNERDTreeDirUpdateFlags(node, glyph)
endif

if g:WebDevIconsUnicodeGlyphDoubleWidth == 0
let padding = ''
let postPadding = ''
endif

if hasGitFlags && g:WebDevIconsUnicodeGlyphDoubleWidth == 1
let prePadding = ' '
let prePadding .= ' '
endif

" align vertically at the same level: non git-flag nodes with git-flag nodes
if g:WebDevIconsNerdTreeGitPluginForceVAlign && !hasGitFlags && hasGitNerdTreePlugin
let prePadding .= ' '
endif

let flag = prePadding . a:glyph . padding
let flag = prePadding . a:glyph . postPadding

call a:node.path.flagSet.clearFlags('webdevicons')

Expand Down Expand Up @@ -194,7 +210,9 @@ function! WebDevIconsNERDTreeMapActivateNode(node)
" continue with normal activate logic
call a:node.activate()
" glyph change possible artifact clean-up
redraw!
if g:DevIconsEnableNERDTreeRedraw #== 1
redraw!
endif
endfunction

function! WebDevIconsNERDTreeMapOpenRecursively(node)
Expand All @@ -205,7 +223,9 @@ function! WebDevIconsNERDTreeMapOpenRecursively(node)
" continue with normal original logic:
call b:NERDTree.render()
" glyph change possible artifact clean-up
redraw!
if g:DevIconsEnableNERDTreeRedraw #== 1
redraw!
endif
call nerdtree#echo("Recursively opening node. Please wait... DONE")
endfunction

Expand All @@ -217,7 +237,9 @@ function! WebDevIconsNERDTreeMapCloseChildren(node)
call b:NERDTree.render()
call a:node.putCursorHere(0, 0)
" glyph change possible artifact clean-up
redraw!
if g:DevIconsEnableNERDTreeRedraw #== 1
redraw!
endif
endfunction

function! WebDevIconsNERDTreeMapCloseDir(node)
Expand All @@ -240,7 +262,9 @@ function! WebDevIconsNERDTreeMapCloseDir(node)
call b:NERDTree.render()
call parent.putCursorHere(0, 0)
" glyph change possible artifact clean-up
redraw!
if g:DevIconsEnableNERDTreeRedraw #== 1
redraw!
endif
endif
endfunction

Expand All @@ -250,7 +274,9 @@ function! WebDevIconsNERDTreeMapUpdirKeepOpen()
call nerdtree#ui_glue#upDir(1)
call s:Refresh()
" glyph change possible artifact clean-up
redraw!
if g:DevIconsEnableNERDTreeRedraw #== 1
redraw!
endif
endfunction

if g:webdevicons_enable == 1 && g:webdevicons_enable_nerdtree == 1
Expand Down Expand Up @@ -313,19 +339,19 @@ if g:webdevicons_enable == 1 && g:webdevicons_enable_nerdtree == 1

" Temporary (hopefully) fix for glyph issues in gvim (proper fix is with the
" actual font patcher)
if g:webdevicons_gui_glyph_fix == 1 && has('gui_running')
if g:webdevicons_gui_glyph_fix #== 1
call NERDTreeAddKeyMap({
\ 'key': g:NERDTreeMapChangeRoot,
\ 'callback': 'WebDevIconsNERDTreeChangeRootHandler',
\ 'override': 1,
\ 'quickhelpText': "change tree root to the\n\" selected dir\n\" plus webdevicons redraw\n\" hack fix",
\ 'quickhelpText': "change tree root to the\n\" selected dir\n\" plus devicons redraw\n\" hack fix",
\ 'scope': 'Node' })

call NERDTreeAddKeyMap({
\ 'key': g:NERDTreeMapUpdir,
\ 'callback': 'WebDevIconsNERDTreeUpDirCurrentRootClosedHandler',
\ 'override': 1,
\ 'quickhelpText': "move tree root up a dir\n\" plus webdevicons redraw\n\" hack fix",
\ 'quickhelpText': "move tree root up a dir\n\" plus devicons redraw\n\" hack fix",
\ 'scope': 'all' })
endif
endif
Expand Down
45 changes: 30 additions & 15 deletions plugin/webdevicons.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ if !exists('g:webdevicons_conceal_nerdtree_brackets')
let g:webdevicons_conceal_nerdtree_brackets = 1
endif

if !exists('g:DevIconsAppendArtifactFix')
if has('gui_running')
let g:DevIconsAppendArtifactFix = 1
else
let g:DevIconsAppendArtifactFix = 0
endif

if !exists('g:DevIconsArtifactFixChar')
let g:DevIconsArtifactFixChar = "\u00A0"
endif

" config options {{{1
"========================================================================

Expand Down Expand Up @@ -109,8 +120,12 @@ if !exists('g:WebDevIconsUnicodeGlyphDoubleWidth')
let g:WebDevIconsUnicodeGlyphDoubleWidth = 1
endif

if !exists('g:WebDevIconsNerdTreeBeforeGlyphPadding')
let g:WebDevIconsNerdTreeBeforeGlyphPadding = ' '
endif

if !exists('g:WebDevIconsNerdTreeAfterGlyphPadding')
let g:WebDevIconsNerdTreeAfterGlyphPadding = ' '
let g:WebDevIconsNerdTreeAfterGlyphPadding = ' '
endif

if !exists('g:WebDevIconsNerdTreeGitPluginForceVAlign')
Expand Down Expand Up @@ -597,7 +612,7 @@ endfunction
" a:1 (bufferName), a:2 (isDirectory), a:3 (appendArtifactFix)
" scope: public
function! WebDevIconsGetFileTypeSymbol(...)
let appendArtifactFix = 1
let appendArtifactFix = g:DevIconsAppendArtifactFix
if a:0 == 0
let fileNodeExtension = expand('%:e')
let fileNode = expand('%:t')
Expand Down Expand Up @@ -646,7 +661,7 @@ function! WebDevIconsGetFileTypeSymbol(...)
" Temporary (hopefully) fix for glyph issues in gvim (proper fix is with the
" actual font patcher)
if appendArtifactFix == 1
let artifactFix = "\u00A0"
let artifactFix = g:DevIconsArtifactFixChar
else
let artifactFix = ""
endif
Expand Down Expand Up @@ -678,7 +693,7 @@ function! WebDevIconsGetFileFormatSymbol(...)

" Temporary (hopefully) fix for glyph issues in gvim (proper fix is with the
" actual font patcher)
let artifactFix = "\u00A0"
let artifactFix = g:DevIconsArtifactFixChar

return bomb . fileformat . artifactFix
endfunction
Expand Down Expand Up @@ -717,17 +732,17 @@ endif
" scope: public
function! NERDTreeWebDevIconsRefreshListener(event)
let path = a:event.subject
let padding = g:WebDevIconsNerdTreeAfterGlyphPadding
let prePadding = ''
let postPadding = g:WebDevIconsNerdTreeAfterGlyphPadding
let prePadding = g:WebDevIconsNerdTreeBeforeGlyphPadding
let hasGitFlags = (len(path.flagSet._flagsForScope('git')) > 0)
let hasGitNerdTreePlugin = (exists('g:loaded_nerdtree_git_status') == 1)

if g:WebDevIconsUnicodeGlyphDoubleWidth == 0
let padding = ''
let postPadding = ''
endif

if hasGitFlags && g:WebDevIconsUnicodeGlyphDoubleWidth == 1
let prePadding = ' '
let prePadding .= ' '
endif

" align vertically at the same level: non git-flag nodes with git-flag nodes
Expand All @@ -737,7 +752,7 @@ function! NERDTreeWebDevIconsRefreshListener(event)

if !path.isDirectory
" Hey we got a regular file, lets get it's proper icon
let flag = prePadding . WebDevIconsGetFileTypeSymbol(path.str()) . padding
let flag = prePadding . WebDevIconsGetFileTypeSymbol(path.str()) . postPadding

elseif path.isDirectory && g:WebDevIconsUnicodeDecorateFolderNodes == 1
" Ok we got a directory, some more tests and checks
Expand All @@ -758,31 +773,31 @@ function! NERDTreeWebDevIconsRefreshListener(event)
" think node_modules
if g:DevIconsEnableFoldersOpenClose && directoryOpened
" the folder is open
let flag = prePadding . g:DevIconsDefaultFolderOpenSymbol . padding
let flag = prePadding . g:DevIconsDefaultFolderOpenSymbol . postPadding
else
" the folder is not open
if path.isSymLink
" We have a symlink
let flag = prePadding . g:WebDevIconsUnicodeDecorateFolderNodesSymlinkSymbol . padding
let flag = prePadding . g:WebDevIconsUnicodeDecorateFolderNodesSymlinkSymbol . postPadding
else
" We have a regular folder
let flag = prePadding . WebDevIconsGetFileTypeSymbol(path.str(), path.isDirectory, 0) . padding
let flag = prePadding . WebDevIconsGetFileTypeSymbol(path.str(), path.isDirectory, 0) . postPadding
endif
endif

else
" the user did not enable exact matching
if g:DevIconsEnableFoldersOpenClose && directoryOpened
" the folder is open
let flag = prePadding . g:DevIconsDefaultFolderOpenSymbol . padding
let flag = prePadding . g:DevIconsDefaultFolderOpenSymbol . postPadding
else
" the folder is not open
if path.isSymLink
" We have a symlink
let flag = prePadding . g:WebDevIconsUnicodeDecorateFolderNodesSymlinkSymbol . padding
let flag = prePadding . g:WebDevIconsUnicodeDecorateFolderNodesSymlinkSymbol . postPadding
else
" We have a regular folder
let flag = prePadding . g:WebDevIconsUnicodeDecorateFolderNodesDefaultSymbol . padding
let flag = prePadding . g:WebDevIconsUnicodeDecorateFolderNodesDefaultSymbol . postPadding
endif
endif

Expand Down

0 comments on commit 40040ba

Please sign in to comment.