Skip to content

Commit

Permalink
fix: shortcuts with special characters when having flexible word starts
Browse files Browse the repository at this point in the history
  • Loading branch information
noam-sc committed Sep 22, 2024
1 parent 2bd1d31 commit 1fbbf25
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,16 @@ export default class EnhancedSymbolsPrettifier extends Plugin {
let sequence = '';
for (let i = cursor.ch - 1; i >= 0; i--) {
if (this.isWordStart(line, i)) {
const excludeWhitespace = i + 1;
from = excludeWhitespace;
sequence = line.slice(excludeWhitespace, cursor.ch);
break;
const excludeWordStartIndex = i + 1;
from = excludeWordStartIndex;
sequence = line.slice(excludeWordStartIndex, cursor.ch);
if ((this.settings.replacements[sequence] && !this.settings.replacements[sequence].disabled) || this.isSpaceCharacter(line, i)) {
break;
} else if (i === 0) {
from = i;
sequence = line.slice(i, cursor.ch);
break;
}
} else if (i === 0) {
from = i;
sequence = line.slice(i, cursor.ch);
Expand Down Expand Up @@ -300,7 +306,11 @@ export default class EnhancedSymbolsPrettifier extends Plugin {
}

private isWordStart(line: string, i: number) {
return line.charAt(i) === ' ' || (this.settings.flexibleWordsStart && FLEXIBLE_WORDS_START.includes(line.charAt(i)));
return this.isSpaceCharacter(line, i) || (this.settings.flexibleWordsStart && FLEXIBLE_WORDS_START.includes(line.charAt(i)));
}

private isSpaceCharacter(line: string, i: number) {
return line.charAt(i) === ' ';
}

private isWordEnd(event: KeyboardEvent, isSpacebar: boolean) {
Expand Down

0 comments on commit 1fbbf25

Please sign in to comment.