Skip to content

Commit c3b7c78

Browse files
committed
Merge branch 'ctrl-b-whitespace-ignore'
* Branch commit log: jj-fzf: Ctrl-B: support cycling through whitespace-ignore options for diffs lib/{reparent.sh|rebase.sh}: enable preview wrap on startup Signed-off-by: Tim Janik <timj@gnu.org>
2 parents 42d1ce3 + f7edc31 commit c3b7c78

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

jj-fzf

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ while test $# -ne 0 ; do
2323
esac
2424
shift
2525
done
26+
echo "IGNORE_SPACE='$(jjfzf_config get jj-fzf.whitespace-mode)'" >> $JJFZF_TEMPD/preview.env
2627

2728
# == Config ==
2829
export JJFZF_REVSET_OVERRIDE="$JJFZF_TEMPD/log_revset"
@@ -41,13 +42,17 @@ jjfzf_full_commit()
4142
set -Eeuo pipefail
4243
test -z "${1-}" && # may be revset
4344
exit 0
44-
jjfzf_jjlog "$JJFZF_LOG_DETAILED_CONFIG" $JJFZF_COLOR --no-graph -r "$1" -p \
45-
-T '"\n" ++ concat( builtin_log_oneline , builtin_log_detailed , diff.stat() , "\n" )'
45+
IGNORE_SPACE=
46+
test -r "$JJFZF_TEMPD/preview.env" && . $JJFZF_TEMPD/preview.env # IGNORE_SPACE
47+
test -z "$IGNORE_SPACE" && DIFF_COMMENT='""' || DIFF_COMMENT="\"diff $IGNORE_SPACE\\n\""
48+
jjfzf_jjlog "$JJFZF_LOG_DETAILED_CONFIG" $JJFZF_COLOR $IGNORE_SPACE --no-graph -r "$1" -p \
49+
-T '"\n" ++ concat( builtin_log_oneline , builtin_log_detailed , diff.stat() , "\n", '"$DIFF_COMMENT"' )'
4650
)
4751
export -f jjfzf_full_commit
4852
jjfzf_log_detailed # for preview, assigns $JJFZF_LOG_DETAILED_CONFIG
4953

5054
# == jjfzf_full_history ==
55+
# Browse revset history in pager
5156
jjfzf_full_history()
5257
(
5358
set -Eeuo pipefail
@@ -234,6 +239,24 @@ KEY[undo]="Alt-Z"
234239
RUN[undo]="jjfzf_run jj --no-pager undo"
235240
DOC[undo]='Use `jj undo` to undo the last operation performed by `jj` that was not previously undone.'
236241

242+
# Whitespace toggle
243+
KEY[nospace]="Ctrl-B"
244+
DOC[nospace]='Cycle between preview diff display with and without whitespace.'
245+
BINDINGS+=( --bind "ctrl-b:execute-silent( jjfzf_whitespace_cycle )+refresh-preview" )
246+
jjfzf_whitespace_cycle()
247+
(
248+
CURRENT_WHITESPACE=$(jjfzf_config get jj-fzf.whitespace-mode)
249+
WHITESPACE_MODES=("--ignore-space-change" "--ignore-all-space" "")
250+
index=0
251+
for i in "${!WHITESPACE_MODES[@]}"; do
252+
[[ "${WHITESPACE_MODES[$i]}" == "$CURRENT_WHITESPACE" ]] && { index=$i && break; }
253+
done
254+
next_index=$(( (index + 1) % ${#WHITESPACE_MODES[@]} ))
255+
jjfzf_config set jj-fzf.whitespace-mode "${WHITESPACE_MODES[$next_index]}"
256+
sed "s/^IGNORE_SPACE=.*/IGNORE_SPACE='${WHITESPACE_MODES[$next_index]}'/" -i $JJFZF_TEMPD/preview.env
257+
)
258+
export -f jjfzf_whitespace_cycle
259+
237260
# Describe
238261
KEY[describe]="Ctrl-D"
239262
RUN[describe]="jjfzf_describe_commit {2}"

lib/rebase.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export -f jjfzf_log0_marked_revs
163163
FZF_ARGS+=(
164164
--color=border:magenta,label:magenta
165165
--border-label "-[ ${TITLE^^} — JJ-FZF ]-"
166+
--bind "load:+toggle-preview-wrap"
166167
--footer "${TITLE}"
167168
--bind 'focus:+transform-ghost( R={2} && echo -n "${R:0:12}" )'
168169
)

lib/reparent.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ FZF_ARGS+=(
156156
--bind 'focus:+transform-ghost( R={2} && echo -n "${R:0:12}" )'
157157
--prompt 'Parent > '
158158
--bind "start,resize,alt-h:+transform-header: jjfzf_header "
159-
--bind "start:+toggle-preview-wrap"
159+
--bind "load:+toggle-preview-wrap"
160160
--footer "${TITLE}"
161161
)
162162
test -z "${FZF_POS-}" ||

0 commit comments

Comments
 (0)