Skip to content

Commit

Permalink
sheet: Fix scrolling up when a buffer refill is required (#271)
Browse files Browse the repository at this point in the history
* sheet: Fix scrolling up when a buffer refill is required
* Update Makefile
  • Loading branch information
richiejp authored Nov 11, 2024
1 parent ed36726 commit fae69db
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/sheet/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static int zsvsheet_goto_input_raw_row(struct zsvsheet_ui_buffer *uib, size_t in

size_t buffer_rows = zsvsheet_buffer_rows(buffer);
int update_buffer = 0;
if (input_raw_num < input_offset->row // move the buffer up
if (input_raw_num < input_offset->row + input_header_span // move the buffer up
|| input_raw_num + input_header_span + 1 > input_offset->row + buffer_rows // move the buffer down
) {
input_offset->row = input_offset_centered(input_dims, buffer_rows, input_raw_num);
Expand Down
14 changes: 13 additions & 1 deletion app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ test-sheet: test-%: ${BUILD_DIR}/bin/zsv_%${EXE} worldcitiespop_mil.csv test-she
test-sheet-cleanup:
@rm -f tmux-*.log

test-sheet-all: test-sheet-1 test-sheet-2 test-sheet-3 test-sheet-4 test-sheet-5 test-sheet-6 test-sheet-7 test-sheet-8
test-sheet-all: test-sheet-1 test-sheet-2 test-sheet-3 test-sheet-4 test-sheet-5 test-sheet-6 test-sheet-7 test-sheet-8 test-sheet-9
@(for SESSION in $^; do ! tmux kill-session -t "$$SESSION" 2>/dev/null; done && ${TEST_PASS} || ${TEST_FAIL})

TMUX_TERM=xterm-256color
Expand Down Expand Up @@ -672,3 +672,15 @@ test-sheet-8: ${BUILD_DIR}/bin/zsv_sheet${EXE}
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
tmux send-keys -t $@ "q" && \
${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || (echo 'Incorrect output:' && cat ${TMP_DIR}/$@.out && ${TEST_FAIL}))

test-sheet-9: ${BUILD_DIR}/bin/zsv_sheet${EXE}
@${TEST_INIT}
@echo 'set-option default-terminal "${TMUX_TERM}"' > ~/.tmux.conf
@(tmux new-session -x 80 -y 6 -d -s $@ "${PREFIX} $< -d 3 ${TEST_DATA_DIR}/test/mixed-line-endings.csv" && \
sleep 0.5 && \
tmux send-keys -t $@ "G" && \
tmux send-keys -t $@ -N 4096 "k" && \
sleep 2 && \
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
tmux send-keys -t $@ "q" && \
${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || (echo 'Incorrect output:' && cat ${TMP_DIR}/$@.out && ${TEST_FAIL}))
1 change: 1 addition & 0 deletions app/test/expected/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!*.out
6 changes: 6 additions & 0 deletions app/test/expected/test-sheet-9.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Row # HA1 HA2 HA3 HB1 HB2 HB3 HC1 HC2 HC3
1 A1 B1 C1
2 A2 B2 C2
3 A3 B3 C3
4 A4 B4 C4
? for help Row #

0 comments on commit fae69db

Please sign in to comment.