zhangchao 5 years ago
parent
commit
35457a9159
3 changed files with 12 additions and 8 deletions
  1. 4
    2
      src/RichTextEditor.js
  2. 2
    1
      src/const.js
  3. 6
    5
      src/editor.html

+ 4
- 2
src/RichTextEditor.js View File

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

+ 2
- 1
src/const.js View File

74
   CONTENT_CHANGE: 'CONTENT_CHANGE',
74
   CONTENT_CHANGE: 'CONTENT_CHANGE',
75
   SELECTED_TEXT_RESPONSE: 'SELECTED_TEXT_RESPONSE',
75
   SELECTED_TEXT_RESPONSE: 'SELECTED_TEXT_RESPONSE',
76
   LINK_TOUCHED: 'LINK_TOUCHED',
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 View File

1062
 					var range = selection.getRangeAt(0);
1062
 					var range = selection.getRangeAt(0);
1063
 					zss_editor.currentSelection = {"startContainer": range.startContainer, "startOffset":range.startOffset,"endContainer":range.endContainer, "endOffset":range.endOffset};
1063
 					zss_editor.currentSelection = {"startContainer": range.startContainer, "startOffset":range.startOffset,"endContainer":range.endContainer, "endOffset":range.endOffset};
1064
 					if (range.endOffset === range.startOffset && showCaretPlaceholder === true) {
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
 				} catch (err) {}
1067
 				} catch (err) {}
1068
 			}
1068
 			}
1480
 			}
1480
 			}
1481
 
1481
 
1482
 			zss_editor.enabledEditingItems = function(e) {
1482
 			zss_editor.enabledEditingItems = function(e) {
1483
-
1484
-				console.log('enabledEditingItems');
1485
 				var items = [];
1483
 				var items = [];
1486
 				if (zss_editor.isCommandEnabled('bold')) {
1484
 				if (zss_editor.isCommandEnabled('bold')) {
1487
 					items.push('bold');
1485
 					items.push('bold');
1656
 			var contentIsEmpty = true;
1654
 			var contentIsEmpty = true;
1657
 			zss_editor.setOnChangeEmptyOrNot = function() {
1655
 			zss_editor.setOnChangeEmptyOrNot = function() {
1658
 				$('#zss_editor_content').on('input', function() {
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
 						ReactNativeWebView.postMessage(JSON.stringify({type: 'ONCHANGE_EMPTY_OR_NOT', isEmpty: true}))
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
 						ReactNativeWebView.postMessage(JSON.stringify({type: 'ONCHANGE_EMPTY_OR_NOT', isEmpty: false}))
1663
 						ReactNativeWebView.postMessage(JSON.stringify({type: 'ONCHANGE_EMPTY_OR_NOT', isEmpty: false}))
1663
 					}
1664
 					}
1664
 				});
1665
 				});