From 08794e99fccae04e78fc50d884b3fdd94defa830 Mon Sep 17 00:00:00 2001 From: Yggdroot Date: Tue, 2 Oct 2018 22:32:46 +0800 Subject: [PATCH] fix issue #195, #222: allow for bottom-up ordering of results --- README.md | 7 +- autoload/leaderf/Any.vim | 1 + autoload/leaderf/python/leaderf/bufTagExpl.py | 29 ++- autoload/leaderf/python/leaderf/instance.py | 92 +++++++-- autoload/leaderf/python/leaderf/manager.py | 184 ++++++++++++++---- doc/leaderf.txt | 4 + 6 files changed, 261 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index da7f5a8a..b048dac0 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Usage ----- ``` -usage: Leaderf[!] [-h] [--stayOpen] [--input INPUT | --cword] +usage: Leaderf[!] [-h] [--reverse] [--stayOpen] [--input INPUT | --cword] [--top | --bottom | --left | --right | --belowright | --aboveleft | --fullScreen] [--nameOnly | --fullPath | --fuzzy | --regex] {file,tag,function,mru,searchHistory,cmdHistory,help,line,colorscheme,self,bufTag,buffer} @@ -85,6 +85,7 @@ usage: Leaderf[!] [-h] [--stayOpen] [--input INPUT | --cword] optional arguments: -h, --help show this help message and exit + --reverse show results in bottom-up order --stayOpen don't quit LeaderF after accepting an entry --input INPUT specifies INPUT as the pattern inputted in advance --cword current word under cursor is inputted in advance @@ -122,7 +123,8 @@ If [!] is given, enter normal mode directly. use `:Leaderf -h` to get specific help of subcommand, e.g., `:Leaderf mru -h` ``` -usage: Leaderf[!] mru [-h] [--cwd] [--stayOpen] [--input INPUT | --cword] +usage: Leaderf[!] mru [-h] [--cwd] [--reverse] [--stayOpen] + [--input INPUT | --cword] [--top | --bottom | --left | --right | --belowright | --aboveleft | --fullScreen] [--nameOnly | --fullPath | --fuzzy | --regex] @@ -133,6 +135,7 @@ specific arguments: --cwd search MRU in current working directory common arguments: + --reverse show results in bottom-up order --stayOpen don't quit LeaderF after accepting an entry --input INPUT specifies INPUT as the pattern inputted in advance --cword current word under cursor is inputted in advance diff --git a/autoload/leaderf/Any.vim b/autoload/leaderf/Any.vim index 4acb3d4f..23091c43 100644 --- a/autoload/leaderf/Any.vim +++ b/autoload/leaderf/Any.vim @@ -79,6 +79,7 @@ let g:Lf_Arguments = { \} let g:Lf_CommonArguments = [ + \ {"name": ["--reverse"], "nargs": 0, "help": "show results in bottom-up order"}, \ {"name": ["--stayOpen"], "nargs": 0, "help": "don't quit LeaderF after accepting an entry"}, \ [ \ {"name": ["--input"], "nargs": 1, "help": "specifies INPUT as the pattern inputted in advance"}, diff --git a/autoload/leaderf/python/leaderf/bufTagExpl.py b/autoload/leaderf/python/leaderf/bufTagExpl.py index 20749f31..f169bbcc 100644 --- a/autoload/leaderf/python/leaderf/bufTagExpl.py +++ b/autoload/leaderf/python/leaderf/bufTagExpl.py @@ -232,7 +232,10 @@ def _acceptSelection(self, *args, **kwargs): if line[0].isspace(): # if g:Lf_PreviewCode == 1 buffer = args[1] line_nr = args[2] - line = buffer[line_nr - 2] + if self._getInstance().isReverseOrder(): + line = buffer[line_nr] + else: + line = buffer[line_nr - 2] # {tag} {kind} {scope} {file}:{line} {buf_number} items = re.split(" *\t *", line) tagname = items[0] @@ -388,16 +391,36 @@ def _getList(self, pairs): def _toUp(self): if self._supports_preview: - lfCmd("norm! 2k") + if self._getInstance().isReverseOrder() and self._getInstance().getCurrentPos()[0] <= 3: + self._setResultContent() + if self._cli.pattern and len(self._highlight_pos) < len(self._getInstance().buffer) // 2 \ + and len(self._highlight_pos) < int(lfEval("g:Lf_NumberOfHighlight")): + self._highlight_method() + + if self._getInstance().isReverseOrder(): + lfCmd("norm! 3kj") + self._getInstance().setLineNumber() + else: + lfCmd("norm! 2k") else: super(BufTagExplManager, self)._toUp() + lfCmd("setlocal cursorline!") # these two help to redraw the statusline, + lfCmd("setlocal cursorline!") # also fix a weird bug of vim + def _toDown(self): if self._supports_preview: - lfCmd("norm! 3jk") + if self._getInstance().isReverseOrder(): + lfCmd("norm! 2j") + self._getInstance().setLineNumber() + else: + lfCmd("norm! 3jk") else: super(BufTagExplManager, self)._toDown() + lfCmd("setlocal cursorline!") # these two help to redraw the statusline, + lfCmd("setlocal cursorline!") # also fix a weird bug of vim + def removeCache(self, buf_number): self._getExplorer().removeCache(buf_number) diff --git a/autoload/leaderf/python/leaderf/instance.py b/autoload/leaderf/python/leaderf/instance.py index a900b777..c10bfe60 100644 --- a/autoload/leaderf/python/leaderf/instance.py +++ b/autoload/leaderf/python/leaderf/instance.py @@ -35,8 +35,8 @@ def __init__(self, category, self._win_height = float(lfEval("g:Lf_WindowHeight")) self._show_tabline = int(lfEval("&showtabline")) self._is_autocmd_set = False + self._reverse_order = lfEval("get(g:, 'Lf_ReverseOrder', 0)") == '1' self._orig_pos = () # (tabpage, window, buffer) - self._initStlVar() self._highlightStl() def _initStlVar(self): @@ -44,6 +44,7 @@ def _initStlVar(self): lfCmd("let g:Lf_{}_StlMode = '-'".format(self._category)) lfCmd("let g:Lf_{}_StlCwd= '-'".format(self._category)) lfCmd("let g:Lf_{}_StlTotal = '0'".format(self._category)) + lfCmd("let g:Lf_{}_StlLineNumber = '1'".format(self._category)) lfCmd("let g:Lf_{}_StlResultsCount = '0'".format(self._category)) stl = "%#Lf_hl_{0}_stlName# LeaderF " @@ -56,7 +57,10 @@ def _initStlVar(self): stl += "%#Lf_hl_{0}_stlSeparator3#%{{g:Lf_StlSeparator.left}}" stl += "%=%#Lf_hl_{0}_stlBlank#" stl += "%#Lf_hl_{0}_stlSeparator4#%{{g:Lf_StlSeparator.right}}" - stl += "%#Lf_hl_{0}_stlLineInfo# %l/%{{g:Lf_{0}_StlResultsCount}} " + if self._reverse_order: + stl += "%#Lf_hl_{0}_stlLineInfo# %{{g:Lf_{0}_StlLineNumber}}/%{{g:Lf_{0}_StlResultsCount}} " + else: + stl += "%#Lf_hl_{0}_stlLineInfo# %l/%{{g:Lf_{0}_StlResultsCount}} " stl += "%#Lf_hl_{0}_stlSeparator5#%{{g:Lf_StlSeparator.right}}" stl += "%#Lf_hl_{0}_stlTotal# Total: %{{g:Lf_{0}_StlTotal}} " self._stl = stl.format(self._category) @@ -71,18 +75,25 @@ def _setAttributes(self): lfCmd("setlocal undolevels=-1") lfCmd("setlocal noswapfile") lfCmd("setlocal nolist") - lfCmd("setlocal number") lfCmd("setlocal norelativenumber") lfCmd("setlocal nospell") lfCmd("setlocal wrap") lfCmd("setlocal nofoldenable") - lfCmd("setlocal foldcolumn=0") lfCmd("setlocal foldmethod=manual") lfCmd("setlocal shiftwidth=4") lfCmd("setlocal cursorline") lfCmd("setlocal filetype=leaderf") + if self._reverse_order: + lfCmd("setlocal nonumber") + lfCmd("setlocal foldcolumn=1") + lfCmd("setlocal winfixheight") + else: + lfCmd("setlocal number") + lfCmd("setlocal foldcolumn=0") + lfCmd("setlocal nowinfixheight") def _setStatusline(self): + self._initStlVar() self.window.options["statusline"] = self._stl lfCmd("redrawstatus") if not self._is_autocmd_set: @@ -145,6 +156,10 @@ def _createBufWindow(self, win_pos): self._tabpage_object = vim.current.tabpage self._window_object = vim.current.window + self._initial_win_height = self._window_object.height + if self._reverse_order: + self._window_object.height = 1 + if self._buffer_object is None or not self._buffer_object.valid: self._buffer_object = vim.current.buffer lfCmd("augroup Lf_{}_Colorscheme".format(self._category)) @@ -154,6 +169,8 @@ def _createBufWindow(self, win_pos): lfCmd("autocmd ColorScheme * call leaderf#colorscheme#highlightMode('{0}', g:Lf_{0}_StlMode)" .format(self._category)) lfCmd("autocmd ColorScheme doautocmd syntax") + lfCmd("autocmd CursorMoved let g:Lf_{}_StlLineNumber = 1 + line('$') - line('.')" + .format(self._category)) lfCmd("autocmd VimResized * let g:Lf_VimResized = 1") lfCmd("augroup END") @@ -167,6 +184,13 @@ def _enterOpeningBuffer(self): return True return False + def setArguments(self, arguments): + self._arguments = arguments + if "--reverse" in self._arguments or lfEval("get(g:, 'Lf_ReverseOrder', 0)") == '1': + self._reverse_order = True + else: + self._reverse_order = False + def setStlCategory(self, category): lfCmd("let g:Lf_{}_StlCategory = '{}'".format(self._category, category) ) @@ -188,6 +212,7 @@ def enterBuffer(self, win_pos): if self._enterOpeningBuffer(): return + lfCmd("let g:Lf_{}_StlLineNumber = '1'".format(self._category)) self._orig_pos = (vim.current.tabpage, vim.current.window, vim.current.buffer) self._orig_cursor = vim.current.window.cursor @@ -241,7 +266,25 @@ def setBuffer(self, content): # if lfEval("has('nvim')") == '1': # # NvimError: string cannot contain newlines # content = [ line.rstrip("\r\n") for line in content ] - self._buffer_object[:] = content + if self._reverse_order: + orig_row = self._window_object.cursor[0] + orig_buf_len = len(self._buffer_object) + + self._buffer_object[:] = content[::-1] + buffer_len = len(self._buffer_object) + if buffer_len < self._initial_win_height: + self._window_object.height = buffer_len + elif self._window_object.height < self._initial_win_height: + self._window_object.height = self._initial_win_height + + try: + self._window_object.cursor = (orig_row + buffer_len - orig_buf_len, 0) + except vim.error: + self._window_object.cursor = (buffer_len, 0) + + self.setLineNumber() + else: + self._buffer_object[:] = content def appendLine(self, line): self._buffer_object.append(line) @@ -250,35 +293,37 @@ def initBuffer(self, content, unit, set_content): if isinstance(content, list): self.setBuffer(content) self.setStlTotal(len(content)//unit) - self.setStlResultsCount(len(content)) - return + self.setStlResultsCount(len(content)//unit) + return content self.buffer.options['modifiable'] = True self._buffer_object[:] = [] try: start = time.time() + cur_content = [] for line in content: - if line is None: - continue - if self.empty(): - self._buffer_object[0] = line - else: - self._buffer_object.append(line) + cur_content.append(line) if time.time() - start > 0.1: start = time.time() + self.setBuffer(cur_content) + if self._reverse_order: + lfCmd("normal! G") self.setStlTotal(len(self._buffer_object)//unit) - self.setStlResultsCount(len(self._buffer_object)) + self.setStlResultsCount(len(self._buffer_object)//unit) lfCmd("redrawstatus") + self.setBuffer(cur_content) self.setStlTotal(len(self._buffer_object)//unit) - self.setStlResultsCount(len(self._buffer_object)) + self.setStlResultsCount(len(self._buffer_object)//unit) lfCmd("redrawstatus") - set_content(self.buffer[:]) + set_content(cur_content) except vim.error: # neovim pass except KeyboardInterrupt: # pass + return cur_content + @property def tabpage(self): return self._tabpage_object @@ -307,4 +352,19 @@ def getOriginalPos(self): def getOriginalCursor(self): return self._orig_cursor + def getInitialWinHeight(self): + if self._reverse_order: + return self._initial_win_height + else: + return 200 + + def isReverseOrder(self): + return self._reverse_order + + def setLineNumber(self): + if self._reverse_order: + line_nr = 1 + len(self._buffer_object) - self._window_object.cursor[0] + lfCmd("let g:Lf_{}_StlLineNumber = '{}'".format(self._category, line_nr)) + + # vim: set ts=4 sw=4 tw=0 et : diff --git a/autoload/leaderf/python/leaderf/manager.py b/autoload/leaderf/python/leaderf/manager.py index 2656aa25..25b2807e 100644 --- a/autoload/leaderf/python/leaderf/manager.py +++ b/autoload/leaderf/python/leaderf/manager.py @@ -82,7 +82,7 @@ def __init__(self): self._fuzzy_engine = None self._result_content = [] self._reader_thread = None - self._initial_count = 200 + self._highlight_method = lambda : None self._getExplClass() #************************************************************** @@ -294,12 +294,33 @@ def _createHelpHint(self): else: help += self._createHelp() self._help_length = len(help) - cursor_line = self._getInstance().window.cursor[0] - self._getInstance().buffer.append(help, 0) - self._getInstance().window.cursor = (cursor_line + self._help_length, 0) + orig_row = self._getInstance().window.cursor[0] + if self._getInstance().isReverseOrder(): + self._getInstance().buffer.append(help[::-1]) + lfCmd("normal! Gzb") + self._getInstance().window.cursor = (orig_row, 0) + else: + self._getInstance().buffer.append(help, 0) + self._getInstance().window.cursor = (orig_row + self._help_length, 0) def _hideHelp(self): - del self._getInstance().buffer[:self._help_length] + if self._getInstance().isReverseOrder(): + orig_row = self._getInstance().window.cursor[0] + countdown = len(self._getInstance().buffer) - orig_row - self._help_length + if self._help_length > 0: + del self._getInstance().buffer[-self._help_length:] + + self._getInstance().buffer[:] = self._getInstance().buffer[-self._initial_count:] + lfCmd("normal! Gzb") + + if 0 < countdown < self._initial_count: + self._getInstance().window.cursor = (len(self._getInstance().buffer) - countdown, 0) + else: + self._getInstance().window.cursor = (len(self._getInstance().buffer), 0) + + self._getInstance().setLineNumber() + else: + del self._getInstance().buffer[:self._help_length] self._help_length = 0 def _getExplorer(self): @@ -321,26 +342,59 @@ def _setAutochdir(self): lfCmd("set autochdir") def _toUp(self): + adjust = False + if self._getInstance().isReverseOrder() and self._getInstance().getCurrentPos()[0] == 1: + adjust = True + self._setResultContent() + if self._cli.pattern \ + and len(self._highlight_pos) < (len(self._getInstance().buffer) - self._help_length) // self._getUnit() \ + and len(self._highlight_pos) < int(lfEval("g:Lf_NumberOfHighlight")): + self._highlight_method() + lfCmd("norm! k") + if adjust: + lfCmd("norm! zt") + + self._getInstance().setLineNumber() + lfCmd("setlocal cursorline!") # these two help to redraw the statusline, + lfCmd("setlocal cursorline!") # also fix a weird bug of vim + def _toDown(self): - if self._getInstance().getCurrentPos()[0] == self._getInstance().window.height: + if not self._getInstance().isReverseOrder() \ + and self._getInstance().getCurrentPos()[0] == self._getInstance().window.height: self._setResultContent() lfCmd("norm! j") + self._getInstance().setLineNumber() + lfCmd("setlocal cursorline!") # these two help to redraw the statusline, + lfCmd("setlocal cursorline!") # also fix a weird bug of vim def _pageUp(self): + if self._getInstance().isReverseOrder(): + self._setResultContent() + if self._cli.pattern \ + and len(self._highlight_pos) < (len(self._getInstance().buffer) - self._help_length) // self._getUnit() \ + and len(self._highlight_pos) < int(lfEval("g:Lf_NumberOfHighlight")): + self._highlight_method() + lfCmd('exec "norm! \"') + self._getInstance().setLineNumber() + def _pageDown(self): - self._setResultContent() + if not self._getInstance().isReverseOrder(): + self._setResultContent() lfCmd('exec "norm! \"') + self._getInstance().setLineNumber() + def _leftClick(self): if self._getInstance().window.number == int(lfEval("v:mouse_win")): lfCmd("exec v:mouse_lnum") lfCmd("exec 'norm!'.v:mouse_col.'|'") + self._getInstance().setLineNumber() self.clearSelections() exit_loop = False else: @@ -354,8 +408,9 @@ def _search(self, content, is_continue=False, step=0): self._clearHighlightsPos() self._cli.highlightMatches() if not self._cli.pattern: # e.g., when or is typed - self._getInstance().setBuffer(content) + self._getInstance().setBuffer(content[:self._initial_count]) self._getInstance().setStlResultsCount(len(content)) + self._result_content = [] return if self._cli.isFuzzy: @@ -603,6 +658,7 @@ def _fuzzySearch(self, content, is_continue, step): self._getInstance().setStlResultsCount(len(self._result_content)) highlight_method() + self._highlight_method = highlight_method def _clearHighlights(self): for i in self._highlight_ids: @@ -615,15 +671,24 @@ def _clearHighlightsPos(self): def _resetHighlights(self): self._clearHighlights() - for i, pos in enumerate(self._highlight_pos, self._help_length + 1): - pos = [[i] + p for p in pos] + + unit = self._getUnit() + bottom = len(self._getInstance().buffer) - self._help_length + for i, pos in enumerate(self._highlight_pos): + if self._getInstance().isReverseOrder(): + pos = [[bottom - unit*i] + p for p in pos] + else: + pos = [[unit*i + 1 + self._help_length] + p for p in pos] # The maximum number of positions is 8 in matchaddpos(). for j in range(0, len(pos), 8): id = int(lfEval("matchaddpos('Lf_hl_match', %s)" % str(pos[j:j+8]))) self._highlight_ids.append(id) - for i, pos in enumerate(self._highlight_refine_pos, self._help_length + 1): - pos = [[i] + p for p in pos] + for i, pos in enumerate(self._highlight_refine_pos): + if self._getInstance().isReverseOrder(): + pos = [[bottom - unit*i] + p for p in pos] + else: + pos = [[unit*i + 1 + self._help_length] + p for p in pos] # The maximum number of positions is 8 in matchaddpos(). for j in range(0, len(pos), 8): id = int(lfEval("matchaddpos('Lf_hl_matchRefine', %s)" % str(pos[j:j+8]))) @@ -644,21 +709,34 @@ def _highlight(self, is_full_path, get_highlights, use_fuzzy_engine=False): getDigest = partial(self._getDigest, mode=0 if is_full_path else 1) unit = self._getUnit() + if self._getInstance().isReverseOrder(): + if self._help_length > 0: + content = cb[:-self._help_length][::-1] + else: + content = cb[:][::-1] + else: + content = cb[self._help_length:] + if use_fuzzy_engine: self._highlight_pos = get_highlights(source=[getDigest(line) - for line in cb[:][:highlight_number:unit]]) + for line in content[:highlight_number:unit]]) else: # e.g., self._highlight_pos = [ [ [2,3], [6,2] ], [ [1,4], [7,6], ... ], ... ] # where [2, 3] indicates the highlight starts at the 2nd column with the # length of 3 in bytes self._highlight_pos = [get_highlights(getDigest(line)) - for line in cb[:][:highlight_number:unit]] + for line in content[:highlight_number:unit]] + + bottom = len(content) for i, pos in enumerate(self._highlight_pos): - start_pos = self._getDigestStartPos(cb[unit*i], 0 if is_full_path else 1) + start_pos = self._getDigestStartPos(content[unit*i], 0 if is_full_path else 1) if start_pos > 0: for j in range(len(pos)): pos[j][0] += start_pos - pos = [[unit*i+1] + p for p in pos] + if self._getInstance().isReverseOrder(): + pos = [[bottom - unit*i] + p for p in pos] + else: + pos = [[unit*i + 1 + self._help_length] + p for p in pos] # The maximum number of positions is 8 in matchaddpos(). for j in range(0, len(pos), 8): id = int(lfEval("matchaddpos('Lf_hl_match', %s)" % str(pos[j:j+8]))) @@ -678,27 +756,44 @@ def _highlightRefine(self, first_get_highlights, get_highlights): getDigest = self._getDigest unit = self._getUnit() + + if self._getInstance().isReverseOrder(): + if self._help_length > 0: + content = cb[:-self._help_length][::-1] + else: + content = cb[:][::-1] + else: + content = cb[self._help_length:] + + bottom = len(content) + self._highlight_pos = [first_get_highlights(getDigest(line, 1)) - for line in cb[:][:highlight_number:unit]] + for line in content[:highlight_number:unit]] for i, pos in enumerate(self._highlight_pos): - start_pos = self._getDigestStartPos(cb[unit*i], 1) + start_pos = self._getDigestStartPos(content[unit*i], 1) if start_pos > 0: for j in range(len(pos)): pos[j][0] += start_pos - pos = [[unit*i+1] + p for p in pos] + if self._getInstance().isReverseOrder(): + pos = [[bottom - unit*i] + p for p in pos] + else: + pos = [[unit*i + 1 + self._help_length] + p for p in pos] # The maximum number of positions is 8 in matchaddpos(). for j in range(0, len(pos), 8): id = int(lfEval("matchaddpos('Lf_hl_match', %s)" % str(pos[j:j+8]))) self._highlight_ids.append(id) self._highlight_refine_pos = [get_highlights(getDigest(line, 2)) - for line in cb[:][:highlight_number:unit]] + for line in content[:highlight_number:unit]] for i, pos in enumerate(self._highlight_refine_pos): - start_pos = self._getDigestStartPos(cb[unit*i], 2) + start_pos = self._getDigestStartPos(content[unit*i], 2) if start_pos > 0: for j in range(len(pos)): pos[j][0] += start_pos - pos = [[unit*i+1] + p for p in pos] + if self._getInstance().isReverseOrder(): + pos = [[bottom - unit*i] + p for p in pos] + else: + pos = [[unit*i + 1 + self._help_length] + p for p in pos] # The maximum number of positions is 8 in matchaddpos(). for j in range(0, len(pos), 8): id = int(lfEval("matchaddpos('Lf_hl_matchRefine', %s)" % str(pos[j:j+8]))) @@ -738,7 +833,11 @@ def _cleanup(self): @modifiableController def toggleHelp(self): self._show_help = not self._show_help - del self._getInstance().buffer[:self._help_length] + if self._getInstance().isReverseOrder(): + if self._help_length > 0: + del self._getInstance().buffer[-self._help_length:] + else: + del self._getInstance().buffer[:self._help_length] self._createHelpHint() self.clearSelections() self._resetHighlights() @@ -763,9 +862,14 @@ def _accept(self, file, mode, *args, **kwargs): self._acceptSelection(file, *args, **kwargs) def accept(self, mode=''): - if self._getInstance().window.cursor[0] <= self._help_length: - lfCmd("norm! j") - return + if self._getInstance().isReverseOrder(): + if self._getInstance().window.cursor[0] > len(self._getInstance().buffer) - self._help_length: + lfCmd("norm! k") + return + else: + if self._getInstance().window.cursor[0] <= self._help_length: + lfCmd("norm! j") + return if len(self._selections) > 0: files = [] for i in sorted(self._selections.keys()): @@ -826,8 +930,7 @@ def refresh(self, normal_mode=True): self._clearHighlightsPos() self.clearSelections() - self._getInstance().initBuffer(content, self._getUnit(), self._getExplorer().setContent) - self._content = self._getInstance().buffer[:] + self._content = self._getInstance().initBuffer(content, self._getUnit(), self._getExplorer().setContent) self._iteration_end = True if self._cli.pattern: @@ -894,7 +997,10 @@ def startExplorer(self, win_pos, *args, **kwargs): if not content: lfCmd("echohl Error | redraw | echo ' No content!' | echohl NONE") return + + self._getInstance().setArguments(self._arguments) self._getInstance().enterBuffer(win_pos) + self._initial_count = self._getInstance().getInitialWinHeight() self._getInstance().setStlCategory(self._getExplorer().getStlCategory()) self._setStlMode(**kwargs) @@ -937,8 +1043,7 @@ def startExplorer(self, win_pos, *args, **kwargs): self._result_content = [] self._callback = self._workInIdle if lfEval("g:Lf_CursorBlink") == '0': - self._getInstance().initBuffer(content, self._getUnit(), self._getExplorer().setContent) - self._content = self._getInstance().buffer[:] + self._content = self._getInstance().initBuffer(content, self._getUnit(), self._getExplorer().setContent) self.input() else: self._content = [] @@ -955,8 +1060,7 @@ def startExplorer(self, win_pos, *args, **kwargs): self._result_content = [] self._callback = partial(self._workInIdle, content) if lfEval("g:Lf_CursorBlink") == '0': - self._getInstance().initBuffer(content, self._getUnit(), self._getExplorer().setContent) - self._content = self._getInstance().buffer[:] + self._content = self._getInstance().initBuffer(content, self._getUnit(), self._getExplorer().setContent) self.input() else: self._content = [] @@ -1043,7 +1147,7 @@ def _workInIdle(self, content=None): step = 2000 self._search(self._content[:cur_len], True, step) else: - if len(self._getInstance().buffer) < self._initial_count: + if len(self._getInstance().buffer) < min(cur_len, self._initial_count): self._getInstance().setBuffer(self._content[:self._initial_count]) @modifiableController @@ -1060,12 +1164,18 @@ def input(self): if equal(cmd, ''): self._search(cur_content) elif equal(cmd, ''): - lfCmd("normal! gg") + if self._getInstance().isReverseOrder(): + lfCmd("normal! G") + else: + lfCmd("normal! gg") self._index = 0 # search from beginning self._search(cur_content) elif equal(cmd, ''): self._setStlMode() - lfCmd("normal! gg") + if self._getInstance().isReverseOrder(): + lfCmd("normal! G") + else: + lfCmd("normal! gg") self._index = 0 # search from beginning if self._cli.pattern: self._search(cur_content) @@ -1104,6 +1214,10 @@ def input(self): self._cli.hideCursor() self._createHelpHint() self._resetHighlights() + if self._getInstance().isReverseOrder() and self._cli.pattern \ + and len(self._highlight_pos) < (len(self._getInstance().buffer) - self._help_length) // self._getUnit() \ + and len(self._highlight_pos) < int(lfEval("g:Lf_NumberOfHighlight")): + self._highlight_method() break elif equal(cmd, ''): self.refresh(False) diff --git a/doc/leaderf.txt b/doc/leaderf.txt index 816b12dd..e55bc1a7 100644 --- a/doc/leaderf.txt +++ b/doc/leaderf.txt @@ -515,6 +515,10 @@ g:Lf_RecurseSubmodules *g:Lf_RecurseSubmodules* 2.11+ and there will be an error if git version is lower than 2.11, this option is off with value 0 by default. +g:Lf_ReverseOrder *g:Lf_ReverseOrder* + Show results in bottom-up order. + Default value is 0(top-down order). + ============================================================================== USAGE *leaderf-usage*