чување 3a1b22049eed8ab79c625efcac75f089eda3f2b5
родитељ e8b4e766ff073bb758f8f8414e820f874db97200
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 21 Feb 2022 18:07:24 +0100
Add vi M; default.pdf.do: New file
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 5, додавања: 56(+), брисања: 4(-)
diff --git a/config.def.h b/config.def.h
@@ -64,6 +64,7 @@ int move_page_up(struct DrawState* state);
int move_prev_word(struct DrawState* state);
int move_right(struct DrawState* state);
int move_screen_bottom(struct DrawState* state);
+int move_screen_middle(struct DrawState* state);
int move_screen_top(struct DrawState* state);
int move_start(struct DrawState* state);
int move_top(struct DrawState* state);
@@ -190,6 +191,7 @@ static const struct Key command_keys[] = {
{ .ev = { .ch = 'k' }, .callback = move_up },
{ .ev = { .ch = 'L' }, .callback = move_screen_bottom },
{ .ev = { .ch = 'l' }, .callback = move_right },
+ { .ev = { .ch = 'M' }, .callback = move_screen_middle },
{ .ev = { .ch = 'q' }, .callback = exit_program },
{ .ev = { .ch = 'v' }, .callback = toggle_selection },
{ .ev = { .ch = 'W' }, .callback = move_prev_word },
diff --git a/config.h b/config.h
@@ -64,6 +64,7 @@ int move_page_up(struct DrawState* state);
int move_prev_word(struct DrawState* state);
int move_right(struct DrawState* state);
int move_screen_bottom(struct DrawState* state);
+int move_screen_middle(struct DrawState* state);
int move_screen_top(struct DrawState* state);
int move_start(struct DrawState* state);
int move_top(struct DrawState* state);
@@ -190,6 +191,7 @@ static const struct Key command_keys[] = {
{ .ev = { .ch = 'k' }, .callback = move_up },
{ .ev = { .ch = 'L' }, .callback = move_screen_bottom },
{ .ev = { .ch = 'l' }, .callback = move_right },
+ { .ev = { .ch = 'M' }, .callback = move_screen_middle },
{ .ev = { .ch = 'q' }, .callback = exit_program },
{ .ev = { .ch = 'v' }, .callback = toggle_selection },
{ .ev = { .ch = 'W' }, .callback = move_prev_word },
diff --git a/default.pdf.do b/default.pdf.do
@@ -0,0 +1,2 @@
+redo-ifchange $2.1
+groff -mandoc -t -T pdf $2.1 >$3
diff --git a/sled.1.in b/sled.1.in
@@ -136,6 +136,7 @@ _
\fCk\fP@Go to previous line
\fCL\fP@Go to last line on the screen
\fCl\fP@Go to next character
+\fCM\fP@Go to middle line on the screen
\fCq\fP@Quit
\fCv\fP@Toggle selection mode
\fCW\fP@Go to previous word
diff --git a/sled.c b/sled.c
@@ -537,6 +537,45 @@ move_screen_top(struct DrawState* state)
}
int
+move_screen_middle(struct DrawState* state)
+{
+ if (state->rows_count < state->maxy - 2)
+ {
+ state->row = state->rows_count / 2;
+ state->first_shown_row = 0;
+ }
+ else
+ {
+ state->row = state->first_shown_row + (state->maxy - 2) / 2;
+ if (state->rows_count - state->row < (state->maxy - 2) / 2)
+ state->row = state->rows_count - (state->maxy - 2) / 2;
+ }
+ if (state->saved_column == -1)
+ state->saved_column = state->display_column;
+ size_t dlen = display_length(state, state->buffer[state->row].text,
+ state->buffer[state->row].length);
+ if (dlen < state->saved_column)
+ state->display_column = dlen;
+ else
+ state->display_column = state->saved_column;
+ state->column = buffer_length(state, state->buffer[state->row].text,
+ state->display_column);
+ if (state->first_shown_column > state->display_column)
+ state->first_shown_column = state->display_column;
+ if (state->first_shown_column + state->maxx - 1 < state->display_column)
+ state->first_shown_column
+ = state->display_column - state->maxx + 1;
+ state->display_column = display_length(state,
+ state->buffer[state->row].text, state->column);
+ if (state->in_selection_mode)
+ {
+ state->sel_end_row = state->row;
+ state->sel_end_col = state->column;
+ }
+ return 0;
+}
+
+int
move_start(struct DrawState* state)
{
state->column = 0;
@@ -698,10 +737,16 @@ move_bottom(struct DrawState* state)
int
move_screen_bottom(struct DrawState* state)
{
- if (state->row == state->rows_count - 1)
- return 0;
- if (state->first_shown_row + state->maxy - 2 < state->rows_count)
- state->row = state->first_shown_row + state->maxy - 2;
+ if (state->rows_count < state->maxy - 2)
+ {
+ state->row = state->rows_count - 1;
+ state->first_shown_row = 0;
+ }
+ else
+ {
+ if (state->first_shown_row + state->maxy - 2 < state->rows_count)
+ state->row = state->first_shown_row + state->maxy - 2;
+ }
if (state->saved_column == -1)
state->saved_column = state->display_column;
size_t dlen = display_length(state, state->buffer[state->row].text,