Skip to content

Commit 47f0a84

Browse files
author
Bruno Sutic
committed
Improve sidebar right handling
1 parent 48413c6 commit 47f0a84

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- more options for customizing tree sidebar
55
- describe various options in the readme
66
- fix sidebar right resizing
7+
- improve sidebar right handling
78

89
### v0.5.0, Sep 04, 2014
910
- key bindings work from the sidebar now too

scripts/toggle.sh

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -119,62 +119,57 @@ size_defined() {
119119
[ -n $SIZE ]
120120
}
121121

122-
# this is done just to refresh the main pane. See github issue #14.
123-
touch_resize_main_pane() {
124-
local sidebar_id="$1"
125-
if sidebar_left; then
126-
tmux resize-pane -t "$sidebar_id" "-R" 1
127-
else
128-
tmux resize-pane -t "$PANE_ID" "-L" 1
129-
fi
130-
}
131-
132-
sidebar_left_resize() {
133-
local sidebar_width="$1"
122+
desired_sidebar_size() {
123+
local half_pane="$((PANE_WIDTH / 2))"
134124
if directory_in_sidebar_file "$PANE_CURRENT_PATH"; then
135125
# use stored sidebar width for the directory
136-
local saved_width="$(width_from_sidebar_file "$PANE_CURRENT_PATH")"
137-
tmux resize-pane -x "$((saved_width - 1))"
138-
elif size_defined && [ $SIZE -lt $sidebar_width ]; then
139-
tmux resize-pane -x "$((SIZE - 1))"
126+
echo "$(width_from_sidebar_file "$PANE_CURRENT_PATH")"
127+
elif size_defined && [ $SIZE -lt $half_pane ]; then
128+
echo $SIZE
140129
fi
141130
}
142131

143-
sidebar_right_resize() {
144-
local sidebar_width="$1"
145-
local correction
146-
if directory_in_sidebar_file "$PANE_CURRENT_PATH"; then
147-
# use stored sidebar width for the directory
148-
local saved_width="$(width_from_sidebar_file "$PANE_CURRENT_PATH")"
149-
correction="$((sidebar_width - saved_width))"
150-
tmux resize-pane -t "$PANE_ID" -R "$((correction + 1))"
151-
elif size_defined && [ $SIZE -lt $sidebar_width ]; then
152-
correction="$((SIZE - saved_width))"
153-
tmux resize-pane -t "$PANE_ID" -R "$((correction + 1))"
132+
resize_sidebar_left() {
133+
local "$sidebar_id"
134+
local desired_size="$(desired_sidebar_size)"
135+
if [ -n $desired_size ]; then
136+
tmux resize-pane -x "$((desired_size - 1))"
137+
# this is done just to refresh the main pane. See github issue #14.
138+
tmux resize-pane -t "$sidebar_id" "-R" 1
154139
fi
155140
}
156141

157-
split_sidebar() {
142+
split_sidebar_left() {
158143
tmux split-window "$(orientation_option)" -c "$PANE_CURRENT_PATH" -P -F "#{pane_id},#{pane_width}" "$COMMAND"
159144
}
160145

161-
create_sidebar() {
162-
local sidebar_info=$(split_sidebar)
146+
create_sidebar_left() {
147+
local sidebar_info=$(split_sidebar_left)
163148
local sidebar_id=$(echo "$sidebar_info" | cut -d',' -f1)
164-
local sidebar_width=$(echo "$sidebar_info" | cut -d',' -f2) # half a pane
165149
register_sidebar "$sidebar_id" "$PANE_ID"
166150
register_sidebar_for_current_pane "$sidebar_id"
167-
if sidebar_left; then
168-
tmux swap-pane -U
169-
sidebar_left_resize "$sidebar_width"
170-
else # sidebar right
171-
sidebar_right_resize "$sidebar_width"
151+
tmux swap-pane -U
152+
resize_sidebar_left "$sidebar_id"
153+
154+
if no_focus; then
155+
tmux last-pane
172156
fi
157+
}
158+
159+
split_sidebar_right() {
160+
local sidebar_size=$(desired_sidebar_size)
161+
tmux split-window "$(orientation_option)" -l "$sidebar_size" -c "$PANE_CURRENT_PATH" -P -F "#{pane_id},#{pane_width}" "$COMMAND"
162+
}
163+
164+
create_sidebar_right() {
165+
local sidebar_info=$(split_sidebar_right)
166+
local sidebar_id=$(echo "$sidebar_info" | cut -d',' -f1)
167+
register_sidebar "$sidebar_id" "$PANE_ID"
168+
register_sidebar_for_current_pane "$sidebar_id"
173169

174170
if no_focus; then
175171
tmux last-pane
176172
fi
177-
touch_resize_main_pane "$sidebar_id"
178173
}
179174

180175
current_pane_is_sidebar() {
@@ -209,7 +204,11 @@ toggle_sidebar() {
209204
# fi
210205
else
211206
exit_if_pane_too_narrow
212-
create_sidebar
207+
if sidebar_left; then
208+
create_sidebar_left
209+
else
210+
create_sidebar_right
211+
fi
213212
fi
214213
}
215214

0 commit comments

Comments
 (0)