Skip to content

Commit

Permalink
Merge pull request #204 from jrmd/fix/highlight-error
Browse files Browse the repository at this point in the history
Fix an issue where highlighting a format would error
  • Loading branch information
dkotter authored Jul 12, 2023
2 parents c32000a + 5ffb1a1 commit b381105
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,22 @@ registerFormatType( type, {
( char ) => {
const newValue = {
...value,
// duplicate the format at the value start to ensure the
// formats array is the correct size and formatted correctly.
formats: value.formats.splice(
value.start,
0,
value.formats.at( value.start )
),
// grab the format at the start position,
// if it is undefined then use an empty array.
formats: value.formats.at( value.start )
? [ value.formats.at( value.start ) ]
: [],
text: char.char,
};

onChange( insert( value, newValue ) );
onChange(
insert(
value,
newValue,
newValue.start,
newValue.end
)
);
}
}
categoryNames={ {
Expand Down

0 comments on commit b381105

Please sign in to comment.