Skip to content

Commit

Permalink
Merge branch 'release/0.2.8' into release/0.2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
dsouza95 committed Sep 23, 2024
2 parents 61e24cb + 028d20d commit b986597
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/syncfusion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ export class IaraSyncfusionAdapter
inference.inferenceId
? `inferenceId_${inference.inferenceId}`
: undefined,
true,
this.config.highlightInference
);

Expand Down
40 changes: 24 additions & 16 deletions src/syncfusion/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class IaraSyncfusionSelectionManager {
private _editor: DocumentEditor,
private _config: IaraSyncfusionConfig,
bookmarkId?: string,
getSurrondingWords = false,
highlightSelection = false
) {
if (highlightSelection) this._highlightSelection();
Expand All @@ -62,42 +61,51 @@ export class IaraSyncfusionSelectionManager {
};

const { endOffset, startOffset } = this._editor.selection;
this._editor.editor.insertBookmark(this.initialSelectionData.bookmarkId);

if (!getSurrondingWords) return;
const [wordBefore, lineBefore] = this._getWordBeforeSelection();
this.wordBeforeSelection = wordBefore;

this._editor.selection.select(startOffset, endOffset);
this.wordBeforeSelection = this._getWordBeforeSelection();
const [wordAfter, lineAfter] = this._getWordAfterSelection();
this.wordAfterSelection = wordAfter;

this._editor.selection.select(startOffset, endOffset);
this.wordAfterSelection = this._getWordAfterSelection();
if (lineAfter.trim() === lineBefore.trim()) {
// Handle a syncfusion bug where the previous text is returned as the entire previous line.
// This only happens on the start of a line
this.wordBeforeSelection = "";
}

this._editor.selection.extendToLineStart();
this.isAtStartOfLine = this._editor.selection.text.length === 0;
this.isAtStartOfLine =
this.wordBeforeSelection.length === 0 || startOffset.endsWith(";0");

this._editor.selection.select(startOffset, endOffset);
this._editor.editor.insertBookmark(this.initialSelectionData.bookmarkId);

this.resetSelection();
}

private _getWordAfterSelection(): string {
private _getWordAfterSelection(): string[] {
this._editor.selection.extendToLineEnd();
const startsWithSpace = this._editor.selection.text.startsWith(" ");
const words = this._editor.selection.text
const lineAfter = this._editor.selection.text;
const startsWithSpace = lineAfter.startsWith(" ");
const words = lineAfter
.split(" ")
.slice(0, 2)
.filter(word => word.trim());
const wordAfter = `${startsWithSpace ? " " : ""}${words[0] || ""}`;
return wordAfter;
return [wordAfter, lineAfter];
}

private _getWordBeforeSelection(): string {
private _getWordBeforeSelection(): string[] {
this._editor.selection.extendToLineStart();
const endsWithSpace = this._editor.selection.text.endsWith(" ");
const words = this._editor.selection.text
const lineBefore = this._editor.selection.text;
const endsWithSpace = lineBefore.endsWith(" ");
const words = lineBefore
.split(" ")
.slice(-2)
.filter(word => word.trim());
const wordBefore = `${words.pop() || ""}${endsWithSpace ? " " : ""}`;
return wordBefore;
return [wordBefore, lineBefore];
}

private _highlightSelection(): void {
Expand Down

0 comments on commit b986597

Please sign in to comment.