Skip to content

Commit

Permalink
Fix "constructor" triggers auto list issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Jun 11, 2024
1 parent a0f32c6 commit 597341b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function getListTypeStyle(
listMarkerSegment.segmentType == 'Text'
) {
const listMarker = listMarkerSegment.text.trim();
const bulletType = bulletListType[listMarker];
const bulletType = bulletListType.get(listMarker);

if (bulletType && shouldSearchForBullet) {
return { listType: 'UL', styleType: bulletType };
Expand Down Expand Up @@ -117,16 +117,16 @@ const getPreviousListStyle = (list?: ContentModelListItem) => {
}
};

const bulletListType: Record<string, number> = {
'*': BulletListType.Disc,
'-': BulletListType.Dash,
'--': BulletListType.Square,
'->': BulletListType.LongArrow,
'-->': BulletListType.DoubleLongArrow,
'=>': BulletListType.UnfilledArrow,
'>': BulletListType.ShortArrow,
'—': BulletListType.Hyphen,
};
const bulletListType: Map<string, number> = new Map<string, number>([
['*', BulletListType.Disc],
['-', BulletListType.Dash],
['--', BulletListType.Square],
['->', BulletListType.LongArrow],
['-->', BulletListType.DoubleLongArrow],
['=>', BulletListType.UnfilledArrow],
['>', BulletListType.ShortArrow],
['—', BulletListType.Hyphen],
]);

const isNewList = (listMarker: string) => {
const marker = listMarker.replace(/[^\w\s]/g, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type {
ShallowMutableContentModelParagraph,
} from 'roosterjs-content-model-types';

const FRACTIONS: Record<string, string> = {
'1/2': '½',
'1/4': '¼',
'3/4': '¾',
};
const FRACTIONS: Map<string, string> = new Map<string, string>([
['1/2', '½'],
['1/4', '¼'],
['3/4', '¾'],
]);

/**
* @internal
Expand All @@ -20,11 +20,13 @@ export function transformFraction(
context: FormatContentModelContext
): boolean {
const fraction = previousSegment.text.split(' ').pop()?.trim();
if (fraction && FRACTIONS[fraction]) {
const text = fraction ? FRACTIONS.get(fraction) : undefined;

if (fraction && text) {
const textLength = previousSegment.text.length - 1;
const textIndex = textLength - fraction.length;
const textSegment = splitTextSegment(previousSegment, paragraph, textIndex, textLength);
textSegment.text = FRACTIONS[fraction];
textSegment.text = text;

context.canUndoByBackspace = true;
return true;
Expand Down

0 comments on commit 597341b

Please sign in to comment.