diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-03-26 13:13:05 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-03-26 13:34:21 +0000 |
| commit | 757366472b7c70e54e0e145b286ea01090ee5dbc (patch) | |
| tree | 31ced2c37ff1dd630313e7a4ee92ce6ad11b580b /src | |
| parent | 9f5b064a87bc72eaa5f6534ed946a679321ffcbf (diff) | |
Add <alt-:> for ensuring selections are forward (cursor >= anchor)
Not very useful interactively, but that feature can make macros much
more robust.
Diffstat (limited to 'src')
| -rw-r--r-- | src/normal.cc | 6 | ||||
| -rw-r--r-- | src/selectors.hh | 13 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/normal.cc b/src/normal.cc index 1d4d1cba..eec19752 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1373,6 +1373,11 @@ void flip_selections(Context& context, NormalParams) flip_selections(context.selections()); } +void ensure_forward(Context& context, NormalParams) +{ + ensure_forward(context.selections()); +} + static NormalCmdDesc cmds[] = { { 'h', "move left", move<CharCount, Backward> }, @@ -1434,6 +1439,7 @@ static NormalCmdDesc cmds[] = { alt(' '), "remove main selection", remove_selection }, { ';', "reduce selections to their cursor", clear_selections }, { alt(';'), "swap selections cursor and anchor", flip_selections }, + { alt(':'), "ensure selection cursor is after anchor", ensure_forward }, { 'w', "select to next word start", repeated<&select<SelectMode::Replace, select_to_next_word<Word>>> }, { 'e', "select to next word end", repeated<select<SelectMode::Replace, select_to_next_word_end<Word>>> }, diff --git a/src/selectors.hh b/src/selectors.hh index cdd89dcb..e03c479c 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -28,13 +28,24 @@ inline void flip_selections(SelectionList& selections) { for (auto& sel : selections) { - ByteCoord tmp = sel.anchor(); + const ByteCoord tmp = sel.anchor(); sel.anchor() = sel.cursor(); sel.cursor() = tmp; } selections.check_invariant(); } +inline void ensure_forward(SelectionList& selections) +{ + for (auto& sel : selections) + { + const ByteCoord min = sel.min(), max = sel.max(); + sel.anchor() = min; + sel.cursor() = max; + } + selections.check_invariant(); +} + inline void keep_selection(SelectionList& selections, int index) { if (index < selections.size()) |
