Skip to content

Commit

Permalink
ShadowEdit selection
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong committed Apr 4, 2024
1 parent 1377277 commit 53e94b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
} from 'roosterjs-content-model-dom';
import type { SetContentModel } from 'roosterjs-content-model-types';

const SelectionClassName = '__shadowEditSelection';
const SelectionSelector = '.' + SelectionClassName;

/**
* @internal
* Set content with content model
Expand All @@ -15,6 +18,16 @@ import type { SetContentModel } from 'roosterjs-content-model-types';
*/
export const setContentModel: SetContentModel = (core, model, option, onNodeCreated) => {
const editorContext = core.api.createEditorContext(core, true /*saveIndex*/);

if (core.lifecycle.shadowEditFragment) {
editorContext.selectionClassName = SelectionClassName;
core.api.setEditorStyle(core, SelectionClassName, 'background-color: #ddd!important', [
SelectionSelector,
]);
} else {
core.api.setEditorStyle(core, SelectionClassName, null /*rule*/);
}

const modelToDomContext = option
? createModelToDomContext(
editorContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ export function handleSegmentCommon(

applyFormat(containerNode, context.formatAppliers.elementBasedSegment, segment.format, context);

if (segment.isSelected && context.selectionClassName) {
containerNode.className = context.selectionClassName;
}

context.onNodeCreated?.(segment, segmentNode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ export interface EditorContext {
* Root Font size in Px.
*/
rootFontSize?: number;

selectionClassName?: string;
}

0 comments on commit 53e94b0

Please sign in to comment.