Skip to content

TextEditorMask: Refactor and improve typing#32572

Open
marker-dao wants to merge 4 commits intoDevExpress:26_1from
marker-dao:26_1_texteditor_masks
Open

TextEditorMask: Refactor and improve typing#32572
marker-dao wants to merge 4 commits intoDevExpress:26_1from
marker-dao:26_1_texteditor_masks

Conversation

@marker-dao
Copy link
Contributor

No description provided.

@marker-dao marker-dao force-pushed the 26_1_texteditor_masks branch from 623f3c1 to 44757c5 Compare February 13, 2026 15:41
@marker-dao marker-dao marked this pull request as ready for review February 13, 2026 15:41
@marker-dao marker-dao requested a review from a team as a code owner February 13, 2026 15:41
Copilot AI review requested due to automatic review settings February 13, 2026 15:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the TextEditorMask component and related files to improve TypeScript typing and code quality. The changes include converting relative imports to @ts/ path aliases, adding explicit type annotations, improving null/undefined handling with optional chaining, and refactoring various methods for better type safety.

Changes:

  • Migrated imports from relative paths (e.g., ./m_text_editor.base) to @ts/ui/ path aliases for consistency with codebase conventions
  • Added comprehensive type annotations for function parameters, return types, and class properties
  • Refactored method implementations to use modern TypeScript patterns (optional chaining, nullish coalescing)
  • Improved typing for mask rule classes (BaseMaskRule, MaskRule, StubMaskRule, EmptyMaskRule) with explicit interfaces and type parameters

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
m_text_editor.mask.ts Main component with improved typing, refactored key handlers, and better null handling
m_text_editor.mask.strategy.ts Strategy class with typed method overloads and improved event handler signatures
m_text_editor.mask.rule.ts Mask rule classes with new type definitions (HandlingArgs, AllowedChars) and explicit return types

marker dao ® added 2 commits February 13, 2026 17:04
Copilot AI review requested due to automatic review settings February 13, 2026 16:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.


this._renderValue();
this._caret(caret);
this._caret(currentCaret);
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential bug: When _caret() returns undefined, this method will call this._caret(undefined), which may not properly restore the caret position. The method should handle the case where caret parameter is not provided and this._caret() returns undefined. Consider either skipping the caret restoration when it's undefined, or providing a default caret position.

Suggested change
this._caret(currentCaret);
if (currentCaret) {
this._caret(currentCaret);
}

Copilot uses AI. Check for mistakes.
this.editor._maskKeyHandler(event, (): Promise<string> => {
const text = getClipboardText(event, selectedText);

return text as unknown as Promise<string>;
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type mismatch: The function is declared to return Promise<string> but getClipboardText likely returns a string (not a Promise). The type cast as unknown as Promise<string> is forcing an incorrect type. According to the signature of _maskKeyHandler, the keyHandler parameter should return Promise<string> | undefined. If getClipboardText returns a synchronous string, this should either be wrapped in Promise.resolve() or the return type should be undefined with the actual clipboard handling done synchronously.

Suggested change
return text as unknown as Promise<string>;
return Promise.resolve(text);

Copilot uses AI. Check for mistakes.
Comment on lines +486 to 487
_handleKey(key: string, direction: CaretDirection): void {
this._direction(direction || FORWARD_DIRECTION);
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type inconsistency: The _handleKey method signature declares direction as a required parameter of type CaretDirection, but the implementation uses direction || FORWARD_DIRECTION which suggests it can be undefined/falsy. The signature should be changed to direction?: CaretDirection to match the actual usage, or callers should always provide the direction explicitly. Currently, line 239 in m_text_editor.mask.strategy.ts calls _handleKey with only one argument.

Suggested change
_handleKey(key: string, direction: CaretDirection): void {
this._direction(direction || FORWARD_DIRECTION);
_handleKey(key: string, direction?: CaretDirection): void {
this._direction(direction ?? FORWARD_DIRECTION);

Copilot uses AI. Check for mistakes.

if (handled) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
handled.then(raiseInputEvent);
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling: The promise returned by keyHandler() is not being awaited and has no error handling. If the promise rejects, it will result in an unhandled promise rejection. Consider either awaiting this promise with proper error handling or using .catch() to handle potential errors. The eslint disable comment indicates this is a known issue but doesn't resolve the underlying problem.

Suggested change
handled.then(raiseInputEvent);
handled
.then(raiseInputEvent)
.catch(() => { /* prevent unhandled promise rejections */ });

Copilot uses AI. Check for mistakes.
Comment on lines +238 to 239
// @ts-expect-error ts-expect-error
editor._handleKey(EMPTY_CHAR);
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing parameter: This call to _handleKey is missing the second parameter direction. The method signature requires direction: CaretDirection (though the implementation treats it as optional with a fallback). Either update the call to pass an explicit direction (likely 'forward'), or update the method signature in m_text_editor.mask.ts to make the parameter optional.

Suggested change
// @ts-expect-error ts-expect-error
editor._handleKey(EMPTY_CHAR);
editor._handleKey(EMPTY_CHAR, 'forward');

Copilot uses AI. Check for mistakes.
Comment on lines +259 to +263
_parseMaskRule(index: number): EmptyMaskRule | StubMaskRule | MaskRule | undefined {
const { mask } = this.option();
// @ts-expect-error ts-error

if (!mask) {
return undefined;
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type inconsistency: The _parseMaskRule method can return undefined (line 263), but the class property _maskRulesChain is typed to accept null (line 80). Additionally, line 222 sets it to null. For consistency, either change the return type to include null instead of undefined, or update the property type and line 222 to use undefined. TypeScript treats null and undefined as distinct types, so this mismatch could cause type errors.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants