Mercurial > vim
comparison src/window.c @ 34538:c865c2f93a04 v9.1.0171
patch 9.1.0171: Small split-move related improvements
Commit: https://github.com/vim/vim/commit/5cac1a9bee0798d70a7fd80363a1f697759638e8
Author: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Date: Tue Mar 12 21:11:39 2024 +0100
patch 9.1.0171: Small split-move related improvements
Problem: small improvements can be made to split-move related
functions.
Solution: apply them (Sean Dewar):
- Improve some doc comments (frame_flatten should still work for non-current
tabpages, despite the topframe check, which looks benign, though I'm unsure if
it's still needed; see #2467).
- f_win_splitmove should check_split_disallowed on wp, not targetwin, as that's
what win_splitmove checks (though it's probably unnecessary to check
b_locked_split at all; see #14109, which I hope to get around to finishing at
some point).
- Make winframe_restore restore window positions for the altframe, which
winframe_remove changes. This doesn't affect the prior behaviour, as we called
win_comp_pos after, but as win_comp_pos only works for curtab, and
winframe_remove supports non-current tabpages, we should undo it. Regardless,
this should mean we don't need win_comp_pos anymore; adjust tests to check
that window positions remain unchanged.
I'm not sure win_comp_pos is needed after last_status anyway if it doesn't
steal rows from another frame to make room for a new statusline, which
shouldn't be the case after winframe_remove? To be safe, I'll leave it as is.
closes: #14185
Signed-off-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 12 Mar 2024 21:15:03 +0100 |
parents | ad6cd802579d |
children | db67c09ccd53 |
comparison
equal
deleted
inserted
replaced
34537:6e23d69b728e | 34538:c865c2f93a04 |
---|---|
894 else | 894 else |
895 STRCPY(bufp, cmd); | 895 STRCPY(bufp, cmd); |
896 } | 896 } |
897 | 897 |
898 /* | 898 /* |
899 * If "split_disallowed" is set for "wp", give an error and return FAIL. | 899 * If "split_disallowed" is set, or "wp"'s buffer is closing, give an error and |
900 * Otherwise return OK. | 900 * return FAIL. Otherwise return OK. |
901 */ | 901 */ |
902 int | 902 int |
903 check_split_disallowed(win_T *wp) | 903 check_split_disallowed(win_T *wp) |
904 { | 904 { |
905 if (split_disallowed > 0) | 905 if (split_disallowed > 0) |
1978 { | 1978 { |
1979 // win_split_ins doesn't change sizes or layout if it fails to insert an | 1979 // win_split_ins doesn't change sizes or layout if it fails to insert an |
1980 // existing window, so just undo winframe_remove. | 1980 // existing window, so just undo winframe_remove. |
1981 winframe_restore(wp, dir, unflat_altfr); | 1981 winframe_restore(wp, dir, unflat_altfr); |
1982 win_append(wp->w_prev, wp); | 1982 win_append(wp->w_prev, wp); |
1983 (void)win_comp_pos(); // recompute window positions | |
1984 return FAIL; | 1983 return FAIL; |
1985 } | 1984 } |
1986 | 1985 |
1987 // If splitting horizontally, try to preserve height. | 1986 // If splitting horizontally, try to preserve height. |
1988 // Note that win_split_ins autocommands may have immediately closed "wp"! | 1987 // Note that win_split_ins autocommands may have immediately closed "wp"! |
3605 | 3604 |
3606 /* | 3605 /* |
3607 * Flatten "frp" into its parent frame if it's the only child, also merging its | 3606 * Flatten "frp" into its parent frame if it's the only child, also merging its |
3608 * list with the grandparent if they share the same layout. | 3607 * list with the grandparent if they share the same layout. |
3609 * Frees "frp" if flattened; also "frp->fr_parent" if it has the same layout. | 3608 * Frees "frp" if flattened; also "frp->fr_parent" if it has the same layout. |
3610 * "frp" must be valid in the current tabpage. | |
3611 */ | 3609 */ |
3612 static void | 3610 static void |
3613 frame_flatten(frame_T *frp) | 3611 frame_flatten(frame_T *frp) |
3614 { | 3612 { |
3615 frame_T *frp2, *frp3; | 3613 frame_T *frp2, *frp3; |
3658 } | 3656 } |
3659 } | 3657 } |
3660 | 3658 |
3661 /* | 3659 /* |
3662 * Undo changes from a prior call to winframe_remove, also restoring lost | 3660 * Undo changes from a prior call to winframe_remove, also restoring lost |
3663 * vertical separators and statuslines. | 3661 * vertical separators and statuslines, and changed window positions for |
3662 * windows within "unflat_altfr". | |
3664 * Caller must ensure no other changes were made to the layout or window sizes! | 3663 * Caller must ensure no other changes were made to the layout or window sizes! |
3665 */ | 3664 */ |
3666 static void | 3665 static void |
3667 winframe_restore(win_T *wp, int dir, frame_T *unflat_altfr) | 3666 winframe_restore(win_T *wp, int dir, frame_T *unflat_altfr) |
3668 { | 3667 { |
3669 frame_T *frp = wp->w_frame; | 3668 frame_T *frp = wp->w_frame; |
3669 int row = wp->w_winrow; | |
3670 int col = wp->w_wincol; | |
3670 | 3671 |
3671 // Put "wp"'s frame back where it was. | 3672 // Put "wp"'s frame back where it was. |
3672 if (frp->fr_prev != NULL) | 3673 if (frp->fr_prev != NULL) |
3673 frame_append(frp->fr_prev, frp); | 3674 frame_append(frp->fr_prev, frp); |
3674 else | 3675 else |
3682 // Statuslines above may have been lost. Restore them. | 3683 // Statuslines above may have been lost. Restore them. |
3683 if (wp->w_status_height == 0 | 3684 if (wp->w_status_height == 0 |
3684 && frp->fr_parent->fr_layout == FR_COL && frp->fr_prev != NULL) | 3685 && frp->fr_parent->fr_layout == FR_COL && frp->fr_prev != NULL) |
3685 frame_add_statusline(frp->fr_prev); | 3686 frame_add_statusline(frp->fr_prev); |
3686 | 3687 |
3687 // Restore the lost room that was redistributed to the altframe. | 3688 // Restore the lost room that was redistributed to the altframe. Also |
3689 // adjusts window sizes to fit restored statuslines/separators, if needed. | |
3688 if (dir == 'v') | 3690 if (dir == 'v') |
3689 { | 3691 { |
3690 frame_new_height(unflat_altfr, unflat_altfr->fr_height - frp->fr_height, | 3692 frame_new_height(unflat_altfr, unflat_altfr->fr_height - frp->fr_height, |
3691 unflat_altfr == frp->fr_next, FALSE); | 3693 unflat_altfr == frp->fr_next, FALSE); |
3694 row += frp->fr_height; | |
3692 } | 3695 } |
3693 else if (dir == 'h') | 3696 else if (dir == 'h') |
3694 { | 3697 { |
3695 frame_new_width(unflat_altfr, unflat_altfr->fr_width - frp->fr_width, | 3698 frame_new_width(unflat_altfr, unflat_altfr->fr_width - frp->fr_width, |
3696 unflat_altfr == frp->fr_next, FALSE); | 3699 unflat_altfr == frp->fr_next, FALSE); |
3697 } | 3700 col += frp->fr_width; |
3701 } | |
3702 | |
3703 // If rows/columns went to a window below/right, its positions need to be | |
3704 // restored. Can only be done after the sizes have been updated. | |
3705 if (unflat_altfr == frp->fr_next) | |
3706 frame_comp_pos(unflat_altfr, &row, &col); | |
3698 } | 3707 } |
3699 | 3708 |
3700 /* | 3709 /* |
3701 * Return a pointer to the frame that will receive the empty screen space that | 3710 * Return a pointer to the frame that will receive the empty screen space that |
3702 * is left over after "win" is closed. | 3711 * is left over after "win" is closed. |