summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-10-10 14:24:17 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-10-10 14:24:17 +0000
commit7e84ca9ae970b2a3a314946ae4890d3a986f374d (patch)
tree7b78f1e13106407138ec062149022b9d2ebc238d /src
parent003c5d4e3ddd3c841a8fdef437c9810576cdab6f (diff)
gl and gh now go to first or last character of the line
append mode is supported through G key
Diffstat (limited to 'src')
-rw-r--r--src/main.cc39
-rw-r--r--src/selectors.cc14
-rw-r--r--src/selectors.hh2
3 files changed, 39 insertions, 16 deletions
diff --git a/src/main.cc b/src/main.cc
index 37fd8c66..7a22b9af 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -322,11 +322,16 @@ void do_insert(Window& window, IncrementalInserter::Mode mode)
window.clear_selections();
}
+template<bool append>
void do_go(Window& window, int count)
{
- BufferIterator target;
if (count != 0)
- target = window.buffer().iterator_at({count, 0});
+ {
+ BufferIterator target =
+ window.buffer().iterator_at(BufferCoord(count, 0));
+
+ window.move_cursor_to(window.line_and_column_at(target));
+ }
else
{
char c = getch();
@@ -334,28 +339,29 @@ void do_go(Window& window, int count)
{
case 'g':
case 't':
- target = window.buffer().iterator_at({0,0});
+ {
+ BufferIterator target =
+ window.buffer().iterator_at(BufferCoord(0,0));
+ window.move_cursor_to(window.line_and_column_at(target));
break;
+ }
case 'l':
- target = window.iterator_at(window.cursor_position());
- while (not target.is_end() and *target != '\n')
- ++target;
- --target;
+ case 'L':
+ window.select(select_to_eol, append);
break;
case 'h':
- target = window.iterator_at(window.cursor_position());
- while (not target.is_begin() and *target != '\n')
- --target;
- ++target;
+ case 'H':
+ window.select(select_to_eol_reverse, append);
break;
case 'b':
- target = window.buffer().iterator_at(
- {window.buffer().line_count() - 1, 0});
- break;
+ {
+ BufferIterator target = window.buffer().iterator_at(
+ BufferCoord(window.buffer().line_count() - 1, 0));
+ window.move_cursor_to(window.line_and_column_at(target));
break;
}
+ }
}
- window.move_cursor_to(window.line_and_column_at(target));
}
Window* current_window;
@@ -516,7 +522,8 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'o', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineBelow); } },
{ 'O', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineAbove); } },
- { 'g', do_go },
+ { 'g', do_go<false> },
+ { 'G', do_go<true> },
{ 'y', do_yank },
{ 'p', do_paste<true> },
diff --git a/src/selectors.cc b/src/selectors.cc
index c2f8e33b..c4864c74 100644
--- a/src/selectors.cc
+++ b/src/selectors.cc
@@ -223,4 +223,18 @@ Selection select_to_reverse(const BufferIterator& cursor, char c, int count, boo
return Selection(cursor, inclusive ? end : end+1);
}
+Selection select_to_eol(const BufferIterator& cursor)
+{
+ BufferIterator end = cursor + 1;
+ skip_while(end, [](char cur) { return not is_eol(cur); });
+ return Selection(cursor, end-1);
+}
+
+Selection select_to_eol_reverse(const BufferIterator& cursor)
+{
+ BufferIterator end = cursor - 1;
+ skip_while_reverse(end, [](char cur) { return not is_eol(cur); });
+ return Selection(cursor, end.is_begin() ? end : end+1);
+}
+
}
diff --git a/src/selectors.hh b/src/selectors.hh
index a53b30cc..4849ea5c 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -16,6 +16,8 @@ Selection select_matching(const BufferIterator& cursor);
Selection select_to(const BufferIterator& cursor, char c, int count, bool inclusive);
Selection select_to_reverse(const BufferIterator& cursor, char c, int count, bool inclusive);
+Selection select_to_eol(const BufferIterator& cursor);
+Selection select_to_eol_reverse(const BufferIterator& cursor);
}
#endif // selectors_hh_INCLUDED