| 1067 | |
| 1068 | |
| 1069 | void WizDocumentWebView::onEditorLoadFinished(bool ok) |
| 1070 | { |
| 1071 | if (!ok) |
| 1072 | return; |
| 1073 | // |
| 1074 | QString resPath = Utils::WizPathResolve::resourcesPath() + "files/"; |
| 1075 | QString editorPath = resPath + "wizeditor/"; |
| 1076 | QString lang = "zh-cn"; |
| 1077 | QString userGUID = m_dbMgr.db().getUserGuid(); |
| 1078 | QString userAlias = m_dbMgr.db().getUserAlias(); |
| 1079 | // |
| 1080 | const WIZDOCUMENTDATAEX& doc = view()->note(); |
| 1081 | bool ignoreTable = doc.strURL.startsWith("http"); |
| 1082 | // |
| 1083 | QString noteType = getNoteType(); |
| 1084 | QString keywords = getHighlightKeywords(); |
| 1085 | // Initialize rich text editor |
| 1086 | QString strCode = "(async function(){\n"; |
| 1087 | strCode += WizFormatString6("await WizEditorInit(\"%1\", \"%2\", \"%3\", \"%4\", %5, \"%6\", false);", |
| 1088 | editorPath, lang, userGUID, userAlias, |
| 1089 | ignoreTable ? "true" : "false", |
| 1090 | noteType); |
| 1091 | if (m_currentEditorMode == modeEditor) { |
| 1092 | // Open rich text editor when doc is in edit mode |
| 1093 | strCode += "WizEditor.on();"; |
| 1094 | } else { |
| 1095 | // Close rich text editor when doc is in read mode |
| 1096 | if (keywords.isEmpty()) { |
| 1097 | strCode += "WizEditor.off();"; |
| 1098 | } else { |
| 1099 | // When user open document in search results, highlit key words |
| 1100 | QString strCodeMarkdown = QString("WizEditor.off(null, function(){\n\ |
| 1101 | WizReader.highlight.on([%1]);\nconsole.log('highlight');\n\ |
| 1102 | });").arg(keywords); |
| 1103 | QString strCodeCommon = "await new Promise( (resolve, reject) => {" |
| 1104 | "WizEditor.off(null, () => {" |
| 1105 | "resolve();" |
| 1106 | "});" |
| 1107 | "});"; |
| 1108 | // It's hard to determine when markdown document has rendered. |
| 1109 | // So, keywords highlight in scroll bar is only available for |
| 1110 | // common document. |
| 1111 | if (noteType == "common") { |
| 1112 | strCode += strCodeCommon; |
| 1113 | } else { |
| 1114 | strCode += strCodeMarkdown; |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | strCode += "\n})()"; |
| 1119 | page()->runJavaScript(strCode, [=](const QVariant &v) { |
| 1120 | if (!keywords.isEmpty()) { |
| 1121 | if (noteType == "common") { |
| 1122 | //FIXME: This is not the best way, it needs the keyword in search line |
| 1123 | QString word = keywords.split(",").first() |
| 1124 | .section("'", 0, 0, QString::SectionSkipEmpty); |
| 1125 | findText(word); |
| 1126 | } |
nothing calls this directly
no test coverage detected