Skip to content

Commit

Permalink
Pause before rolling over at first/last elements
Browse files Browse the repository at this point in the history
  • Loading branch information
kannibalox committed Dec 16, 2024
1 parent a41533e commit 58990b8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
29 changes: 25 additions & 4 deletions src/core/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,41 @@ View::set_not_visible(Download* download) {
}

void
View::next_focus(int i) {
View::next_focus(unsigned int i) {
if (empty())
return;

m_focus = (m_focus + i) % (size() + 1);
// If at the boundary, roll over
if (m_focus == size() - 1) {
m_focus = size();
} else {
// Move forward, stop at the boundary
if (m_focus == size())
m_focus = i - 1;
else
m_focus += i;
if (m_focus > size() - 1)
m_focus = size() - 1;
}

emit_changed();
}

void
View::prev_focus(int i) {
View::prev_focus(unsigned int i) {
if (empty())
return;

m_focus = (m_focus - i + size() + 1) % (size() + 1);
// If at the boundary, roll over
if (m_focus == size()) {
m_focus = size() - 1;
} else {
// Move backward, stop at the boundary
m_focus -= i;
if (m_focus < 0 || m_focus > size())
m_focus = size();
}

emit_changed();
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class View : private std::vector<Download*> {
void set_visible(Download* download);
void set_not_visible(Download* download);

void next_focus(int i);
void prev_focus(int i);
void next_focus(unsigned int i);
void prev_focus(unsigned int i);

void next_focus() { next_focus(1); }
void prev_focus() { prev_focus(1); }
Expand Down
2 changes: 1 addition & 1 deletion src/ui/element_download_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ElementDownloadList::ElementDownloadList() :
m_bindings[KEY_DOWN] = m_bindings['N' - '@'] = std::bind(&ElementDownloadList::receive_next, this);

m_bindings[KEY_PPAGE] = m_bindings['K' - '@'] = [this] { receive_prev_page(); };
m_bindings[KEY_NPAGE] = m_bindings['J' - '@'] = [this] { receive_next_page(); };
m_bindings[KEY_NPAGE] = m_bindings['H' - '@'] = [this] { receive_next_page(); };

m_bindings[KEY_HOME] = m_bindings['A' - '@'] = [this] { receive_home(); };
m_bindings[KEY_END] = m_bindings['E' - '@'] = [this] { receive_end(); };
Expand Down

0 comments on commit 58990b8

Please sign in to comment.