Add support for page up and page down
This commit is contained in:
parent
499bb77491
commit
46565723b1
|
@ -16,7 +16,7 @@ struct Key
|
|||
Alt = 2,
|
||||
ControlAlt = 3
|
||||
};
|
||||
enum NamedKeys : Character
|
||||
enum NamedKey : Character
|
||||
{
|
||||
Backspace = 256,
|
||||
Escape,
|
||||
|
@ -24,6 +24,8 @@ struct Key
|
|||
Down,
|
||||
Left,
|
||||
Right,
|
||||
PageUp,
|
||||
PageDown,
|
||||
};
|
||||
|
||||
Modifiers modifiers;
|
||||
|
|
28
src/main.cc
28
src/main.cc
|
@ -236,6 +236,31 @@ void do_select_object(Context& context)
|
|||
});
|
||||
}
|
||||
|
||||
template<Key::NamedKey key>
|
||||
void do_scroll(Context& context)
|
||||
{
|
||||
static_assert(key == Key::PageUp or key == Key::PageDown,
|
||||
"do_scrool only implements PageUp and PageDown");
|
||||
Window& window = context.window();
|
||||
Buffer& buffer = context.buffer();
|
||||
BufferCoord position = window.position();
|
||||
BufferIterator cursor_pos;
|
||||
|
||||
if (key == Key::PageUp)
|
||||
{
|
||||
position.line -= (window.dimensions().line - 2);
|
||||
cursor_pos = buffer.iterator_at(position);
|
||||
}
|
||||
else if (key == Key::PageDown)
|
||||
{
|
||||
position.line += (window.dimensions().line - 2);
|
||||
cursor_pos = buffer.iterator_at(position + BufferCoord{window.dimensions().line - 1, 0});
|
||||
}
|
||||
|
||||
window.select(cursor_pos);
|
||||
window.set_position(position);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class Repeated
|
||||
{
|
||||
|
@ -370,6 +395,9 @@ std::unordered_map<Key, std::function<void (Context& context)>> keymap =
|
|||
{ { Key::Modifiers::Alt, 'x' }, [](Context& context) { context.editor().select(select_whole_lines); } },
|
||||
|
||||
{ { Key::Modifiers::Alt, 'c' }, [](Context& context) { if (context.has_window()) context.window().center_selection(); } },
|
||||
|
||||
{ { Key::Modifiers::None, Key::PageUp }, do_scroll<Key::PageUp> },
|
||||
{ { Key::Modifiers::None, Key::PageDown }, do_scroll<Key::PageDown> },
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -187,6 +187,8 @@ Key NCursesClient::get_key()
|
|||
case KEY_DOWN: return Key::Down;
|
||||
case KEY_LEFT: return Key::Left;
|
||||
case KEY_RIGHT: return Key::Right;
|
||||
case KEY_PPAGE: return Key::PageUp;
|
||||
case KEY_NPAGE: return Key::PageDown;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@ public:
|
|||
~Window();
|
||||
|
||||
const BufferCoord& position() const { return m_position; }
|
||||
void set_position(const BufferCoord& position) { m_position = buffer().clamp(position); }
|
||||
|
||||
const DisplayCoord& dimensions() const { return m_dimensions; }
|
||||
void set_dimensions(const DisplayCoord& dimensions);
|
||||
|
||||
const DisplayBuffer& display_buffer() const { return m_display_buffer; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user