Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/prt 2040 #184

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
2 changes: 2 additions & 0 deletions src/editor/navigationFields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IaraSpeechRecognition } from "../speech";
import { IaraAdditiveBookmark } from "../syncfusion/navigationFields/navigationBookmark";

export abstract class IaraEditorNavigationFieldManager {
abstract nextField(): void;
Expand All @@ -10,6 +11,7 @@ export abstract class IaraEditorNavigationFieldManager {
title?: string,
type?: "Field" | "Mandatory" | "Optional"
): void;
abstract additiveBookmark: IaraAdditiveBookmark;
constructor(private _recognition: IaraSpeechRecognition) {
this._recognition.addEventListener("iaraSpeechMikeForwardButtonPress", () =>
this.nextField()
Expand Down
46 changes: 28 additions & 18 deletions src/syncfusion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,18 @@ export class IaraSyncfusionAdapter
.replace(/\r/g, "\n")
.trim()
.toLocaleLowerCase();
const normalizedInferenceText = bookmark.inferenceText?.trim().toLocaleLowerCase();
if (!bookmark.recordingId || !normalizedContent.length || !normalizedInferenceText?.length) return;

const evaluation = normalizedContent === normalizedInferenceText ? 6 : 5;
const normalizedInferenceText = bookmark.inferenceText
?.trim()
.toLocaleLowerCase();
if (
!bookmark.recordingId ||
!normalizedContent.length ||
!normalizedInferenceText?.length
)
return;

const evaluation =
normalizedContent === normalizedInferenceText ? 6 : 5;
await fetch(`${IaraSyncfusionAdapter.IARA_API_URL}voice/validation/`, {
headers: {
...this._recognition.internal.iaraAPIMandatoryHeaders,
Expand Down Expand Up @@ -342,7 +350,7 @@ export class IaraSyncfusionAdapter
fontColor: this.config.darkMode ? "#fff" : "#000",
});

this._navigationFieldManager.getBookmarks();
this._navigationFieldManager.createBookmarks();
this._documentEditor.selection.moveToDocumentEnd();
}

Expand Down Expand Up @@ -372,7 +380,8 @@ export class IaraSyncfusionAdapter
if (!this._selectionManager) return;

this._inferenceBookmarksManager.updateBookmarkInference(
this._selectionManager.initialSelectionData.bookmarkId, inference
this._selectionManager.initialSelectionData.bookmarkId,
inference
);

if (
Expand All @@ -393,7 +402,9 @@ export class IaraSyncfusionAdapter

if (this._selectionManager.initialSelectionData.characterFormat.allCaps) {
// Insert text is not respecting the allCaps property, work around that
this._selectionManager.selectBookmark(this._selectionManager.initialSelectionData.bookmarkId);
this._selectionManager.selectBookmark(
this._selectionManager.initialSelectionData.bookmarkId
);
this._documentEditor.selection.characterFormat.allCaps = true;
}

Expand Down Expand Up @@ -491,10 +502,8 @@ export class IaraSyncfusionAdapter
if (item.category === "Template") {
if (this.preprocessAndInsertTemplate)
this.preprocessAndInsertTemplate?.(item.content, item);
else
this.insertTemplate(item.content);
}
else this.insertText(item.content);
else this.insertTemplate(item.content);
} else this.insertText(item.content);

dialogObj.hide();
}
Expand Down Expand Up @@ -531,7 +540,8 @@ export class IaraSyncfusionAdapter
.getRootElement()
.addEventListener("mousedown", event => {
if (event.button === 1) {
if (this._documentEditor.selection.text.length > 0) this._documentEditor.editor.delete();
if (this._documentEditor.selection.text.length > 0)
this._documentEditor.editor.delete();
this._cursorSelection = new IaraSyncfusionSelectionManager(
this._documentEditor,
this.config
Expand All @@ -549,7 +559,7 @@ export class IaraSyncfusionAdapter
});
}

protected _initCommands(): void {
protected _initCommands(): void {
super._initCommands();
this._recognition.commands.add(
this._locale.acceptAll,
Expand All @@ -559,7 +569,7 @@ export class IaraSyncfusionAdapter
},
...this._defaultCommandArgs
);
}
}

private _updateSelectedNavigationField(field: string): void {
if (field.match(/\[(.*)\]/)) {
Expand All @@ -580,7 +590,7 @@ export class IaraSyncfusionAdapter

private _handleFirstInference(inference: IaraSpeechRecognitionDetail): void {
this._updateSelectedNavigationField(this._documentEditor.selection.text);
const hadSelectedText = this._documentEditor.selection.text.length
const hadSelectedText = this._documentEditor.selection.text.length;

if (hadSelectedText) this._documentEditor.editor.delete();

Expand Down Expand Up @@ -609,7 +619,8 @@ export class IaraSyncfusionAdapter
this._documentEditor.selection.moveToPreviousCharacter();
this._documentEditor.selection.extendForward();
this._documentEditor.editor.delete();
this._selectionManager.wordBeforeSelection = this._selectionManager.wordBeforeSelection.slice(0, -1);
this._selectionManager.wordBeforeSelection =
this._selectionManager.wordBeforeSelection.slice(0, -1);
}
this._selectionManager.resetSelection();
}
Expand Down Expand Up @@ -654,8 +665,7 @@ export class IaraSyncfusionAdapter
});
if (this.preprocessAndInsertTemplate)
this.preprocessAndInsertTemplate?.(template, metadata);
else
this.insertTemplate(template);
else this.insertTemplate(template);
return true;
}

Expand Down
Loading