Add <alt-:> for ensuring selections are forward (cursor >= anchor)

Not very useful interactively, but that feature can make macros much
more robust.
This commit is contained in:
Maxime Coste 2015-03-26 13:13:05 +00:00
parent 9f5b064a87
commit 757366472b
3 changed files with 19 additions and 1 deletions

View File

@ -195,6 +195,7 @@ Basic Movement
* +;+: reduce selections to their cursor * +;+: reduce selections to their cursor
* +alt-;+: flip the selections direction * +alt-;+: flip the selections direction
* +alt-:+: ensure selections are in forward direction (cursor after anchor)
A word is a sequence of alphanumeric characters or underscore, a WORD is a A word is a sequence of alphanumeric characters or underscore, a WORD is a

View File

@ -1373,6 +1373,11 @@ void flip_selections(Context& context, NormalParams)
flip_selections(context.selections()); flip_selections(context.selections());
} }
void ensure_forward(Context& context, NormalParams)
{
ensure_forward(context.selections());
}
static NormalCmdDesc cmds[] = static NormalCmdDesc cmds[] =
{ {
{ 'h', "move left", move<CharCount, Backward> }, { 'h', "move left", move<CharCount, Backward> },
@ -1434,6 +1439,7 @@ static NormalCmdDesc cmds[] =
{ alt(' '), "remove main selection", remove_selection }, { alt(' '), "remove main selection", remove_selection },
{ ';', "reduce selections to their cursor", clear_selections }, { ';', "reduce selections to their cursor", clear_selections },
{ alt(';'), "swap selections cursor and anchor", flip_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>>> }, { '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>>> }, { 'e', "select to next word end", repeated<select<SelectMode::Replace, select_to_next_word_end<Word>>> },

View File

@ -28,13 +28,24 @@ inline void flip_selections(SelectionList& selections)
{ {
for (auto& sel : selections) for (auto& sel : selections)
{ {
ByteCoord tmp = sel.anchor(); const ByteCoord tmp = sel.anchor();
sel.anchor() = sel.cursor(); sel.anchor() = sel.cursor();
sel.cursor() = tmp; sel.cursor() = tmp;
} }
selections.check_invariant(); 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) inline void keep_selection(SelectionList& selections, int index)
{ {
if (index < selections.size()) if (index < selections.size())