Skip to content

Commit

Permalink
Fix autocomplete character selection (#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Onokaev authored Jan 12, 2023
1 parent 1707286 commit b95426f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/modules/suggestions/utilities/delimiters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@ const delimiters: Delimiters = {
function getLastDelimiterInUrl(url: string): Delimiter {
const symbols = Object.values(delimiters);
symbols.forEach(key => {
key.index = url.lastIndexOf(key.symbol);
const prevCharIndex = url.lastIndexOf(key.symbol) - 1;
key.index = isSecondLastCharADelimiter(url.charAt(prevCharIndex)) ? url.lastIndexOf(key.symbol)-1 :
url.lastIndexOf(key.symbol);
});

return symbols.reduce((prev, current) => (prev.index > current.index) ? prev : current);
}

const isSecondLastCharADelimiter = (prevCharacter: string): boolean => {
const symbols = Object.values(delimiters);
let isSecondLastCharDelimiter = false;
for(const symbol of symbols ){
if(prevCharacter === symbol.symbol){
isSecondLastCharDelimiter = true;
break;
}
}
return isSecondLastCharDelimiter;
}

export { delimiters, getLastDelimiterInUrl }

0 comments on commit b95426f

Please sign in to comment.