def it() -> Iterator[Tuple[Window, Tuple[int, int]]]: wins = list_wins(nvim) for win in wins: buf = win_get_buf(nvim, win=win) if buf == ctx.buf: row, col = win_get_cursor(nvim, win) yield win, (row, col)
def _open_fm_window(nvim: Nvim, settings: Settings, opts: _Args, width: int) -> None: cwin = cur_win(nvim) win = next(find_fm_windows_in_tab(nvim), None) if win: if opts.toggle: wins = list_wins(nvim) if len(wins) > 1: win_close(nvim, win=win) else: set_cur_win(nvim, win=win) else: buf = next(find_fm_buffers(nvim), None) if buf is None: buf = new_fm_buffer(nvim, settings=settings) win = new_window( nvim, win_local=settings.win_actual_opts, open_left=settings.open_left, width=width, ) for key, val in settings.win_local_opts.items(): win_set_option(nvim, win=win, key=key, val=val) win_set_buf(nvim, win=win, buf=buf) _ensure_side_window(nvim, window=win, settings=settings, width=width) if not opts.focus: set_cur_win(nvim, win=cwin)
def refresh(nvim: Nvim, state: State, settings: Settings) -> Stage: current = find_current_buffer_path(nvim) cwd = state.root.path paths = {cwd} current_ancestors = ancestors(current) if current else set() new_current = current if cwd in current_ancestors else None index = {path for path in state.index if exists(path, follow=True)} | paths selection = {s for s in state.selection if exists(s, follow=False)} parent_paths: AbstractSet[PurePath] = current_ancestors if state.follow else set() new_index = index if new_current else index | parent_paths window_ids = {w.handle for w in list_wins(nvim)} window_order = { win_id: None for win_id in state.window_order if win_id in window_ids } mks = markers(nvim) new_state = forward( state, settings=settings, index=new_index, selection=selection, markers=mks, paths=paths, current=new_current or Void, window_order=window_order, ) return Stage(new_state)
def _quit(nvim: Nvim, state: State, settings: Settings, is_visual: bool) -> None: """ Close sidebar """ wins = list_wins(nvim) if len(wins) <= 1: nvim.api.command("quit") else: for win in find_fm_windows_in_tab(nvim, last_used=state.window_order): win_close(nvim, win=win)
def _toggle_fm_window( nvim: Nvim, state: State, settings: Settings, opts: _Args ) -> None: cwin = cur_win(nvim) win = next(find_fm_windows_in_tab(nvim), None) if win: wins = list_wins(nvim) if len(wins) <= 1: pass else: win_close(nvim, win=win) else: buf = next(find_fm_buffers(nvim), None) if buf is None: buf = new_fm_buffer(nvim, settings=settings) win = new_window(nvim, open_left=settings.open_left, width=state.width) for key, val in settings.win_local_opts.items(): win_set_option(nvim, win=win, key=key, val=val) win_set_buf(nvim, win=win, buf=buf) _ensure_side_window(nvim, window=win, state=state, settings=settings) if not opts.focus: set_cur_win(nvim, win=cwin)
def find_fm_windows(nvim: Nvim) -> Iterator[Tuple[Window, Buffer]]: for win in list_wins(nvim): buf = win_get_buf(nvim, win=win) if is_fm_buffer(nvim, buf=buf): yield win, buf
def _ls(nvim: Nvim) -> Iterator[Window]: for win in list_wins(nvim): if win_get_var(nvim, win=win, key=_FLOAT_WIN_UUID): yield win