From a65cd3a593acb3b556fb5cf7d54c87ff034e1b74 Mon Sep 17 00:00:00 2001 From: Richard Palethorpe Date: Fri, 8 Nov 2024 13:33:01 +0000 Subject: [PATCH] sheet: Fix scrolling up when a buffer refill is required Also remove *.out from .gitignore for the expected directory so that the expected outputs don't have to be force added. --- app/sheet/cursor.c | 2 +- app/test/Makefile | 14 +++++++++++++- app/test/expected/.gitignore | 1 + app/test/expected/test-sheet-9.out | 6 ++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/test/expected/.gitignore create mode 100644 app/test/expected/test-sheet-9.out diff --git a/app/sheet/cursor.c b/app/sheet/cursor.c index ba3d22d8..c1a45768 100644 --- a/app/sheet/cursor.c +++ b/app/sheet/cursor.c @@ -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); diff --git a/app/test/Makefile b/app/test/Makefile index 22dc55d0..8db4fe42 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -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 @@ -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-256color"' > ~/.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 1 && \ + 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})) diff --git a/app/test/expected/.gitignore b/app/test/expected/.gitignore new file mode 100644 index 00000000..6aa6b80a --- /dev/null +++ b/app/test/expected/.gitignore @@ -0,0 +1 @@ +!*.out diff --git a/app/test/expected/test-sheet-9.out b/app/test/expected/test-sheet-9.out new file mode 100644 index 00000000..3de62ade --- /dev/null +++ b/app/test/expected/test-sheet-9.out @@ -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 #