Skip to content

Commit

Permalink
Fix auto-complete for Payee and Category
Browse files Browse the repository at this point in the history
If the user enters a letter that has the Autocomplete*() function
return empty, because the string doesn't match anymore, send the
M_*_AUTOCOMPLETE BMessage with the entire text control text. Including
that non-matching letter.

Fixes #85
  • Loading branch information
humdingerb committed Aug 17, 2024
1 parent 35d73b3 commit 275730a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 8 additions & 9 deletions src/CategoryBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,19 @@ CategoryBoxFilter::KeyFilter(const int32& key, const int32& mod)
TextControl()->TextView()->GetSelection(&start, &end);
if (end == (int32)strlen(TextControl()->Text())) {
TextControl()->TextView()->Delete(start, end);
BString string = "";
GetCurrentMessage()->FindString("bytes", &string);

BString string;
if (GetCurrentMessage()->FindString("bytes", &string) != B_OK)
string = "";
string.Prepend(TextControl()->Text());

BString autocomplete = acc->AutocompleteCategory(string.String());
if (autocomplete.CountChars() == 0 || IsInternalCategory(autocomplete.String()))
autocomplete = string;

if (autocomplete.CountChars() > 0 && !IsInternalCategory(autocomplete.String())) {
BMessage automsg(M_CATEGORY_AUTOCOMPLETE);
automsg.AddInt32("start", strlen(TextControl()->Text()) + 1);
automsg.AddString("string", autocomplete.String());
SendMessage(&automsg);
}
BMessage automsg(M_CATEGORY_AUTOCOMPLETE);
automsg.AddInt32("start", strlen(TextControl()->Text()) + 1);
automsg.AddString("string", autocomplete.String());
SendMessage(&automsg);
}

return B_DISPATCH_MESSAGE;
Expand Down
17 changes: 8 additions & 9 deletions src/PayeeBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,19 @@ PayeeBoxFilter::KeyFilter(const int32& key, const int32& mod)
TextControl()->TextView()->GetSelection(&start, &end);
if (end == (int32)strlen(TextControl()->Text())) {
TextControl()->TextView()->Delete(start, end);
BString string = "";
GetCurrentMessage()->FindString("bytes", &string);

BString string;
if (GetCurrentMessage()->FindString("bytes", &string) != B_OK)
string = "";
string.Prepend(TextControl()->Text());

BString autocomplete = acc->AutocompletePayee(string.String());
if (autocomplete.CountChars() == 0)
autocomplete = string;

if (autocomplete.CountChars() > 0) {
BMessage automsg(M_PAYEE_AUTOCOMPLETE);
automsg.AddInt32("start", strlen(TextControl()->Text()) + 1);
automsg.AddString("string", autocomplete.String());
SendMessage(&automsg);
}
BMessage automsg(M_PAYEE_AUTOCOMPLETE);
automsg.AddInt32("start", strlen(TextControl()->Text()) + 1);
automsg.AddString("string", autocomplete.String());
SendMessage(&automsg);
}

return B_DISPATCH_MESSAGE;
Expand Down

0 comments on commit 275730a

Please sign in to comment.