Skip to content

Commit

Permalink
Add background to maintain selection highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
francismengMS committed May 15, 2024
1 parent eea61b8 commit ef023d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'roosterjs-content-model-dom';
import type { SetContentModel } from 'roosterjs-content-model-types';

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

/**
Expand All @@ -19,7 +19,7 @@ const SelectionSelector = '.' + SelectionClassName;
export const setContentModel: SetContentModel = (core, model, option, onNodeCreated) => {
const editorContext = core.api.createEditorContext(core, true /*saveIndex*/);

if (core.lifecycle.shadowEditFragment) {
if (option?.shouldMaintainSelection) {
editorContext.selectionClassName = SelectionClassName;
core.api.setEditorStyle(core, SelectionClassName, 'background-color: #ddd!important', [
SelectionSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ export interface ModelToDomOption {
* When set to true, selection from content model will not be applied
*/
ignoreSelection?: boolean;

/**
* When set to true, selection will be maintained on text even if cursor has moved away from editor.
*/
shouldMaintainSelection?: boolean;
}

0 comments on commit ef023d1

Please sign in to comment.