Skip to content

Commit ac5cded

Browse files
committed
Add getTitleText method
1 parent 9e33d52 commit ac5cded

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/RichTextEditor.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ export default class RichTextEditor extends Component {
8585
}
8686
}
8787
break;
88+
case messages.TITLE_TEXT_RESPONSE:
89+
if (this.titleTextResolve) {
90+
this.titleTextResolve(message.data);
91+
this.titleTextResolve = undefined;
92+
this.titleTextReject = undefined;
93+
if (this.pendingTitleText) {
94+
clearTimeout(this.pendingTitleText);
95+
this.pendingTitleText = undefined;
96+
}
97+
}
98+
break;
8899
case messages.CONTENT_HTML_RESPONSE:
89100
if (this.contentResolve) {
90101
this.contentResolve(message.data);
@@ -440,6 +451,20 @@ export default class RichTextEditor extends Component {
440451
});
441452
}
442453

454+
async getTitleText() {
455+
return new Promise((resolve, reject) => {
456+
this.titleTextResolve = resolve;
457+
this.titleTextReject = reject;
458+
this._sendAction(actions.getTitleText);
459+
460+
this.pendingTitleText = setTimeout(() => {
461+
if (this.titleTextReject) {
462+
this.titleTextReject('timeout');
463+
}
464+
}, 5000);
465+
});
466+
}
467+
443468
async getContentHtml() {
444469
return new Promise((resolve, reject) => {
445470
this.contentResolve = resolve;

src/WebviewMessageHandler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export const InjectedMessageHandler = `
104104
var html = zss_editor.getTitleHTML();
105105
WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_HTML_RESPONSE}', data: html}));
106106
break;
107+
case '${actions.getTitleText}':
108+
var html = zss_editor.getTitleText();
109+
WebViewBridge.send(JSON.stringify({type: '${messages.TITLE_TEXT_RESPONSE}', data: html}));
110+
break;
107111
case '${actions.getContentHtml}':
108112
var html = zss_editor.getContentHTML();
109113
WebViewBridge.send(JSON.stringify({type: '${messages.CONTENT_HTML_RESPONSE}', data: html}));

src/const.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const actions = {
22
setTitleHtml: 'SET_TITLE_HTML',
33
setContentHtml: 'SET_CONTENT_HTML',
44
getTitleHtml: 'GET_TITLE_HTML',
5+
getTitleText: 'GET_TITLE_TEXT',
56
getContentHtml: 'GET_CONTENT_HTML',
67
blurTitleEditor: 'BLUR_TITLE_EDITOR',
78
blurContentEditor: 'BLUR_CONTENT_EDITOR',
@@ -48,6 +49,7 @@ export const actions = {
4849

4950
export const messages = {
5051
TITLE_HTML_RESPONSE: 'TITLE_HTML_RESPONSE',
52+
TITLE_TEXT_RESPONSE: 'TITLE_TEXT_RESPONSE',
5153
CONTENT_HTML_RESPONSE: 'CONTENT_HTML_RESPONSE',
5254
ZSS_INITIALIZED: 'ZSS_INITIALIZED',
5355
SCROLL: 'SCROLL',

0 commit comments

Comments
 (0)