zhangchao 4 年之前
父節點
當前提交
35457a9159
共有 3 個檔案被更改,包括 12 行新增8 行删除
  1. 4
    2
      src/RichTextEditor.js
  2. 2
    1
      src/const.js
  3. 6
    5
      src/editor.html

+ 4
- 2
src/RichTextEditor.js 查看文件

@@ -172,7 +172,7 @@ export default class RichTextEditor extends Component {
172 172
           this.contentBlurHandler && this.contentBlurHandler();
173 173
           break;
174 174
         case messages.ONCHANGE_EMPTY_OR_NOT:
175
-          this.onChangeEmptyOrNot && this.onChangeEmptyOrNot();
175
+          this.onChangeEmptyOrNot && this.onChangeEmptyOrNot(message.isEmpty);
176 176
           break;
177 177
         case messages.SELECTION_CHANGE: {
178 178
           const items = message.data.items;
@@ -307,7 +307,9 @@ export default class RichTextEditor extends Component {
307 307
 
308 308
   _sendAction(action, data) {
309 309
     let jsToBeExecutedOnPage = MessageConverter({ type: action, data });
310
-    console.log(jsToBeExecutedOnPage + ';true;')
310
+    if (__DEV__) {
311
+      console.log(jsToBeExecutedOnPage + ';true;')
312
+    }
311 313
     this.webview.injectJavaScript(jsToBeExecutedOnPage + ';true;');
312 314
   }
313 315
 

+ 2
- 1
src/const.js 查看文件

@@ -74,5 +74,6 @@ export const messages = {
74 74
   CONTENT_CHANGE: 'CONTENT_CHANGE',
75 75
   SELECTED_TEXT_RESPONSE: 'SELECTED_TEXT_RESPONSE',
76 76
   LINK_TOUCHED: 'LINK_TOUCHED',
77
-  SELECTED_TEXT_CHANGED: 'SELECTED_TEXT_CHANGED'
77
+  SELECTED_TEXT_CHANGED: 'SELECTED_TEXT_CHANGED',
78
+  ONCHANGE_EMPTY_OR_NOT: 'ONCHANGE_EMPTY_OR_NOT'
78 79
 };

+ 6
- 5
src/editor.html 查看文件

@@ -1062,7 +1062,7 @@
1062 1062
 					var range = selection.getRangeAt(0);
1063 1063
 					zss_editor.currentSelection = {"startContainer": range.startContainer, "startOffset":range.startOffset,"endContainer":range.endContainer, "endOffset":range.endOffset};
1064 1064
 					if (range.endOffset === range.startOffset && showCaretPlaceholder === true) {
1065
-						zss_editor.insertHTML('<div class="caret_placeholder">&nbsp;&nbsp;</div>');
1065
+						zss_editor.insertHTML('<div class="caret_placeholder">&nbsp;</div>');
1066 1066
 					}
1067 1067
 				} catch (err) {}
1068 1068
 			}
@@ -1480,8 +1480,6 @@
1480 1480
 			}
1481 1481
 
1482 1482
 			zss_editor.enabledEditingItems = function(e) {
1483
-
1484
-				console.log('enabledEditingItems');
1485 1483
 				var items = [];
1486 1484
 				if (zss_editor.isCommandEnabled('bold')) {
1487 1485
 					items.push('bold');
@@ -1656,9 +1654,12 @@
1656 1654
 			var contentIsEmpty = true;
1657 1655
 			zss_editor.setOnChangeEmptyOrNot = function() {
1658 1656
 				$('#zss_editor_content').on('input', function() {
1659
-					if (!this.textContent && this.querySelectorAll('img, li').length === 0 && !contentIsEmpty) {
1657
+					const textContentLength = this.textContent.length - document.querySelectorAll(".caret_placeholder").length;
1658
+					if (textContentLength === 0 && this.querySelectorAll('img, li').length === 0 && !contentIsEmpty) {
1659
+						contentIsEmpty = true;
1660 1660
 						ReactNativeWebView.postMessage(JSON.stringify({type: 'ONCHANGE_EMPTY_OR_NOT', isEmpty: true}))
1661
-					} else if (contentIsEmpty && (this.textContent || this.querySelectorAll('img, li').length > 0)) {
1661
+					} else if (contentIsEmpty && (textContentLength > 0 || this.querySelectorAll('img, li').length > 0)) {
1662
+						contentIsEmpty = false;
1662 1663
 						ReactNativeWebView.postMessage(JSON.stringify({type: 'ONCHANGE_EMPTY_OR_NOT', isEmpty: false}))
1663 1664
 					}
1664 1665
 				});