Support user given text objects
This commit is contained in:
parent
b7530b021a
commit
f3ec218a1c
|
@ -517,6 +517,8 @@ object you want.
|
||||||
* `␣`: select the whitespaces
|
* `␣`: select the whitespaces
|
||||||
* `i`: select the current indentation block
|
* `i`: select the current indentation block
|
||||||
* `n`: select the number
|
* `n`: select the number
|
||||||
|
* `:`: select user defined object, will prompt
|
||||||
|
for open and close text.
|
||||||
|
|
||||||
For nestable objects, a count can be used in order to specify which surrounding
|
For nestable objects, a count can be used in order to specify which surrounding
|
||||||
level to select.
|
level to select.
|
||||||
|
|
|
@ -935,8 +935,28 @@ void select_object(Context& context, NormalParams params)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*cp == 'u')
|
if (*cp == 'u')
|
||||||
{
|
|
||||||
return select<mode>(context, std::bind(select_argument, _1, _2, level, flags));
|
return select<mode>(context, std::bind(select_argument, _1, _2, level, flags));
|
||||||
|
|
||||||
|
if (*cp == ':')
|
||||||
|
{
|
||||||
|
context.input_handler().prompt(
|
||||||
|
"opening:", "", get_face("Prompt"), complete_nothing,
|
||||||
|
[level](StringView cmdline, PromptEvent event, Context& context) {
|
||||||
|
if (event != PromptEvent::Validate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String opening = cmdline.str();
|
||||||
|
context.input_handler().prompt(
|
||||||
|
"closing:", "", get_face("Prompt"), complete_nothing,
|
||||||
|
[level, opening](StringView cmdline, PromptEvent event, Context& context) {
|
||||||
|
if (event != PromptEvent::Validate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String closing = cmdline.str();
|
||||||
|
return select<mode>(context, std::bind(select_surrounding, _1, _2,
|
||||||
|
opening, closing, level, flags));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr struct
|
static constexpr struct
|
||||||
|
@ -977,7 +997,8 @@ void select_object(Context& context, NormalParams params)
|
||||||
"␣: whitespaces \n"
|
"␣: whitespaces \n"
|
||||||
"i: indent \n"
|
"i: indent \n"
|
||||||
"u: argument \n"
|
"u: argument \n"
|
||||||
"n: number \n");
|
"n: number \n"
|
||||||
|
":: prompt for object \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Key::NamedKey key>
|
template<Key::NamedKey key>
|
||||||
|
|
|
@ -728,6 +728,12 @@ UnitTest test_find_surrounding{[]()
|
||||||
auto res = find_surrounding(s, s.begin() + 6, '[', ']', ObjectFlags::ToBegin, 0);
|
auto res = find_surrounding(s, s.begin() + 6, '[', ']', ObjectFlags::ToBegin, 0);
|
||||||
kak_assert(not res);
|
kak_assert(not res);
|
||||||
}
|
}
|
||||||
|
s = "begin tchou begin tchaa end end";
|
||||||
|
{
|
||||||
|
auto res = find_surrounding(s, s.begin() + 6, "begin", "end",
|
||||||
|
ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0);
|
||||||
|
kak_assert(res and StringView{res->first COMMA res->second+1} == s);
|
||||||
|
}
|
||||||
}};
|
}};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user