mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-23 15:23:29 +03:00
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:
parent
9f5b064a87
commit
757366472b
@ -195,6 +195,7 @@ Basic Movement
|
||||
|
||||
* +;+: reduce selections to their cursor
|
||||
* +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
|
||||
|
@ -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>>> },
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user