aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
authorJurica Bradaric <jbradaric@gmail.com>2016-01-27 22:49:48 +0100
committerJurica Bradaric <jbradaric@gmail.com>2016-01-28 18:25:25 +0100
commita31f9161b09f3500385e99b076b3d8328de47dd7 (patch)
tree970e5c2d0b383f23e2b31d63a6f7645e90b86461 /src/nvim/window.c
parent50393ef17831a24a57e68812f9cadf186c650ab9 (diff)
downloadrneovim-a31f9161b09f3500385e99b076b3d8328de47dd7.tar.gz
rneovim-a31f9161b09f3500385e99b076b3d8328de47dd7.tar.bz2
rneovim-a31f9161b09f3500385e99b076b3d8328de47dd7.zip
vim-patch:7.4.709
Problem: ":tabmove" does not work as documented. Solution: Make it work consistently. Update documentation and add tests. (Hirohito Higashi) https://github.com/vim/vim/commit/40ce3a4e1f50badb75ca812e26557a9bc5fde8c6
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 853f8755c3..64034863ed 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -3274,17 +3274,27 @@ void goto_tabpage_win(tabpage_T *tp, win_T *wp)
}
}
-/*
- * Move the current tab page to before tab page "nr".
- */
+// Move the current tab page to after tab page "nr".
void tabpage_move(int nr)
{
- int n = nr;
- tabpage_T *tp;
+ int n = 1;
+ tabpage_T *tp;
+ tabpage_T *tp_dst;
if (first_tabpage->tp_next == NULL)
return;
+ for (tp = first_tabpage; tp->tp_next != NULL && n < nr; tp = tp->tp_next) {
+ ++n;
+ }
+
+ if (tp == curtab || (nr > 0 && tp->tp_next != NULL
+ && tp->tp_next == curtab)) {
+ return;
+ }
+
+ tp_dst = tp;
+
/* Remove the current tab page from the list of tab pages. */
if (curtab == first_tabpage)
first_tabpage = curtab->tp_next;
@@ -3297,15 +3307,13 @@ void tabpage_move(int nr)
tp->tp_next = curtab->tp_next;
}
- /* Re-insert it at the specified position. */
- if (n <= 0) {
+ // Re-insert it at the specified position.
+ if (nr <= 0) {
curtab->tp_next = first_tabpage;
first_tabpage = curtab;
} else {
- for (tp = first_tabpage; tp->tp_next != NULL && n > 1; tp = tp->tp_next)
- --n;
- curtab->tp_next = tp->tp_next;
- tp->tp_next = curtab;
+ curtab->tp_next = tp_dst->tp_next;
+ tp_dst->tp_next = curtab;
}
/* Need to redraw the tabline. Tab page contents doesn't change. */