Skip to content

Commit

Permalink
feat: add logic to save when editor created (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItalloDornelas authored Jan 5, 2024
1 parent d0cb95a commit 6f8833e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ export abstract class EditorAdapter {

constructor(
protected _editorContainer: DocumentEditorContainer | TinymceEditor,
protected _recognition: IaraSpeechRecognition
protected _recognition: IaraSpeechRecognition,
protected _shouldSaveReport: boolean = true
) {
this._inferenceFormatter = new IaraEditorInferenceFormatter();
this._initCommands();
this._initListeners();
this._recognition.internal.settings.replaceCommandActivationStringBeforeCallback =
true;
if (this._shouldSaveReport && !this._recognition.report["_key"])
this.beginReport();
}

abstract blockEditorWhileSpeaking(status: boolean): void;
Expand All @@ -59,11 +62,12 @@ export abstract class EditorAdapter {
abstract getEditorContent(): Promise<[string, string, string]>;

beginReport(): string | void {
this._recognition.report["_key"] = "";
if (!this._shouldSaveReport) return;
return this._recognition.beginReport({ richText: "", text: "" });
}

finishReport(clear = true): void {
if (!this._shouldSaveReport) return;
this.copyReport();
if (clear) this.clearReport();
this._recognition.finishReport();
Expand Down Expand Up @@ -100,6 +104,7 @@ export abstract class EditorAdapter {
}

protected async _onEditorDestroyed(): Promise<void> {
this._recognition.report["_key"] = "";
this._listeners.forEach(listener => {
this._recognition.removeEventListener(
listener.key,
Expand Down
6 changes: 4 additions & 2 deletions src/syncfusion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export class IaraSyncfusionAdapter
constructor(
protected _editorContainer: DocumentEditorContainer,
protected _recognition: IaraSpeechRecognition,
protected _shouldSaveReport = true,
replaceToolbar = false
) {
super(_editorContainer, _recognition);
super(_editorContainer, _recognition, _shouldSaveReport);

this._contentManager = new IaraSyncfusionEditorContentManager(
_editorContainer.documentEditor,
_recognition,
this._onContentChange.bind(this)
() => (this._shouldSaveReport ? this._onContentChange() : undefined)
);

this._shortcutsManager = new IaraSyncfusionShortcutsManager(
Expand Down

0 comments on commit 6f8833e

Please sign in to comment.