Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/ftb-tmux-popup
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ if (( ! $+IN_FZF_TAB )); then
cat > $tmp_dir/completions.$$
fi

local text REPLY comp_lines comp_length length popup_pad popup_min_size
local text REPLY comp_lines comp_length length popup_pad popup_min_size popup_max_width popup_max_height

zstyle -a ":fzf-tab:$_ftb_curcontext" popup-pad popup_pad || popup_pad=(0 0)
zstyle -a ":fzf-tab:$_ftb_curcontext" popup-min-size popup_min_size || popup_min_size=(0 0)
zstyle -s ":fzf-tab:$_ftb_curcontext" popup-max-height popup_max_height || popup_max_height=$window_height
zstyle -s ":fzf-tab:$_ftb_curcontext" popup-max-width popup_max_width || popup_max_width=$window_width

# get the size of content, note we should remove all ANSI color code
comp_lines=$(( ${#${(f)mapfile[$tmp_dir/completions.$$]}} + $popup_pad[2] ))
Expand All @@ -70,21 +72,21 @@ fi
# calculate the popup height and y position
if (( cursor_y * 2 > window_height )); then
# show above the cursor
popup_height=$(( min(max(comp_lines + 4, popup_min_size[2]), cursor_y - window_top) + adjust_height ))
popup_height=$(( min(max(min(comp_lines, popup_max_height) + 4, popup_min_size[2]), cursor_y - window_top) + adjust_height ))
popup_y=$cursor_y
if zstyle -T ":fzf-tab:$_ftb_curcontext" popup-smart-tab; then
fzf_opts+=(--bind=tab:up,btab:down)
fi
fzf_opts+=(--layout=default)
else
# show below the cursor
popup_height=$(( min(max(comp_lines + 4, popup_min_size[2]), window_height - cursor_y + window_top - 1) + adjust_height ))
popup_height=$(( min(max(min(comp_lines, popup_max_height) + 4, popup_min_size[2]), window_height - cursor_y + window_top - 1) + adjust_height ))
popup_y=$(( cursor_y + popup_height + 1 ))
fzf_opts+=(--layout=reverse)
fi

# calculate the popup width and x position
popup_width=$(( min(max(comp_length + 5, popup_min_size[1]), window_width) ))
popup_width=$(( min(min(max(comp_length + 5, popup_min_size[1]), window_width), popup_max_width) ))
popup_x=$(( cursor_x + popup_width > window_width ? window_width - popup_width : cursor_x ))

echo -E "env FZF_DEFAULT_OPTS=${(qq)FZF_DEFAULT_OPTS} SHELL=$ZSH_NAME $commands[fzf] ${(qq)fzf_opts[@]} < $tmp_dir/completions.$$ > $tmp_dir/result-$$" > $tmp_dir/fzf-$$
Expand Down