info command take a -anchor <pos> instead of -inline params
This commit is contained in:
parent
f8209e3b52
commit
84ea452ed2
|
@ -401,8 +401,9 @@ Some helper commands can be used to define composite commands:
|
|||
when only one choice is provided. and a -select-cmds argument, in which
|
||||
case menu takes three argument per item, the last one being a command
|
||||
to execute when the item is selected (but not validated).
|
||||
* +info <text>+: display text in an information box, when the option inline
|
||||
is given, place the info box next to last selection end.
|
||||
* +info <text>+: display text in an information box, at can take a -anchor
|
||||
option, which accepts +left+, +right+ and +cursor+ as value, in order to
|
||||
specify where the info box should be anchored relative to the last selection.
|
||||
* +try <commands> catch <on_error_commands>+: prevent an error in <commands>
|
||||
from aborting the whole commands execution, execute <on_error_commands>
|
||||
instead.
|
||||
|
|
|
@ -623,7 +623,7 @@ void menu(const CommandParameters& params, Context& context)
|
|||
|
||||
void info(const CommandParameters& params, Context& context)
|
||||
{
|
||||
ParametersParser parser(params, { { "inline", false } });
|
||||
ParametersParser parser(params, { { "anchor", true } });
|
||||
|
||||
if (parser.positional_count() > 1)
|
||||
throw wrong_argument_count();
|
||||
|
@ -631,13 +631,22 @@ void info(const CommandParameters& params, Context& context)
|
|||
context.ui().info_hide();
|
||||
if (parser.positional_count() > 0)
|
||||
{
|
||||
MenuStyle style = parser.has_option("inline") ?
|
||||
MenuStyle::Inline : MenuStyle::Prompt;
|
||||
DisplayCoord pos;
|
||||
if (style == MenuStyle::Inline)
|
||||
pos = context.window().display_position(context.editor().selections().back().last());
|
||||
else
|
||||
pos.line = context.ui().dimensions().line;
|
||||
MenuStyle style = MenuStyle::Prompt;
|
||||
DisplayCoord pos = { context.ui().dimensions().line, 0 };
|
||||
if (parser.has_option("anchor"))
|
||||
{
|
||||
style = MenuStyle::Inline;
|
||||
const auto& sel = context.editor().selections().back();
|
||||
auto it = sel.last();
|
||||
String anchor = parser.option_value("anchor");
|
||||
if (anchor == "left")
|
||||
it = sel.begin();
|
||||
else if (anchor == "right")
|
||||
it = sel.end() - 1;
|
||||
else if (anchor != "cursor")
|
||||
throw runtime_error("anchor param must be one of [left, right, cursor]");
|
||||
pos = context.window().display_position(it);
|
||||
}
|
||||
context.ui().info_show(parser[0], pos, style);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user