|
@@ -32,7 +32,7 @@ export default class RichTextEditor extends Component {
|
32
|
32
|
this._onKeyboardWillShow = this._onKeyboardWillShow.bind(this);
|
33
|
33
|
this._onKeyboardWillHide = this._onKeyboardWillHide.bind(this);
|
34
|
34
|
this.state = {
|
35
|
|
- listeners: [],
|
|
35
|
+ selectionChangeListeners: [],
|
36
|
36
|
onChange: [],
|
37
|
37
|
showLinkDialog: false,
|
38
|
38
|
linkInitialUrl: '',
|
|
@@ -40,6 +40,7 @@ export default class RichTextEditor extends Component {
|
40
|
40
|
linkUrl: '',
|
41
|
41
|
keyboardHeight: 0
|
42
|
42
|
};
|
|
43
|
+ this._selectedTextChangeListeners = [];
|
43
|
44
|
}
|
44
|
45
|
|
45
|
46
|
componentWillMount() {
|
|
@@ -154,14 +155,25 @@ export default class RichTextEditor extends Component {
|
154
|
155
|
case messages.CONTENT_FOCUSED:
|
155
|
156
|
this.contentFocusHandler && this.contentFocusHandler();
|
156
|
157
|
break;
|
157
|
|
- case messages.SELECTION_CHANGE:
|
|
158
|
+ case messages.SELECTION_CHANGE: {
|
158
|
159
|
const items = message.data.items;
|
159
|
|
- this.state.listeners.map((listener) => listener(items));
|
160
|
|
- break
|
161
|
|
- case messages.CONTENT_CHANGE:
|
|
160
|
+ this.state.selectionChangeListeners.map((listener) => {
|
|
161
|
+ listener(items);
|
|
162
|
+ });
|
|
163
|
+ break;
|
|
164
|
+ }
|
|
165
|
+ case messages.CONTENT_CHANGE: {
|
162
|
166
|
const content = message.data.content;
|
163
|
167
|
this.state.onChange.map((listener) => listener(content));
|
164
|
|
- break
|
|
168
|
+ break;
|
|
169
|
+ }
|
|
170
|
+ case messages.SELECTED_TEXT_CHANGED: {
|
|
171
|
+ const selectedText = message.data;
|
|
172
|
+ this._selectedTextChangeListeners.forEach((listener) => {
|
|
173
|
+ listener(selectedText);
|
|
174
|
+ });
|
|
175
|
+ break;
|
|
176
|
+ }
|
165
|
177
|
}
|
166
|
178
|
} catch(e) {
|
167
|
179
|
//alert('NON JSON MESSAGE');
|
|
@@ -319,7 +331,7 @@ export default class RichTextEditor extends Component {
|
319
|
331
|
|
320
|
332
|
registerToolbar(listener) {
|
321
|
333
|
this.setState({
|
322
|
|
- listeners: [...this.state.listeners, listener]
|
|
334
|
+ selectionChangeListeners: [...this.state.selectionChangeListeners, listener]
|
323
|
335
|
});
|
324
|
336
|
}
|
325
|
337
|
|
|
@@ -559,6 +571,10 @@ export default class RichTextEditor extends Component {
|
559
|
571
|
this.contentFocusHandler = callbackHandler;
|
560
|
572
|
this._sendAction(actions.setContentFocusHandler);
|
561
|
573
|
}
|
|
574
|
+
|
|
575
|
+ addSelectedTextChangeListener(listener) {
|
|
576
|
+ this._selectedTextChangeListeners.push(listener);
|
|
577
|
+ }
|
562
|
578
|
}
|
563
|
579
|
|
564
|
580
|
const styles = StyleSheet.create({
|