info command take a -anchor <pos> instead of -inline params

This commit is contained in:
Maxime Coste 2013-01-29 18:56:14 +01:00
parent f8209e3b52
commit 84ea452ed2
2 changed files with 20 additions and 10 deletions

View File

@ -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 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 case menu takes three argument per item, the last one being a command
to execute when the item is selected (but not validated). to execute when the item is selected (but not validated).
* +info <text>+: display text in an information box, when the option inline * +info <text>+: display text in an information box, at can take a -anchor
is given, place the info box next to last selection end. 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> * +try <commands> catch <on_error_commands>+: prevent an error in <commands>
from aborting the whole commands execution, execute <on_error_commands> from aborting the whole commands execution, execute <on_error_commands>
instead. instead.

View File

@ -623,7 +623,7 @@ void menu(const CommandParameters& params, Context& context)
void info(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) if (parser.positional_count() > 1)
throw wrong_argument_count(); throw wrong_argument_count();
@ -631,13 +631,22 @@ void info(const CommandParameters& params, Context& context)
context.ui().info_hide(); context.ui().info_hide();
if (parser.positional_count() > 0) if (parser.positional_count() > 0)
{ {
MenuStyle style = parser.has_option("inline") ? MenuStyle style = MenuStyle::Prompt;
MenuStyle::Inline : MenuStyle::Prompt; DisplayCoord pos = { context.ui().dimensions().line, 0 };
DisplayCoord pos; if (parser.has_option("anchor"))
if (style == MenuStyle::Inline) {
pos = context.window().display_position(context.editor().selections().back().last()); style = MenuStyle::Inline;
else const auto& sel = context.editor().selections().back();
pos.line = context.ui().dimensions().line; 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); context.ui().info_show(parser[0], pos, style);
} }
} }