aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-05-13 08:40:06 +0800
committerGitHub <noreply@github.com>2023-05-13 08:40:06 +0800
commitf76e1ac92eda9cb364a9de49422b45a035256ca6 (patch)
tree6cc375a9410c04d21392e5877513de831cf2f81f /src
parenta6d63591f1fc61d570b646306d7c259b5ec2cace (diff)
downloadrneovim-f76e1ac92eda9cb364a9de49422b45a035256ca6.tar.gz
rneovim-f76e1ac92eda9cb364a9de49422b45a035256ca6.tar.bz2
rneovim-f76e1ac92eda9cb364a9de49422b45a035256ca6.zip
vim-patch:9.0.1546: some commands for opening a file don't use 'switchbuf' (#23600)
Problem: Some commands for opening a file don't use 'switchbuf'. Solution: Use 'switchbuf' for more commands. (Yegappan Lakshmanan, closes vim/vim#12383, closes vim/vim#12381) https://github.com/vim/vim/commit/54be5fb382d2bf25fd1b17ddab8b21f599019b81 Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/window.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index fd6755a382..45a48f13cc 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -514,18 +514,44 @@ wingotofile:
tabpage_T *oldtab = curtab;
win_T *oldwin = curwin;
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.
+ win_T *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, ECMD_HIDE, NULL) == FAIL) {
// Failed to open the file, close the window opened for it.
win_close(curwin, false, 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);
+ }
xfree(ptr);
}
break;