Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Add mark range function
Browse files Browse the repository at this point in the history
Sets the marked state of all images ranging from the latest marked/unmarked
image to the current image, to the state of that latest toggled image.
  • Loading branch information
quite authored and xyb3rt committed Jun 9, 2018
1 parent 8bf1adc commit 6e696ba
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
35 changes: 35 additions & 0 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern fileinfo_t *files;
extern int filecnt, fileidx;
extern int alternate;
extern int markcnt;
extern int toggledidx;

extern int prefix;
extern bool extprefix;
Expand Down Expand Up @@ -196,6 +197,7 @@ bool cg_toggle_image_mark(arg_t _)
markcnt += files[fileidx].flags & FF_MARK ? 1 : -1;
if (mode == MODE_THUMB)
tns_mark(&tns, fileidx, !!(files[fileidx].flags & FF_MARK));
toggledidx = fileidx;
return true;
}

Expand All @@ -212,6 +214,39 @@ bool cg_reverse_marks(arg_t _)
return true;
}

bool cg_mark_range(arg_t _)
{
int i, from, to;

if (toggledidx < 0)
return true;
if (toggledidx == fileidx)
return true;

from = toggledidx;
to = fileidx;
if (fileidx < toggledidx) {
from = fileidx;
to = toggledidx;
}
for (i = from; i <= to; i++) {
if (files[toggledidx].flags & FF_MARK) {
if (!(files[i].flags & FF_MARK)) {
files[i].flags |= FF_MARK;
markcnt += 1;
}
} else {
if (files[i].flags & FF_MARK) {
files[i].flags &= ~FF_MARK;
markcnt -= 1;
}
}
if (mode == MODE_THUMB)
tns_mark(&tns, i, !!(files[i].flags & FF_MARK));
}
return true;
}

bool cg_unmark_all(arg_t _)
{
int i;
Expand Down
1 change: 1 addition & 0 deletions commands.lst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ G_CMD(scroll_screen)
G_CMD(zoom)
G_CMD(toggle_image_mark)
G_CMD(reverse_marks)
G_CMD(mark_range)
G_CMD(unmark_all)
G_CMD(navigate_marked)
G_CMD(change_gamma)
Expand Down
1 change: 1 addition & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static const keymap_t keys[] = {
{ 0, XK_KP_Subtract, g_zoom, -1 },
{ 0, XK_m, g_toggle_image_mark, None },
{ 0, XK_M, g_reverse_marks, None },
{ ControlMask, XK_M, g_mark_range, None },
{ ControlMask, XK_m, g_unmark_all, None },
{ 0, XK_N, g_navigate_marked, +1 },
{ 0, XK_P, g_navigate_marked, -1 },
Expand Down
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fileinfo_t *files;
int filecnt, fileidx;
int alternate;
int markcnt;
int toggledidx = -1;

int prefix;
bool extprefix;
Expand Down
4 changes: 4 additions & 0 deletions sxiv.1
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ Mark/unmark the current image.
.B M
Reverse all image marks.
.TP
.B Ctrl-M
Repeat last mark action on all images from the last marked/unmarked up to the
current one.
.TP
.B Ctrl-m
Remove all image marks.
.TP
Expand Down

0 comments on commit 6e696ba

Please sign in to comment.