aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-05-15 08:13:33 +0800
committerGitHub <noreply@github.com>2023-05-15 08:13:33 +0800
commit189e21ae50efe14d8446db11aee6b50f8022d99f (patch)
tree7fa33b913722d280d39f0e0948ad356fe67a8664 /src/nvim/window.c
parent4a0005aee9b51e1b91794623ad06b9a8a2343ba9 (diff)
downloadrneovim-189e21ae50efe14d8446db11aee6b50f8022d99f.tar.gz
rneovim-189e21ae50efe14d8446db11aee6b50f8022d99f.tar.bz2
rneovim-189e21ae50efe14d8446db11aee6b50f8022d99f.zip
vim-patch:9.0.1554: code for handling 'switchbuf' is repeated (#23632)
Problem: Code for handling 'switchbuf' is repeated. Solution: Add a function to handle 'switchbuf'. (Yegappan Lakshmanan, closes vim/vim#12397) https://github.com/vim/vim/commit/e42c27d9e8a18e3786f13f17663914cdd0f63f9e Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 87e936b92f..4f6b5f81a4 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -139,6 +139,32 @@ win_T *prevwin_curwin(void)
return is_in_cmdwin() && prevwin != NULL ? prevwin : curwin;
}
+/// If the 'switchbuf' option contains "useopen" or "usetab", then try to jump
+/// to a window containing "buf".
+/// Returns the pointer to the window that was jumped to or NULL.
+win_T *swbuf_goto_win_with_buf(buf_T *buf)
+{
+ win_T *wp = NULL;
+
+ if (buf == NULL) {
+ return wp;
+ }
+
+ // If 'switchbuf' contains "useopen": jump to first window in the current
+ // tab page containing "buf" if one exists.
+ if (swb_flags & SWB_USEOPEN) {
+ wp = buf_jump_open_win(buf);
+ }
+
+ // If 'switchbuf' contains "usetab": jump to first window in any tab page
+ // containing "buf" if one exists.
+ if (wp == NULL && (swb_flags & SWB_USETAB)) {
+ wp = buf_jump_open_tab(buf);
+ }
+
+ return wp;
+}
+
/// all CTRL-W window commands are handled here, called from normal_cmd().
///
/// @param xchar extra char from ":wincmd gx" or NUL
@@ -520,20 +546,7 @@ wingotofile:
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);
- }
- }
+ wp = swbuf_goto_win_with_buf(buflist_findname_exp(ptr));
}
if (wp == NULL && win_split(0, 0) == OK) {