Add -lock switch to enter-user-mode command
This commit is contained in:
parent
0d838f80a0
commit
a6a1c34288
|
@ -135,6 +135,9 @@ command *q!* has to be used). Aliases are mentionned below each commands.
|
|||
*enter-user-mode* <scope> <name>::
|
||||
enable <name> keymap mode for next key
|
||||
|
||||
*-lock*:::
|
||||
stay in mode until `<esc>` is pressed
|
||||
|
||||
== Hooks
|
||||
|
||||
*hook* [-group <group>] <scope> <hook_name> <filtering_regex> <command>::
|
||||
|
|
|
@ -2135,11 +2135,38 @@ const CommandDesc declare_user_mode_cmd = {
|
|||
}
|
||||
};
|
||||
|
||||
void enter_user_mode(Context& context, const String mode_name, KeymapMode mode, bool lock)
|
||||
{
|
||||
on_next_key_with_autoinfo(context, KeymapMode::None,
|
||||
[mode_name, mode, lock](Key key, Context& context) mutable {
|
||||
if (key == Key::Escape)
|
||||
return;
|
||||
if (not context.keymaps().is_mapped(key, mode))
|
||||
return;
|
||||
|
||||
auto& mapping = context.keymaps().get_mapping(key, mode);
|
||||
ScopedSetBool disable_keymaps(context.keymaps_disabled());
|
||||
|
||||
InputHandler::ScopedForceNormal force_normal{context.input_handler(), {}};
|
||||
|
||||
ScopedEdition edition(context);
|
||||
for (auto& key : mapping.keys)
|
||||
context.input_handler().handle_key(key);
|
||||
|
||||
if (lock)
|
||||
enter_user_mode(context, std::move(mode_name), mode, true);
|
||||
}, lock ? format("{} (lock)", mode_name) : mode_name,
|
||||
build_autoinfo_for_mapping(context, mode, {}));
|
||||
}
|
||||
|
||||
const CommandDesc enter_user_mode_cmd = {
|
||||
"enter-user-mode",
|
||||
nullptr,
|
||||
"enter-user-mode <scope> <name>: enable <name> keymap mode for next key",
|
||||
ParameterDesc{ {}, ParameterDesc::Flags::None, 2, 2 },
|
||||
"enter-user-mode <switches> <scope> <name>: enable <name> keymap mode for next key",
|
||||
ParameterDesc{
|
||||
{ { "lock", { false, "stay in mode until <esc> is pressed" } } },
|
||||
ParameterDesc::Flags::SwitchesOnlyAtStart, 2, 2
|
||||
},
|
||||
CommandFlags::None,
|
||||
CommandHelper{},
|
||||
[](const Context& context, CompletionFlags flags,
|
||||
|
@ -2159,22 +2186,11 @@ const CommandDesc enter_user_mode_cmd = {
|
|||
},
|
||||
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
||||
{
|
||||
auto lock = (bool)parser.get_switch("lock");
|
||||
KeymapManager& keymaps = get_scope(parser[0], context).keymaps();
|
||||
KeymapMode mode = parse_keymap_mode(parser[1], keymaps.user_modes());
|
||||
on_next_key_with_autoinfo(context, KeymapMode::None,
|
||||
[mode](Key key, Context& context) mutable {
|
||||
if (not context.keymaps().is_mapped(key, mode))
|
||||
return;
|
||||
|
||||
auto& mapping = context.keymaps().get_mapping(key, mode);
|
||||
ScopedSetBool disable_keymaps(context.keymaps_disabled());
|
||||
|
||||
InputHandler::ScopedForceNormal force_normal{context.input_handler(), {}};
|
||||
|
||||
ScopedEdition edition(context);
|
||||
for (auto& key : mapping.keys)
|
||||
context.input_handler().handle_key(key);
|
||||
}, parser[1], build_autoinfo_for_mapping(context, mode, {}));
|
||||
enter_user_mode(context, std::move(parser[1]), mode, lock);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
:declare-user-mode global foo<ret>
|
||||
:map global foo f '<esc>wchello from foo<esc>'
|
||||
:enter-user-mode global foo
|
||||
f
|
1
test/normal/user-modes/lock/cmd
Normal file
1
test/normal/user-modes/lock/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-,>fff<esc>f
|
1
test/normal/user-modes/lock/in
Normal file
1
test/normal/user-modes/lock/in
Normal file
|
@ -0,0 +1 @@
|
|||
123delete
|
1
test/normal/user-modes/lock/out
Normal file
1
test/normal/user-modes/lock/out
Normal file
|
@ -0,0 +1 @@
|
|||
delete
|
3
test/normal/user-modes/lock/rc
Normal file
3
test/normal/user-modes/lock/rc
Normal file
|
@ -0,0 +1,3 @@
|
|||
declare-user-mode global foo
|
||||
map global foo f d
|
||||
map global normal <a-,> ':enter-user-mode -lock global foo<ret>'
|
1
test/normal/user-modes/once/cmd
Normal file
1
test/normal/user-modes/once/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-,>ff
|
3
test/normal/user-modes/once/rc
Normal file
3
test/normal/user-modes/once/rc
Normal file
|
@ -0,0 +1,3 @@
|
|||
declare-user-mode global foo
|
||||
map global foo f 'wchello from foo<esc>'
|
||||
map global normal <a-,> ':enter-user-mode global foo<ret>'
|
Loading…
Reference in New Issue
Block a user