summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-09-17 14:28:23 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-09-17 14:28:23 +0000
commit0513b4de29114fbeb661e39f52fdb68540bdb024 (patch)
tree6bbd540fc05982564c135f61f40472f110f98e67 /src
parent34c9b0d30fe157b52b302a71e2ef73ceba86fab0 (diff)
Shift-{H,J,K,L} keys move cursor while selecting.
Diffstat (limited to 'src')
-rw-r--r--src/main.cc26
-rw-r--r--src/window.cc4
2 files changed, 23 insertions, 7 deletions
diff --git a/src/main.cc b/src/main.cc
index 9d9abda2..e3a21e27 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -346,12 +346,30 @@ void do_search(Window& window)
catch (prompt_aborted&) {}
}
+Selection move_select(Window& window, const BufferIterator& cursor, const WindowCoord& offset)
+{
+ WindowCoord cursor_pos = window.line_and_column_at(cursor);
+ WindowCoord new_pos = cursor_pos + offset;
+
+ return Selection(cursor, window.iterator_at(new_pos));
+}
+
std::unordered_map<char, std::function<void (Window& window, int count)>> keymap =
{
- { 'h', [](Window& window, int count) { if (count == 0) count = 1; window.move_cursor(WindowCoord(0, -count)); window.empty_selections(); } },
- { 'j', [](Window& window, int count) { if (count == 0) count = 1; window.move_cursor(WindowCoord(count, 0)); window.empty_selections(); } },
- { 'k', [](Window& window, int count) { if (count == 0) count = 1; window.move_cursor(WindowCoord(-count, 0)); window.empty_selections(); } },
- { 'l', [](Window& window, int count) { if (count == 0) count = 1; window.move_cursor(WindowCoord(0, count)); window.empty_selections(); } },
+ { 'h', [](Window& window, int count) { window.move_cursor(WindowCoord(0, -std::max(count,1))); window.empty_selections(); } },
+ { 'j', [](Window& window, int count) { window.move_cursor(WindowCoord( std::max(count,1), 0)); window.empty_selections(); } },
+ { 'k', [](Window& window, int count) { window.move_cursor(WindowCoord(-std::max(count,1), 0)); window.empty_selections(); } },
+ { 'l', [](Window& window, int count) { window.move_cursor(WindowCoord(0, std::max(count,1))); window.empty_selections(); } },
+
+ { 'H', [](Window& window, int count) { window.select(true, std::bind(move_select, std::ref(window), std::placeholders::_1,
+ WindowCoord(0, -std::max(count,1)))); } },
+ { 'J', [](Window& window, int count) { window.select(true, std::bind(move_select, std::ref(window), std::placeholders::_1,
+ WindowCoord( std::max(count,1), 0))); } },
+ { 'K', [](Window& window, int count) { window.select(true, std::bind(move_select, std::ref(window), std::placeholders::_1,
+ WindowCoord(-std::max(count,1), 0))); } },
+ { 'L', [](Window& window, int count) { window.select(true, std::bind(move_select, std::ref(window), std::placeholders::_1,
+ WindowCoord(0, std::max(count,1)))); } },
+
{ 'd', [](Window& window, int count) { window.erase(); window.empty_selections(); } },
{ 'c', [](Window& window, int count) { window.erase(); do_insert(window); } },
{ 'i', [](Window& window, int count) { do_insert(window); } },
diff --git a/src/window.cc b/src/window.cc
index 926258b9..feb379d8 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -137,9 +137,7 @@ void Window::select(bool append, const Selector& selector)
void Window::move_cursor(const WindowCoord& offset)
{
- BufferCoord target_position =
- window_to_buffer(WindowCoord(m_cursor.line + offset.line,
- m_cursor.column + offset.column));
+ BufferCoord target_position = window_to_buffer(m_cursor + offset);
m_cursor = buffer_to_window(m_buffer.clamp(target_position));