From fb31776418e0f6c64e8ab8eea916290b7bb40594 Mon Sep 17 00:00:00 2001 From: hw_wyx Date: Mon, 16 Oct 2023 06:51:21 +0000 Subject: [PATCH] richeditorLogFix Signed-off-by: hw_wyx Change-Id: Iac5230f1ca31f07458998d90e16b77d4e6ab886b --- adapter/ohos/osal/log_wrapper.cpp | 1 + frameworks/base/log/log_wrapper.h | 1 + .../jsview/js_richeditor.cpp | 29 ++++---- .../rich_editor/rich_editor_controller.cpp | 2 +- .../rich_editor/rich_editor_model_ng.cpp | 4 +- .../rich_editor/rich_editor_pattern.cpp | 73 +++++++++++-------- .../pattern/rich_editor/rich_editor_theme.h | 2 +- 7 files changed, 61 insertions(+), 51 deletions(-) diff --git a/adapter/ohos/osal/log_wrapper.cpp b/adapter/ohos/osal/log_wrapper.cpp index 25a23a17999..f2012f476d9 100644 --- a/adapter/ohos/osal/log_wrapper.cpp +++ b/adapter/ohos/osal/log_wrapper.cpp @@ -49,6 +49,7 @@ const std::map DOMAIN_CONTENTS_MAP = { { AceLogTag::ACE_VIDEO, "AceVideo" }, { AceLogTag::ACE_FONT, "AceFont" }, { AceLogTag::ACE_TEXTINPUT, "AceTextInput" }, + { AceLogTag::ACE_RICH_EDITOR, "AceRichEditor" }, }; const char* APP_DOMAIN_CONTENT = "JSApp"; diff --git a/frameworks/base/log/log_wrapper.h b/frameworks/base/log/log_wrapper.h index 05533ef03e5..c098ef84ea5 100644 --- a/frameworks/base/log/log_wrapper.h +++ b/frameworks/base/log/log_wrapper.h @@ -80,6 +80,7 @@ enum class AceLogTag : uint8_t { ACE_VIDEO, ACE_FONT, ACE_TEXTINPUT, + ACE_RICH_EDITOR, }; enum class LogDomain : uint32_t { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp b/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp index 9b0372e6bff..4e3a2f945b6 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_richeditor.cpp @@ -143,7 +143,7 @@ void JSRichEditor::Create(const JSCallbackInfo& info) void JSRichEditor::SetOnReady(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { - LOGE("args not function"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "args not function"); return; } JsEventCallback callback(args.GetExecutionContext(), JSRef::Cast(args[0])); @@ -257,7 +257,7 @@ JSRef JSRichEditor::CreateJSSelection(const RichEditorSelection& selectIn void JSRichEditor::SetOnSelect(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { - LOGI("args not function"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "args not function"); return; } auto jsSelectFunc = @@ -272,7 +272,7 @@ void JSRichEditor::SetOnSelect(const JSCallbackInfo& args) void JSRichEditor::SetAboutToIMEInput(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { - LOGE("args not function"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "args not function"); return; } auto jsAboutToIMEInputFunc = AceType::MakeRefPtr>( @@ -292,7 +292,7 @@ void JSRichEditor::SetAboutToIMEInput(const JSCallbackInfo& args) void JSRichEditor::SetOnIMEInputComplete(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { - LOGE("args not function"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "args not function"); return; } auto jsOnIMEInputCompleteFunc = AceType::MakeRefPtr>( @@ -307,7 +307,7 @@ void JSRichEditor::SetOnIMEInputComplete(const JSCallbackInfo& args) void JSRichEditor::SetAboutToDelete(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { - LOGE("args not function"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "args not function"); return; } auto jsAboutToDeleteFunc = AceType::MakeRefPtr>( @@ -327,7 +327,7 @@ void JSRichEditor::SetAboutToDelete(const JSCallbackInfo& args) void JSRichEditor::SetOnDeleteComplete(const JSCallbackInfo& args) { if (args.Length() < 1 || !args[0]->IsFunction()) { - LOGE("args not function"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "args not function"); return; } JsEventCallback callback(args.GetExecutionContext(), JSRef::Cast(args[0])); @@ -470,7 +470,7 @@ void JSRichEditor::CreateImageStyleObj( void JSRichEditor::JsFocusable(const JSCallbackInfo& info) { if (info.Length() != 1 || !info[0]->IsBoolean()) { - LOGW("The info is wrong, it is supposed to be an boolean"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "The info is wrong, it is supposed to be an boolean"); return; } JSInteractableView::SetFocusable(info[0]->ToBoolean()); @@ -496,7 +496,7 @@ void JSRichEditor::BindSelectionMenu(const JSCallbackInfo& info) RichEditorType editorType = RichEditorType::TEXT; if (info.Length() >= 1 && info[0]->IsNumber()) { auto spanType = info[0]->ToNumber(); - LOGI("Set the spanType is %{public}d.", spanType); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "Set the spanType is %{public}d.", spanType); editorType = static_cast(spanType); } @@ -508,7 +508,7 @@ void JSRichEditor::BindSelectionMenu(const JSCallbackInfo& info) JSRef menuObj = JSRef::Cast(info[1]); auto builder = menuObj->GetProperty("builder"); if (!builder->IsFunction()) { - LOGE("builder param is not a function."); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "builder param is not a function."); return; } auto builderFunc = AceType::MakeRefPtr(JSRef::Cast(builder)); @@ -518,7 +518,7 @@ void JSRichEditor::BindSelectionMenu(const JSCallbackInfo& info) ResponseType responseType = ResponseType::LONG_PRESS; if (info.Length() >= 3 && info[2]->IsNumber()) { auto response = info[2]->ToNumber(); - LOGI("Set the responseType is %{public}d.", response); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "Set the responseType is %{public}d.", response); responseType = static_cast(response); } std::function buildFunc = [execCtx = info.GetExecutionContext(), func = std::move(builderFunc)]() { @@ -559,7 +559,6 @@ void JSRichEditor::ParseMenuParam( AceType::MakeRefPtr(JSRef(), JSRef::Cast(onDisappearValue)); auto onDisappear = [execCtx = info.GetExecutionContext(), func = std::move(jsOnDisAppearFunc)]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); - LOGI("About to call onAppear method on js"); ACE_SCORING_EVENT("onDisappear"); func->Execute(); }; @@ -1007,11 +1006,11 @@ namespace { bool ValidationCheck(const JSCallbackInfo& info) { if (info.Length() < 1) { - LOGW("The argv is wrong, it is supposed to have at least 1 argument"); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "The argv is wrong, it is supposed to have at least 1 argument"); return false; } if (!info[0]->IsNumber() && !info[0]->IsObject()) { - LOGW("info[0] not is Object or Number"); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "info[0] not is Object or Number"); return false; } return true; @@ -1199,11 +1198,11 @@ void JSRichEditorController::SetTypingStyle(const JSCallbackInfo& info) auto controller = controllerWeak_.Upgrade(); CHECK_NULL_VOID(controller); if (info.Length() < 1) { - LOGW("The argv is wrong, it is supposed to have at least 1 argument"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "The argv is wrong, it is supposed to have at least 1 argument"); return; } if (!info[0]->IsObject()) { - LOGW("info[0] not is Object"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "info[0] not is Object"); return; } TextStyle textStyle; diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_controller.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_controller.cpp index e067764a229..8bc9c910b41 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_controller.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_controller.cpp @@ -73,7 +73,7 @@ void RichEditorController::UpdateSpanStyle( std::swap(start, end); } if (start > length || end < 0 || start == end) { - LOGI("params error , return"); + TAG_LOGE(AceLogTag::ACE_RICH_EDITOR, "params error , return"); return; } richEditorPattern->SetUpdateSpanStyle(updateSpanStyle_); diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp index 7d31f831589..622afac281f 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_model_ng.cpp @@ -59,9 +59,7 @@ RefPtr RichEditorModelNG::GetRichEditorController() auto richEditorPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_RETURN(richEditorPattern, nullptr); RefPtr controller = richEditorPattern->GetRichEditorController(); - if (!controller) { - LOGE("RichEditorModelNG::GetRichEditorController: RichEditorControllerBase is null"); - } + return controller; } diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp index 32f5d3e9772..fe290e93d3d 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp @@ -1036,7 +1036,7 @@ void RichEditorPattern::ScheduleCaretTwinkling() CHECK_NULL_VOID(context); if (!context->GetTaskExecutor()) { - LOGW("context has no task executor."); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "context has no task executor."); return; } @@ -1102,7 +1102,7 @@ void RichEditorPattern::HandleClickEvent(GestureEvent& info) RequestKeyboard(false, true, true); } } else { - LOGE("request focus fail"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "request focus fail"); } } } @@ -1646,10 +1646,12 @@ void RichEditorPattern::UpdateCaretInfoToController() auto miscTextConfig = GetMiscTextConfig(); CHECK_NULL_VOID(miscTextConfig.has_value()); MiscServices::CursorInfo cursorInfo = miscTextConfig.value().cursorInfo; - LOGD("UpdateCaretInfoToController, left %{public}f, top %{public}f, width %{public}f, height %{public}f", + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "UpdateCaretInfoToController, left %{public}f, top %{public}f, width %{public}f, height %{public}f", cursorInfo.left, cursorInfo.top, cursorInfo.width, cursorInfo.height); MiscServices::InputMethodController::GetInstance()->OnCursorUpdate(cursorInfo); - LOGD("Start %{public}d, end %{public}d", textSelector_.GetStart(), textSelector_.GetEnd()); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "Start %{public}d, end %{public}d", textSelector_.GetStart(), textSelector_.GetEnd()); MiscServices::InputMethodController::GetInstance()->OnSelectionChange( StringUtils::Str8ToStr16(text), textSelector_.GetStart(), textSelector_.GetEnd()); @@ -2554,7 +2556,7 @@ RefPtr RichEditorPattern::GetChildByIndex(int32_t index) const std::string RichEditorPattern::GetSelectedSpanText(std::wstring value, int32_t start, int32_t end) const { if (start < 0 || end > static_cast(value.length()) || start >= end) { - LOGI("Get selected boundary is invalid"); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "Get selected boundary is invalid"); return ""; } auto min = std::min(start, end); @@ -2828,7 +2830,8 @@ void RichEditorPattern::HandleOnCopy() auto data = pattern->GetSelectedSpanText(StringUtils::ToWstring(result.valueString), result.offsetInSpan[RichEditorSpanRange::RANGESTART], result.offsetInSpan[RichEditorSpanRange::RANGEEND]); - LOGI("HandleOnCopy TYPESPAN, start: %{public}d, end: %{public}d, data: %{public}s", + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "HandleOnCopy TYPESPAN, start: %{public}d, end: %{public}d, data: %{public}s", result.offsetInSpan[RichEditorSpanRange::RANGESTART], result.offsetInSpan[RichEditorSpanRange::RANGEEND], data.c_str()); clipboard->AddTextRecord(pasteData, data); @@ -2836,10 +2839,11 @@ void RichEditorPattern::HandleOnCopy() } if (result.type == RichEditorSpanType::TYPEIMAGE) { if (result.valuePixelMap) { - LOGI("HandleOnCopy TYPEIMAGE valuePixelMap"); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "HandleOnCopy TYPEIMAGE valuePixelMap"); clipboard->AddPixelMapRecord(pasteData, result.valuePixelMap); } else { - LOGI("HandleOnCopy TYPEIMAGE, uri: %{public}s", result.valueString.c_str()); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "HandleOnCopy TYPEIMAGE, uri: %{public}s", result.valueString.c_str()); clipboard->AddImageRecord(pasteData, result.valueString); } } @@ -2883,17 +2887,17 @@ void RichEditorPattern::HandleOnPaste() auto textCallback = [weak = WeakClaim(this), textSelector = textSelector_]( const std::string& data, bool isLastRecord) { if (data.empty()) { - LOGE("Paste value is empty"); return; } auto richEditor = weak.Upgrade(); CHECK_NULL_VOID(richEditor); - LOGI("HandleOnPaste InsertValue: %{public}s", data.c_str()); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "HandleOnPaste InsertValue: %{public}s", data.c_str()); richEditor->AddPasteStr(data); if (isLastRecord) { richEditor->ResetAfterPaste(); } - LOGI("after insert text record, CaretPosition:%{public}d, moveLength_: %{public}d", + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "after insert text record, CaretPosition:%{public}d, moveLength_: %{public}d", richEditor->GetCaretPosition(), richEditor->moveLength_); }; auto pixelMapCallback = [weak = WeakClaim(this), textSelector = textSelector_]( @@ -2911,7 +2915,8 @@ void RichEditorPattern::HandleOnPaste() if (isLastRecord) { richEditor->ResetAfterPaste(); } - LOGI("after insert pixelMap record, CaretPosition :%{public}d, moveLength_: %{public}d", + TAG_LOGI(AceLogTag::ACE_RICH_EDITOR, + "after insert pixelMap record, CaretPosition :%{public}d, moveLength_: %{public}d", richEditor->GetCaretPosition(), richEditor->moveLength_); }; auto urlCallback = [weak = WeakClaim(this), textSelector = textSelector_]( @@ -2929,7 +2934,8 @@ void RichEditorPattern::HandleOnPaste() if (isLastRecord) { richEditor->ResetAfterPaste(); } - LOGI("after insert pixelMap url, CaretPosition :%{public}d, moveLength_: %{public}d", + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "after insert pixelMap url, CaretPosition :%{public}d, moveLength_: %{public}d", richEditor->GetCaretPosition(), richEditor->moveLength_); }; clipboard_->GetData(textCallback, pixelMapCallback, urlCallback); @@ -2940,7 +2946,8 @@ void RichEditorPattern::InsertValueByPaste(const std::string& insertValue) RefPtr child; TextInsertValueInfo info; CalcInsertValueObj(info); - LOGD("InsertValueByPaste spanIndex: %{public}d, offset inspan: %{public}d, caretPosition: %{public}d", + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "InsertValueByPaste spanIndex: %{public}d, offset inspan: %{public}d, caretPosition: %{public}d", info.GetSpanIndex(), info.GetOffsetInSpan(), caretPosition_); TextSpanOptions options; options.value = insertValue; @@ -2962,13 +2969,15 @@ void RichEditorPattern::InsertValueByPaste(const std::string& insertValue) } else { InsertValueToSpanNode(spanNode, insertValue, info); } - LOGD("insert first record after SpanNode, caretSpanIndex: %{public}d ", caretSpanIndex_); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "insert first record after SpanNode, caretSpanIndex: %{public}d ", caretSpanIndex_); return; } else if (!child) { auto spanNodeBefore = DynamicCast(GetChildByIndex(info.GetSpanIndex() - 1)); if (spanNodeBefore == nullptr) { caretSpanIndex_ = AddTextSpan(options, true); - LOGD("insert the first record at the end, caretSpanIndex: %{public}d ", caretSpanIndex_); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "insert the first record at the end, caretSpanIndex: %{public}d ", caretSpanIndex_); return; } if (typingStyle_.has_value() && !HasSameTypingStyle(spanNodeBefore)) { @@ -2979,9 +2988,8 @@ void RichEditorPattern::InsertValueByPaste(const std::string& insertValue) InsertValueToBeforeSpan(spanNodeBefore, insertValue); caretSpanIndex_ = info.GetSpanIndex() - 1; } - LOGD("insert the first record at the before spanNode, caretSpanIndex: " - "%{public}d", - caretSpanIndex_); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "insert the first record at the before spanNode, caretSpanIndex: %{public}d", caretSpanIndex_); return; } } else { @@ -2989,7 +2997,8 @@ void RichEditorPattern::InsertValueByPaste(const std::string& insertValue) if (child && child->GetTag() == V2::SPAN_ETS_TAG) { auto spanNode = DynamicCast(child); CHECK_NULL_VOID(spanNode); - LOGD("insert record after spanNode at caretSpanIndex: %{public}d ", caretSpanIndex_); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "insert record after spanNode at caretSpanIndex: %{public}d ", caretSpanIndex_); if (typingStyle_.has_value() && !HasSameTypingStyle(spanNode)) { options.offset = newSpanOffset; caretSpanIndex_ = AddTextSpan(options, true); @@ -3000,7 +3009,7 @@ void RichEditorPattern::InsertValueByPaste(const std::string& insertValue) } } if (child && child->GetTag() == V2::IMAGE_ETS_TAG) { - LOGD("InsertValueByPaste after imageNode"); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "InsertValueByPaste after imageNode"); auto spanNodeBefore = DynamicCast(GetChildByIndex(info.GetSpanIndex() - 1)); if (spanNodeBefore != nullptr && caretSpanIndex_ == -1) { if (typingStyle_.has_value() && !HasSameTypingStyle(spanNodeBefore)) { @@ -3010,26 +3019,26 @@ void RichEditorPattern::InsertValueByPaste(const std::string& insertValue) InsertValueToBeforeSpan(spanNodeBefore, insertValue); caretSpanIndex_ = info.GetSpanIndex() - 1; } - LOGD("child is image and insert the first record at the before spanNode, " - "caretSpanIndex: %{public}d", + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "child is image and insert the first record at the before spanNode, caretSpanIndex: %{public}d", caretSpanIndex_); } else { auto imageNode = DynamicCast(child); if (imageNode && caretSpanIndex_ == -1) { caretSpanIndex_ = AddTextSpan(options, true, info.GetSpanIndex()); - LOGD("child is image and insert the first record after imageNode, " - "caretSpanIndex: %{public}d", + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "child is image and insert the first record after imageNode, caretSpanIndex: %{public}d", caretSpanIndex_); } else { caretSpanIndex_ = AddTextSpan(options, true, caretSpanIndex_ + 1); - LOGD("child is image and insert the record after imageNode, " - "caretSpanIndex: %{public}d", + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "child is image and insert the record after imageNode, caretSpanIndex: %{public}d", caretSpanIndex_); } } } else { caretSpanIndex_ = AddTextSpan(options, true); - LOGD("after insert, caretSpanIndex: %{public}d ", caretSpanIndex_); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, "after insert, caretSpanIndex: %{public}d ", caretSpanIndex_); } } @@ -3325,8 +3334,9 @@ void RichEditorPattern::BindSelectionMenu(ResponseType type, RichEditorType rich auto selectionMenuParams = std::make_shared(richEditorType, menuBuilder, onAppear, onDisappear, type); selectionMenuMap_[key] = selectionMenuParams; - LOGD("BindSelectionMenu, editType = %{public}d responseType = %{public}d, map size = %{public}d", richEditorType, - type, selectionMenuMap_.size()); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "BindSelectionMenu, editType = %{public}d responseType = %{public}d, map size = %{public}d", + richEditorType, type, selectionMenuMap_.size()); auto host = GetHost(); CHECK_NULL_VOID(host); host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); @@ -3402,7 +3412,8 @@ void RichEditorPattern::UpdateSelectionType(RichEditorSelection& selection) } else if (textSelected) { selectedType_ = RichEditorType::TEXT; } - LOGD("UpdateSelectionType selectedType_ is %{public}d", selectedType_.value_or(RichEditorType::TEXT)); + TAG_LOGD(AceLogTag::ACE_RICH_EDITOR, + "UpdateSelectionType selectedType_ is %{public}d", selectedType_.value_or(RichEditorType::TEXT)); } std::shared_ptr RichEditorPattern::GetMenuParams(bool usingMouse, RichEditorType type) diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_theme.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_theme.h index 552cc5adebc..d745092e155 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_theme.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_theme.h @@ -53,7 +53,7 @@ public: } auto pattern = themeStyle->GetAttr>(THEME_PATTERN_RICH_EDITOR, nullptr); if (!pattern) { - LOGW("find pattern of text fail"); + TAG_LOGW(AceLogTag::ACE_RICH_EDITOR, "find pattern of text fail"); return; } auto draggable = pattern->GetAttr("draggable", "0"); -- Gitee