diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a6e454..55806cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR) --> #### 6.9 +- **.8**: Refactor sort comparison functions, removing redundancy (PhilRunninger) [#1166](https://github.com/preservim/nerdtree/pull/1166) - **.7**: Fix argument of `exists()` function calls checking for autocommands. (PhilRunninger) [#1165](https://github.com/preservim/nerdtree/pull/1165) - **.6**: Don't use silent when raising User events (PhilRunninger) [#1164](https://github.com/preservim/nerdtree/pull/1164) - **.5**: Fix highlight for file node. (pirey) [#1157](https://github.com/preservim/nerdtree/pull/1157) diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index c935827..983bb62 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -110,15 +110,15 @@ function! nerdtree#completeBookmarks(A,L,P) abort return filter(g:NERDTreeBookmark.BookmarkNames(), 'v:val =~# "^' . a:A . '"') endfunction -"FUNCTION: nerdtree#compareNodes(dir) {{{2 +"FUNCTION: nerdtree#compareNodes(n1, n2) {{{2 function! nerdtree#compareNodes(n1, n2) abort - return a:n1.path.compareTo(a:n2.path) + return nerdtree#compareNodePaths(a:n1.path, a:n2.path) endfunction -"FUNCTION: nerdtree#compareNodesBySortKey(n1, n2) {{{2 -function! nerdtree#compareNodesBySortKey(n1, n2) abort - let sortKey1 = a:n1.path.getSortKey() - let sortKey2 = a:n2.path.getSortKey() +"FUNCTION: nerdtree#compareNodePaths(p1, p2) {{{2 +function! nerdtree#compareNodePaths(p1, p2) abort + let sortKey1 = a:p1.getSortKey() + let sortKey2 = a:p2.getSortKey() let i = 0 while i < min([len(sortKey1), len(sortKey2)]) " Compare chunks upto common length. diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index 21e357b..786ccd9 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -99,50 +99,6 @@ function! s:Path.changeToDir() endtry endfunction -" FUNCTION: Path.compareTo() {{{1 -" -" Compares this Path to the given path and returns 0 if they are equal, -1 if -" this Path is 'less than' the given path, or 1 if it is 'greater'. -" -" Args: -" path: the path object to compare this to -" -" Return: -" 1, -1 or 0 -function! s:Path.compareTo(path) - let thisPath = self.getLastPathComponent(1) - let thatPath = a:path.getLastPathComponent(1) - - "if the paths are the same then clearly we return 0 - if thisPath ==# thatPath - return 0 - endif - - let thisSS = self.getSortOrderIndex() - let thatSS = a:path.getSortOrderIndex() - - "compare the sort sequences, if they are different then the return - "value is easy - if thisSS < thatSS - return -1 - elseif thisSS > thatSS - return 1 - else - if !g:NERDTreeSortHiddenFirst - let thisPath = substitute(thisPath, '^[._]', '', '') - let thatPath = substitute(thatPath, '^[._]', '', '') - endif - "if the sort sequences are the same then compare the paths - "alphabetically - let pathCompare = g:NERDTreeCaseSensitiveSort ? thisPath <# thatPath : thisPath