From 4cebe29992e6c36cb95a67ff6d54a6ecd74b1df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Mon, 28 Oct 2024 19:25:54 +0100 Subject: [PATCH] PayeeBox and CategoryBox: use offset and byte length when interaction with a BTextView fix #121 --- src/CategoryBox.cpp | 3 ++- src/CheckView.cpp | 4 ++-- src/PayeeBox.cpp | 3 ++- src/SplitView.cpp | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/CategoryBox.cpp b/src/CategoryBox.cpp index 8b6fd46..b40516f 100644 --- a/src/CategoryBox.cpp +++ b/src/CategoryBox.cpp @@ -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()); @@ -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); } diff --git a/src/CheckView.cpp b/src/CheckView.cpp index 8fc6873..d1b019a 100644 --- a/src/CheckView.cpp +++ b/src/CheckView.cpp @@ -162,7 +162,7 @@ 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: @@ -170,7 +170,7 @@ CheckView::MessageReceived(BMessage* msg) 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; } diff --git a/src/PayeeBox.cpp b/src/PayeeBox.cpp index 5afeb39..8ef41c9 100644 --- a/src/PayeeBox.cpp +++ b/src/PayeeBox.cpp @@ -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()); @@ -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); } diff --git a/src/SplitView.cpp b/src/SplitView.cpp index 18ca472..4e865fb 100644 --- a/src/SplitView.cpp +++ b/src/SplitView.cpp @@ -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: @@ -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; }