def new_window( nvim: Nvim, *, last_used: Mapping[int, None], win_local: Mapping[str, Union[bool, str]], open_left: bool, width: Optional[int], ) -> Window: split_r = nvim.options["splitright"] wins = tuple( find_windows_in_tab(nvim, last_used=last_used, no_secondary=False)) focus_win = wins[0] if open_left else wins[-1] direction = False if open_left else True nvim.options["splitright"] = direction set_cur_win(nvim, win=focus_win) nvim.command(f"{width}vnew" if width else "vnew") nvim.options["splitright"] = split_r win = cur_win(nvim) buf = win_get_buf(nvim, win) for key, val in win_local.items(): win_set_option(nvim, win=win, key=key, val=val) buf_set_option(nvim, buf=buf, key="bufhidden", val="wipe") return win
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 _show_file(nvim: Nvim, *, state: State, settings: Settings, click_type: ClickType) -> None: if click_type is ClickType.tertiary: nvim.api.command("tabnew") win = cur_win(nvim) for key, val in settings.win_actual_opts.items(): win_set_option(nvim, win=win, key=key, val=val) path = state.current if path: hold = click_type is ClickType.secondary mgr = hold_win_pos(nvim) if hold else nullcontext() with mgr: non_fm_windows = tuple( find_non_fm_windows_in_tab(nvim, last_used=state.window_order)) buf = next(find_buffers_with_file(nvim, file=path), None) win = next( chain( find_window_with_file_in_tab( nvim, last_used=state.window_order, file=path), non_fm_windows, ), None, ) or new_window( nvim, last_used=state.window_order, win_local=settings.win_actual_opts, open_left=not settings.open_left, width=None if len(non_fm_windows) else nvim.options["columns"] - state.width - 1, ) set_cur_win(nvim, win=win) non_fm_count = len(non_fm_windows) if click_type is ClickType.v_split and non_fm_count: nvim.api.command("vnew") temp_buf = cur_buf(nvim) buf_set_option(nvim, buf=temp_buf, key="bufhidden", val="wipe") elif click_type is ClickType.h_split and non_fm_count: nvim.api.command("new") temp_buf = cur_buf(nvim) buf_set_option(nvim, buf=temp_buf, key="bufhidden", val="wipe") win = cur_win(nvim) if buf is None: escaped = nvim.funcs.fnameescape(normcase(path)) nvim.command(f"edit! {escaped}") else: win_set_buf(nvim, win=win, buf=buf) resize_fm_windows(nvim, last_used=state.window_order, width=state.width) nvim.api.command("filetype detect")
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 _set_win(nvim: Nvim, display: PreviewDisplay, buf: Buffer, pos: _Pos) -> None: opts = { "relative": "editor", "anchor": "NW", "style": "minimal", "noautocmd": True, "width": pos.width, "height": pos.height, "row": pos.row, "col": pos.col, "border": display.border, } win: Window = nvim.api.open_win(buf, False, opts) win_set_option(nvim, win=win, key="wrap", val=True) win_set_var(nvim, win=win, key=_FLOAT_WIN_UUID, val=True)
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 _norm_cursor(nvim: Nvim) -> None: win = cur_win(nvim) win_set_option(nvim, win=win, key="cursorline", val=True)
def _ins_cursor(nvim: Nvim) -> None: win = cur_win(nvim) win_set_option(nvim, win=win, key="cursorline", val=False)