diff --git a/README.asciidoc b/README.asciidoc index 41e14813..3b61cb1a 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -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 +: display text in an information box, when the option inline - is given, place the info box next to last selection end. + * +info +: 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 catch +: prevent an error in from aborting the whole commands execution, execute instead. diff --git a/src/commands.cc b/src/commands.cc index 7805f67f..084b6601 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -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); } }