summaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-05-12 17:49:13 +0100
committerBram Moolenaar <Bram@vim.org>2023-05-12 17:49:13 +0100
commit54be5fb382d2bf25fd1b17ddab8b21f599019b81 (patch)
tree2f8247870b818760f7dac718281ed4067090baf5 /src/window.c
parent8667a5678f983ba899825b810ab849952d49bcb8 (diff)
patch 9.0.1546: some commands for opening a file don't use 'switchbuf'v9.0.1546
Problem: Some commands for opening a file don't use 'switchbuf'. Solution: Use 'switchbuf' for more commands. (Yegappan Lakshmanan, closes #12383, closes #12381)
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/window.c b/src/window.c
index 27b353e17c..b4b23d3584 100644
--- a/src/window.c
+++ b/src/window.c
@@ -580,7 +580,29 @@ wingotofile:
need_mouse_correct = TRUE;
#endif
setpcmark();
- if (win_split(0, 0) == OK)
+
+ // If 'switchbuf' is set to 'useopen' or 'usetab' and the
+ // file is already opened in a window, then jump to it.
+ wp = NULL;
+ if ((swb_flags & (SWB_USEOPEN | SWB_USETAB))
+ && cmdmod.cmod_tab == 0)
+ {
+ buf_T *existing_buf = buflist_findname_exp(ptr);
+
+ if (existing_buf != NULL)
+ {
+ if (swb_flags & SWB_USEOPEN)
+ wp = buf_jump_open_win(existing_buf);
+
+ // If 'switchbuf' contains "usetab": jump to first
+ // window in any tab page containing "existing_buf"
+ // if one exists.
+ if (wp == NULL && (swb_flags & SWB_USETAB))
+ wp = buf_jump_open_tab(existing_buf);
+ }
+ }
+
+ if (wp == NULL && win_split(0, 0) == OK)
{
RESET_BINDING(curwin);
if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL,
@@ -591,12 +613,15 @@ wingotofile:
win_close(curwin, FALSE);
goto_tabpage_win(oldtab, oldwin);
}
- else if (nchar == 'F' && lnum >= 0)
- {
- curwin->w_cursor.lnum = lnum;
- check_cursor_lnum();
- beginline(BL_SOL | BL_FIX);
- }
+ else
+ wp = curwin;
+ }
+
+ if (wp != NULL && nchar == 'F' && lnum >= 0)
+ {
+ curwin->w_cursor.lnum = lnum;
+ check_cursor_lnum();
+ beginline(BL_SOL | BL_FIX);
}
vim_free(ptr);
}