Pārlūkot izejas kodu

Text and Background colors

Yedidya Kennard 8 gadus atpakaļ
vecāks
revīzija
a7267c1016

+ 8
- 0
src/RichTextEditor.js Parādīt failu

@@ -336,6 +336,14 @@ export default class RichTextEditor extends Component {
336 336
     this._sendAction(actions.setOutdent);
337 337
   }
338 338
 
339
+  setBackgroundColor(color) {
340
+    this._sendAction(actions.setBackgroundColor, color);
341
+  }
342
+
343
+  setTextColor(color) {
344
+    this._sendAction(actions.setTextColor, color);
345
+  }
346
+
339 347
   setTitlePlaceholder() {
340 348
     this._sendAction(actions.setTitlePlaceholder);
341 349
   }

+ 6
- 0
src/WebviewMessageHandler.js Parādīt failu

@@ -129,6 +129,12 @@ export const InjectedMessageHandler = `
129 129
         case '${actions.setCustomCSS}':
130 130
           zss_editor.setCustomCSS(action.data);
131 131
           break;
132
+        case '${actions.setTextColor}':
133
+          zss_editor.setTextColor(action.data);
134
+          break;
135
+        case '${actions.setBackgroundColor}':
136
+          zss_editor.setBackgroundColor(action.data);
137
+          break;
132 138
       }
133 139
     };
134 140
   }

+ 8
- 3
src/ZSSRichTextEditor/ZSSRichTextEditor.js Parādīt failu

@@ -371,8 +371,10 @@ zss_editor.setFontFamily = function(fontFamily) {
371 371
 }
372 372
 
373 373
 zss_editor.setTextColor = function(color) {
374
-		
375
-    zss_editor.restorerange();
374
+
375
+    if(zss_editor.currentSelection) {
376
+        zss_editor.restorerange();
377
+    }
376 378
     document.execCommand("styleWithCSS", null, true);
377 379
     document.execCommand('foreColor', false, color);
378 380
     document.execCommand("styleWithCSS", null, false);
@@ -382,7 +384,10 @@ zss_editor.setTextColor = function(color) {
382 384
 }
383 385
 
384 386
 zss_editor.setBackgroundColor = function(color) {
385
-    zss_editor.restorerange();
387
+    
388
+    if(zss_editor.currentSelection) {
389
+        zss_editor.restorerange();
390
+    }
386 391
     document.execCommand("styleWithCSS", null, true);
387 392
     document.execCommand('hiliteColor', false, color);
388 393
     document.execCommand("styleWithCSS", null, false);

+ 3
- 1
src/const.js Parādīt failu

@@ -39,7 +39,9 @@ export const actions = {
39 39
   setContentFocusHandler: 'SET_CONTENT_FOCUS_HANDLER',
40 40
   prepareInsert: 'PREPARE_INSERT',
41 41
   restoreSelection: 'RESTORE_SELECTION',
42
-  setCustomCSS: 'SET_CUSTOM_CSS'
42
+  setCustomCSS: 'SET_CUSTOM_CSS',
43
+  setTextColor: 'SET_TEXT_COLOR',
44
+  setBackgroundColor: 'SET_BACKGROUND_COLOR'
43 45
 };
44 46
 
45 47