Merge remote-tracking branch 'Delapouite/user-mode-lock'
This commit is contained in:
commit
7dfd439263
|
@ -135,6 +135,9 @@ command *q!* has to be used). Aliases are mentionned below each commands.
|
||||||
*enter-user-mode* <scope> <name>::
|
*enter-user-mode* <scope> <name>::
|
||||||
enable <name> keymap mode for next key
|
enable <name> keymap mode for next key
|
||||||
|
|
||||||
|
*-lock*:::
|
||||||
|
stay in mode until `<esc>` is pressed
|
||||||
|
|
||||||
== Hooks
|
== Hooks
|
||||||
|
|
||||||
*hook* [-group <group>] <scope> <hook_name> <filtering_regex> <command>::
|
*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 = {
|
const CommandDesc enter_user_mode_cmd = {
|
||||||
"enter-user-mode",
|
"enter-user-mode",
|
||||||
nullptr,
|
nullptr,
|
||||||
"enter-user-mode <scope> <name>: enable <name> keymap mode for next key",
|
"enter-user-mode <switches> <scope> <name>: enable <name> keymap mode for next key",
|
||||||
ParameterDesc{ {}, ParameterDesc::Flags::None, 2, 2 },
|
ParameterDesc{
|
||||||
|
{ { "lock", { false, "stay in mode until <esc> is pressed" } } },
|
||||||
|
ParameterDesc::Flags::SwitchesOnlyAtStart, 2, 2
|
||||||
|
},
|
||||||
CommandFlags::None,
|
CommandFlags::None,
|
||||||
CommandHelper{},
|
CommandHelper{},
|
||||||
[](const Context& context, CompletionFlags flags,
|
[](const Context& context, CompletionFlags flags,
|
||||||
|
@ -2159,22 +2186,11 @@ const CommandDesc enter_user_mode_cmd = {
|
||||||
},
|
},
|
||||||
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
||||||
{
|
{
|
||||||
|
auto lock = (bool)parser.get_switch("lock");
|
||||||
KeymapManager& keymaps = get_scope(parser[0], context).keymaps();
|
KeymapManager& keymaps = get_scope(parser[0], context).keymaps();
|
||||||
KeymapMode mode = parse_keymap_mode(parser[1], keymaps.user_modes());
|
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);
|
enter_user_mode(context, std::move(parser[1]), mode, lock);
|
||||||
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, {}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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>'
|
2
test/run
2
test/run
|
@ -19,7 +19,7 @@ main() {
|
||||||
eval -buffer *debug* write debug
|
eval -buffer *debug* write debug
|
||||||
quit!
|
quit!
|
||||||
}
|
}
|
||||||
try %{ exec "%sh{cat cmd}" }
|
try %{ exec -with-maps "%sh{cat cmd}" }
|
||||||
exec <c-l>
|
exec <c-l>
|
||||||
eval -buffer *debug* write debug
|
eval -buffer *debug* write debug
|
||||||
nop %sh{
|
nop %sh{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user