Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Jun 3, 2024
1 parent fa4c2ff commit 0698c39
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/roosterjs-content-model-core/lib/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
CachedElementHandler,
DomToModelOptionForCreateModel,
AnnounceData,
ExperimentalFeature,
} from 'roosterjs-content-model-types';

/**
Expand Down Expand Up @@ -406,6 +407,14 @@ export class Editor implements IEditor {
core.api.announce(core, announceData);
}

/**
* Check if a given feature is enabled
* @param featureName The name of feature to check
*/
isExperimentalFeatureEnabled(featureName: ExperimentalFeature | string): boolean {
return this.getCore().experimentalFeatures.indexOf(featureName) >= 0;
}

/**
* @returns the current EditorCore object
* @throws a standard Error if there's no core object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class EditPlugin implements EditorPlugin {
private disposer: (() => void) | null = null;
private shouldHandleNextInputEvent = false;
private selectionAfterDelete: DOMSelection | null = null;
private handleEnterKey = false;

/**
* Get name of this plugin
Expand All @@ -42,6 +43,8 @@ export class EditPlugin implements EditorPlugin {
*/
initialize(editor: IEditor) {
this.editor = editor;
this.handleEnterKey = this.editor.isExperimentalFeatureEnabled('PersistCache');

if (editor.getEnvironment().isAndroid) {
this.disposer = this.editor.attachDomEvent({
beforeinput: {
Expand Down Expand Up @@ -154,7 +157,9 @@ export class EditPlugin implements EditorPlugin {
break;

case 'Enter':
keyboardEnter(editor, rawEvent);
if (this.handleEnterKey) {
keyboardEnter(editor, rawEvent);
}
break;

default:
Expand Down
7 changes: 7 additions & 0 deletions packages/roosterjs-content-model-types/lib/editor/IEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { DarkColorHandler } from '../context/DarkColorHandler';
import type { TrustedHTMLHandler } from '../parameter/TrustedHTMLHandler';
import type { Rect } from '../parameter/Rect';
import type { EntityState } from '../parameter/FormatContentModelContext';
import type { ExperimentalFeature } from './ExperimentalFeature';

/**
* An interface of Editor, built on top of Content Model
Expand Down Expand Up @@ -227,4 +228,10 @@ export interface IEditor {
* @param announceData Data to announce
*/
announce(announceData: AnnounceData): void;

/**
* Check if a given feature is enabled
* @param featureName The name of feature to check
*/
isExperimentalFeatureEnabled(featureName: ExperimentalFeature | string): boolean;
}

0 comments on commit 0698c39

Please sign in to comment.