Skip to content

Commit

Permalink
fix: inline format error (#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Feb 18, 2024
1 parent 9f06ed4 commit a3f1e9b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
65 changes: 29 additions & 36 deletions packages/docs/src/commands/commands/inline-format.command.ts
Expand Up @@ -258,52 +258,45 @@ function getReverseFormatValueInSelection(
} else if (ed <= startOffset!) {
ti++;
} else {
if (ts?.[key] == null) {
if (/bl|it/.test(key)) {
return BooleanNumber.TRUE;
}
if (/bl|it/.test(key)) {
return ts?.[key] === BooleanNumber.TRUE ? BooleanNumber.FALSE : BooleanNumber.TRUE;
}

if (/ul|st/.test(key)) {
return {
if (/ul|st/.test(key)) {
return isTextDecoration(ts?.[key]) && (ts?.[key] as ITextDecoration).s === BooleanNumber.TRUE
? {
s: BooleanNumber.FALSE,
}
: {
s: BooleanNumber.TRUE,
};
}
}

if (/va/.test(key)) {
return preCommandId === SetInlineFormatSubscriptCommand.id
? BaselineOffset.SUBSCRIPT
if (/va/.test(key)) {
if (preCommandId === SetInlineFormatSubscriptCommand.id) {
return ts?.[key] === BaselineOffset.SUBSCRIPT
? BaselineOffset.NORMAL
: BaselineOffset.SUBSCRIPT;
} else {
return ts?.[key] === BaselineOffset.SUPERSCRIPT
? BaselineOffset.NORMAL
: BaselineOffset.SUPERSCRIPT;
}
}

// Add second ?. in just use fix TS checker.
if (isTextDecoration(ts?.[key]) && (ts?.[key] as ITextDecoration).s === BooleanNumber.FALSE) {
return {
s: BooleanNumber.TRUE,
};
}

if (preCommandId === SetInlineFormatSubscriptCommand.id && ts?.[key] !== BaselineOffset.SUBSCRIPT) {
return BaselineOffset.SUBSCRIPT;
}

if (preCommandId === SetInlineFormatSuperscriptCommand.id && ts?.[key] !== BaselineOffset.SUPERSCRIPT) {
return BaselineOffset.SUPERSCRIPT;
}

if (ts?.[key] === BooleanNumber.FALSE) {
return BooleanNumber.TRUE;
}

ti++;
}
}

return /bl|it/.test(key)
? BooleanNumber.FALSE
: /ul|st/.test(key)
? {
s: BooleanNumber.FALSE,
}
: BaselineOffset.NORMAL;
if (/bl|it/.test(key)) {
return BooleanNumber.TRUE;
} else if (/ul|st/.test(key)) {
return {
s: BooleanNumber.TRUE,
};
} else {
return preCommandId === SetInlineFormatSubscriptCommand.id
? BaselineOffset.SUBSCRIPT
: BaselineOffset.SUPERSCRIPT;
}
}
4 changes: 2 additions & 2 deletions packages/docs/src/commands/mutations/core-editing.mutation.ts
Expand Up @@ -90,7 +90,7 @@ export const RichTextEditingMutation: IMutation<IRichTextEditingMutationParams,
segmentViewModel.reset(segmentDocumentDataModel);

// Step 3: Update cursor & selection.
// make sure update cursor & selection after doc skeleton is calculated.
// Make sure update cursor & selection after doc skeleton is calculated.
if (!noNeedSetTextRange && textRanges) {
queueMicrotask(() => {
textSelectionManagerService.replaceTextRanges(textRanges);
Expand All @@ -113,7 +113,7 @@ export const RichTextEditingMutation: IMutation<IRichTextEditingMutationParams,
},
};

// Handle ime input.
// Handle IME input.
if (isCompositionEnd) {
const historyParams = imeInputManagerService.fetchComposedUndoRedoMutationParams();

Expand Down

0 comments on commit a3f1e9b

Please sign in to comment.