File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -395,14 +395,21 @@ export class Caret {
395395 isDirectionReversed : boolean ;
396396 } ) : { left : number ; top : number ; width : number } {
397397 const letters = options . word ?. qsa ( "letter" ) ;
398- let letter ;
399- if ( ! letters ?. length || ! ( letter = letters [ options . letterIndex ] ) ) {
400- // maybe we should return null here instead of throwing
398+
399+ if ( letters . length === 0 ) {
401400 throw new Error (
402401 "Caret getTargetPositionAndWidth: no letters found in word" ,
403402 ) ;
404403 }
405404
405+ let letter = letters [ options . letterIndex ] ?? letters [ letters . length - 1 ] ;
406+
407+ if ( ! letter ) {
408+ throw new Error (
409+ `Caret getTargetPositionAndWidth: letter not found for index ${ options . letterIndex } ` ,
410+ ) ;
411+ }
412+
406413 if ( caretDebug ) {
407414 if ( this . id === "paceCaret" ) {
408415 for ( const l of document . querySelectorAll ( ".word letter" ) ) {
You can’t perform that action at this time.
0 commit comments