Skip to content

Commit

Permalink
PayeeBox and CategoryBox: use offset and byte length
Browse files Browse the repository at this point in the history
when interaction with a BTextView
fix #121
  • Loading branch information
korli committed Oct 28, 2024
1 parent 9799d8c commit 4cebe29
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/CategoryBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ CategoryBoxFilter::KeyFilter(const int32& key, const int32& mod)
TextControl()->TextView()->Delete(start, end);
BString string = "";
GetCurrentMessage()->FindString("bytes", &string);
int32 charLength = string.Length();

string.Prepend(TextControl()->Text());

Expand All @@ -69,7 +70,7 @@ CategoryBoxFilter::KeyFilter(const int32& key, const int32& mod)
autocomplete = string;

BMessage automsg(M_CATEGORY_AUTOCOMPLETE);
automsg.AddInt32("start", strlen(TextControl()->Text()) + 1);
automsg.AddInt32("start", strlen(TextControl()->Text()) + charLength);
automsg.AddString("string", autocomplete.String());
SendMessage(&automsg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/CheckView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ CheckView::MessageReceived(BMessage* msg)
msg->FindInt32("start", &start);
msg->FindString("string", &string);
fPayee->SetText(string.String());
fPayee->TextView()->Select(start, string.CountChars());
fPayee->TextView()->Select(start, string.Length());
break;
}
case M_CATEGORY_AUTOCOMPLETE:
{
msg->FindInt32("start", &start);
msg->FindString("string", &string);
fCategory->SetText(string.String());
fCategory->TextView()->Select(start, string.CountChars() + 2);
fCategory->TextView()->Select(start, string.Length());
break;
}

Expand Down
3 changes: 2 additions & 1 deletion src/PayeeBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ PayeeBoxFilter::KeyFilter(const int32& key, const int32& mod)
TextControl()->TextView()->Delete(start, end);
BString string = "";
GetCurrentMessage()->FindString("bytes", &string);
int32 charLength = string.Length();

string.Prepend(TextControl()->Text());

Expand All @@ -72,7 +73,7 @@ PayeeBoxFilter::KeyFilter(const int32& key, const int32& mod)
autocomplete = string;

BMessage automsg(M_PAYEE_AUTOCOMPLETE);
automsg.AddInt32("start", strlen(TextControl()->Text()) + 1);
automsg.AddInt32("start", strlen(TextControl()->Text()) + charLength);
automsg.AddString("string", autocomplete.String());
SendMessage(&automsg);
}
Expand Down
6 changes: 3 additions & 3 deletions src/SplitView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ SplitView::MessageReceived(BMessage* msg)
msg->FindInt32("start", &start);
msg->FindString("string", &string);
fPayee->SetText(string.String());
fPayee->TextView()->Select(start, string.CountChars());
fPayee->TextView()->Select(start, string.Length());
break;
}
case M_CATEGORY_AUTOCOMPLETE:
Expand All @@ -317,10 +317,10 @@ SplitView::MessageReceived(BMessage* msg)
msg->FindString("string", &string);
if (fSplitContainer->IsHidden()) {
fCategory->SetText(string.String());
fCategory->TextView()->Select(start, string.CountChars());
fCategory->TextView()->Select(start, string.Length());
} else {
fSplitCategory->SetText(string.String());
fSplitCategory->TextView()->Select(start, string.CountChars());
fSplitCategory->TextView()->Select(start, string.Length());
}
break;
}
Expand Down

0 comments on commit 4cebe29

Please sign in to comment.