From d00fc0e3e6caf2d5e17701410bfbd14bd70855c9 Mon Sep 17 00:00:00 2001 From: X512 Date: Thu, 8 Apr 2021 01:31:22 +0900 Subject: [PATCH] BTextView: fix Text field scripting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2048d7f01fa3694d5687447cf7058fecf03ae15d Reviewed-on: https://review.haiku-os.org/c/haiku/+/4007 Reviewed-by: X512 Reviewed-by: John Scipione Reviewed-by: Jérôme Duval --- headers/os/interface/TextView.h | 10 ++++++---- src/kits/interface/TextView.cpp | 25 ++++++++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/headers/os/interface/TextView.h b/headers/os/interface/TextView.h index 268103a7a9..3757bb1862 100644 --- a/headers/os/interface/TextView.h +++ b/headers/os/interface/TextView.h @@ -390,12 +390,14 @@ private: int32 _PreviousWordStart(int32 offset); int32 _NextWordEnd(int32 offset); - bool _GetProperty(BMessage* specifier, int32 form, + bool _GetProperty(BMessage* message, + BMessage* specifier, const char* property, BMessage* reply); - bool _SetProperty(BMessage* specifier, int32 form, + bool _SetProperty(BMessage* message, + BMessage* specifier, const char* property, BMessage* reply); - bool _CountProperties(BMessage* specifier, - int32 form, const char* property, + bool _CountProperties(BMessage* message, + BMessage* specifier, const char* property, BMessage* reply); void _HandleInputMethodChanged(BMessage* message); diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index d390c8fd52..695688c411 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -979,17 +979,17 @@ BTextView::MessageReceived(BMessage* message) bool handled = false; switch(message->what) { case B_GET_PROPERTY: - handled = _GetProperty(&specifier, specifier.what, property, + handled = _GetProperty(message, &specifier, property, &reply); break; case B_SET_PROPERTY: - handled = _SetProperty(&specifier, specifier.what, property, + handled = _SetProperty(message, &specifier, property, &reply); break; case B_COUNT_PROPERTIES: - handled = _CountProperties(&specifier, specifier.what, + handled = _CountProperties(message, &specifier, property, &reply); break; @@ -5525,8 +5525,8 @@ BTextView::_PreviousInitialByte(int32 offset) const bool -BTextView::_GetProperty(BMessage* specifier, int32 form, const char* property, - BMessage* reply) +BTextView::_GetProperty(BMessage* message, BMessage* specifier, + const char* property, BMessage* reply) { CALLED(); if (strcmp(property, "selection") == 0) { @@ -5565,8 +5565,8 @@ BTextView::_GetProperty(BMessage* specifier, int32 form, const char* property, bool -BTextView::_SetProperty(BMessage* specifier, int32 form, const char* property, - BMessage* reply) +BTextView::_SetProperty(BMessage* message, BMessage* specifier, + const char* property, BMessage* reply) { CALLED(); if (strcmp(property, "selection") == 0) { @@ -5587,10 +5587,13 @@ BTextView::_SetProperty(BMessage* specifier, int32 form, const char* property, specifier->FindInt32("range", &range); const char* buffer = NULL; - if (specifier->FindString("data", &buffer) == B_OK) + if (message->FindString("data", &buffer) == B_OK) { InsertText(buffer, range, index, NULL); - else - DeleteText(index, range); + _Refresh(index, index + range); + } else { + DeleteText(index, index + range); + _Refresh(index, index); + } reply->what = B_REPLY; reply->AddInt32("error", B_OK); @@ -5604,7 +5607,7 @@ BTextView::_SetProperty(BMessage* specifier, int32 form, const char* property, bool -BTextView::_CountProperties(BMessage* specifier, int32 form, +BTextView::_CountProperties(BMessage* message, BMessage* specifier, const char* property, BMessage* reply) { CALLED();