mirror of
https://github.com/c3d/DB48X-on-DM42.git
synced 2024-09-28 03:20:53 +02:00
catalog: Display commands that begin with selection first
When selecting `FORE` in the catalog, show `Foreground` first, before all other commands that contain `Foreground` (there are many settings with that name). Fixes: #1106 Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
parent
d7547676d8
commit
de78d5f572
2 changed files with 30 additions and 17 deletions
|
@ -165,18 +165,19 @@ static void initialize_sorted_ids()
|
||||||
#endif // DEOPTIMIZE_CATALOG
|
#endif // DEOPTIMIZE_CATALOG
|
||||||
|
|
||||||
|
|
||||||
static bool matches(utf8 start, size_t size, utf8 name)
|
static uint matches(utf8 start, size_t size, utf8 name)
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Check if what was typed matches the name
|
// Check if what was typed matches the name
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
size_t len = strlen(cstring(name));
|
size_t len = strlen(cstring(name));
|
||||||
bool found = false;
|
uint found = 0;
|
||||||
for (uint o = 0; !found && o + size <= len; o++)
|
for (uint o = 0; !found && o + size <= len; o++)
|
||||||
{
|
{
|
||||||
found = true;
|
found = o+1;
|
||||||
for (uint i = 0; found && i < size; i++)
|
for (uint i = 0; found && i < size; i++)
|
||||||
found = tolower(start[i]) == tolower(name[i + o]);
|
if (tolower(start[i]) != tolower(name[i + o]))
|
||||||
|
found = 0;
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@ -220,6 +221,8 @@ void Catalog::list_commands(info &mi)
|
||||||
initialize_sorted_ids();
|
initialize_sorted_ids();
|
||||||
|
|
||||||
if (sorted_ids)
|
if (sorted_ids)
|
||||||
|
{
|
||||||
|
for (uint pass = 0; pass < uint(filter) + 1; pass++)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < sorted_ids_count; i++)
|
for (size_t i = 0; i < sorted_ids_count; i++)
|
||||||
{
|
{
|
||||||
|
@ -227,10 +230,20 @@ void Catalog::list_commands(info &mi)
|
||||||
auto &s = object::spellings[j];
|
auto &s = object::spellings[j];
|
||||||
id ty = s.type;
|
id ty = s.type;
|
||||||
if (cstring name = s.name)
|
if (cstring name = s.name)
|
||||||
if (!filter || matches(start, size, utf8(name)))
|
{
|
||||||
|
uint ok = !filter;
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
ok = matches(start, size, utf8(name));
|
||||||
|
if (ok)
|
||||||
|
ok = pass ? ok != 1 : ok == 1;
|
||||||
|
}
|
||||||
|
if (ok)
|
||||||
menu::items(mi, name, command::static_object(ty));
|
menu::items(mi, name, command::static_object(ty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Fallback if we did not have enough memory for sorted_ids
|
// Fallback if we did not have enough memory for sorted_ids
|
||||||
|
|
12
src/tests.cc
12
src/tests.cc
|
@ -6135,15 +6135,15 @@ void tests::catalog_test()
|
||||||
.test(CLEAR, RSHIFT, RUNSTOP).editor("{}")
|
.test(CLEAR, RSHIFT, RUNSTOP).editor("{}")
|
||||||
.test(ALPHA, A).editor("{A}")
|
.test(ALPHA, A).editor("{A}")
|
||||||
.test(ADD).editor("{A}")
|
.test(ADD).editor("{A}")
|
||||||
.test(F1).editor("{ %Change }");
|
.test(F1).editor("{ abs }");
|
||||||
step("Finding functions from inside")
|
step("Finding functions from inside")
|
||||||
.test(B).editor("{ %Change B}")
|
.test(B).editor("{ abs B}")
|
||||||
.test(F1).editor("{ %Change abs }");
|
.test(F1).editor("{ abs Background }");
|
||||||
step("Finding functions with middle characters")
|
step("Finding functions with middle characters")
|
||||||
.test(B, U).editor("{ %Change abs BU}")
|
.test(B, U).editor("{ abs Background BU}")
|
||||||
.test(F1).editor("{ %Change abs Debug }");
|
.test(F1).editor("{ abs Background Debug }");
|
||||||
step("Catalog with nothing entered")
|
step("Catalog with nothing entered")
|
||||||
.test(F6, F3).editor("{ %Change abs Debug cosh⁻¹ }");
|
.test(F6, F3).editor("{ abs Background Debug cosh⁻¹ }");
|
||||||
|
|
||||||
step("Test the default menu")
|
step("Test the default menu")
|
||||||
.test(CLEAR, EXIT, A, RSHIFT, RUNSTOP).editor("{}")
|
.test(CLEAR, EXIT, A, RSHIFT, RUNSTOP).editor("{}")
|
||||||
|
|
Loading…
Reference in a new issue