def _resize_secondary(nvim: Nvim) -> None: tab = cur_tab(nvim) wins = tab_list_wins(nvim, tab=tab) height = nvim.options["previewheight"] for win in wins: is_preview: bool = win_get_option(nvim, win=win, key="previewwindow") buf = win_get_buf(nvim, win=win) ft = buf_filetype(nvim, buf=buf) if is_preview or ft == "qf": nvim.api.win_set_height(win, height)
def _toggle_qf(nvim: Nvim) -> None: tab = cur_tab(nvim) wins = tab_list_wins(nvim, tab=tab) closed = False for win in wins: buf = win_get_buf(nvim, win=win) ft = buf_filetype(nvim, buf=buf) if ft == "qf": win_close(nvim, win=win) closed = True if not closed: nvim.command("copen") win = cur_win(nvim) height = nvim.options["previewheight"] nvim.api.win_set_height(win, height)
def _toggle_preview(nvim: Nvim) -> None: tab = cur_tab(nvim) wins = tab_list_wins(nvim, tab=tab) closed = False for win in wins: is_preview: bool = win_get_option(nvim, win=win, key="previewwindow") if is_preview: win_close(nvim, win=win) closed = True if not closed: nvim.command("new") win = cur_win(nvim) win_set_option(nvim, win=win, key="previewwindow", val=True) height = nvim.options["previewheight"] nvim.api.win_set_height(win, height)
def find_windows_in_tab(nvim: Nvim, no_secondary: bool) -> Iterator[Window]: def key_by(win: Window) -> Tuple[int, int]: """ -> sort by row, then col """ row, col = nvim.funcs.win_screenpos(win.number) return col, row tab = cur_tab(nvim) wins = tab_list_wins(nvim, tab=tab) for win in sorted(wins, key=key_by): is_preview: bool = win_get_option(nvim, win=win, key="previewwindow") buf = win_get_buf(nvim, win) ft = buf_filetype(nvim, buf=buf) is_secondary = is_preview or ft == "qf" if not is_secondary or not no_secondary: yield win
def find_windows_in_tab(nvim: Nvim, last_used: Mapping[int, None], no_secondary: bool) -> Iterator[Window]: ordering = {win_id: idx for idx, win_id in enumerate(reversed(last_used))} def key_by(win: Window) -> Tuple[float, int, int]: """ -> sort by last_used, then row, then col """ pos = ordering.get(win.handle, inf) row, col = nvim.funcs.win_screenpos(win.number) return pos, col, row tab = cur_tab(nvim) wins = tab_list_wins(nvim, tab=tab) ordered = sorted(wins, key=key_by) for win in ordered: is_preview: bool = win_get_option(nvim, win=win, key="previewwindow") buf = win_get_buf(nvim, win) ft = buf_filetype(nvim, buf=buf) is_secondary = is_preview or ft == "qf" if not is_secondary or not no_secondary: yield win