1e41f4b71Sopenharmony_ci# SelectionMenu 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThe context menu on selection is a component that can be bound to the **RichEditor** component through [bindSelectionMenu](./ts-basic-components-richeditor.md#attributes). It is recommended that this menu be displayed by right-clicking or by selecting text with a mouse device. This component cannot be used independently. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci> **NOTE** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> This component is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## Modules to Import 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ciimport { SelectionMenu, EditorMenuOptions, ExpandedMenuOptions, EditorEventInfo, SelectionMenuOptions } from '@kit.ArkUI' 16e41f4b71Sopenharmony_ci``` 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## Child Components 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciNot supported 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci## SelectionMenu 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciSelectionMenu(options: SelectionMenuOptions) 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciDefines a custom context menu on selection. When the input parameter is empty, the sizes of the menu and its content area are 0. In this case, no context menu is displayed when the bound [RichEditor](ts-basic-components-richeditor.md) component is right-clicked. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**Decorator**: @Builder 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**Parameters** 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 37e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 38e41f4b71Sopenharmony_ci| options | [SelectionMenuOptions](#selectionmenuoptions) | Yes| Options of the context menu on selection.| 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci## SelectionMenuOptions 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ciDefines the options of the context menu on selection. 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 49e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 50e41f4b71Sopenharmony_ci| editorMenuOptions | Array<[EditorMenuOptions](#editormenuoptions)> | No| Edit menu.<br>If **editorMenuOptions** is not set, the edit menu is not displayed.<br>When both **action** and **builder** in **EditorMenuOptions** are configured, clicking the edit icon will trigger both.<br>By default, the context menu is not closed when the edit menu icon is clicked. You can configure **closeSelectionMenu** of **RichEditorController** in **action** to enable the menu to be closed.| 51e41f4b71Sopenharmony_ci| expandedMenuOptions | Array<[ExpandedMenuOptions](#expandedmenuoptions)> | No| Expanded drop-down menu options.<br>If this parameter is left empty, the expanded drop-down menu is not displayed.<br>The options configured for **ExpandedMenuOptions** are displayed in the **More** menu option, and clicking **More** shows the expanded drop-down menu.| 52e41f4b71Sopenharmony_ci| controller | [RichEditorController](ts-basic-components-richeditor.md#richeditorcontroller) | No| Rich text editor controller. If **controller** is set, the default system menu (including the cut, copy, and paste options) is displayed, and the preset menu features are provided.<br>If **controller** is left empty, the **More** menu option is not displayed. If **expandedMenuOptions** is not empty, the expanded drop-down menu is displayed.<br>By default, only rich text can be copied and pasted. To support mixture of text and imagery, define custom **onCopy** and **onPaste** APIs . If a custom **onCopy** \| **onPaste** API is defined, the default copy and paste feature is ineffective, and the custom function is called instead.<br>**NOTE**<br> When the preset copy option is selected, the custom context menu on selection is hidden, while the selected text is still highlighted.<br> When the preset select-all option is selected, the custom context menu on selection is hidden, while all text is highlighted.<br> When the preset paste option is selected, the style of the copied text is retained, whether the text is pasted to a blank area or not.<br> When the **copyOptions** attribute of the [RichEditor](ts-basic-components-richeditor.md) component is set to **CopyOptions.None**, the preset copy and cut features are not restricted.| 53e41f4b71Sopenharmony_ci| onCopy | (event?: [EditorEventInfo](#editoreventinfo)) => void | No| Event callback to take the place of the preset copy menu option.<br>It is effective only when the **controller** parameter is set and the preset menu is available.<br>**NOTE**<br> **event** indicates the returned information.| 54e41f4b71Sopenharmony_ci| onPaste | (event?: [EditorEventInfo](#editoreventinfo)) => void | No| Event callback to take the place of the preset paste menu option.<br>It is effective only when the **controller** parameter is set and the preset menu is available.<br>**NOTE**<br> **event** indicates the returned information.| 55e41f4b71Sopenharmony_ci| onCut | (event?: [EditorEventInfo](#editoreventinfo)) => void | No| Event callback to take the place of the preset cut menu option.<br>It is effective only when the **controller** parameter is set and the preset menu is available.<br>**NOTE**<br>**event** indicates the returned information.| 56e41f4b71Sopenharmony_ci| onSelectAll | (event?: [EditorEventInfo](#editoreventinfo)) => void | No| Event callback to take the place of the preset select-all menu option.<br>It is effective only when the **controller** parameter is set and the preset menu is available.<br>**NOTE**<br>**event** indicates the returned information.| 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci## EditorMenuOptions 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ciDescribes the edit menu options. 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 68e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 69e41f4b71Sopenharmony_ci| icon | [ResourceStr](ts-types.md#resourcestr) | Yes| Icon.| 70e41f4b71Sopenharmony_ci| builder | () => void | No| Builder of the custom component displayed upon click. It must be used with @Builder for building the custom component.| 71e41f4b71Sopenharmony_ci| action | () => void | No| Action triggered when the menu option is clicked.| 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci## ExpandedMenuOptions 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ciDescribes the expanded drop-down menu options. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciInherits from [MenuItemOptions](ts-basic-components-menuitem.md#menuitemoptions). 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 85e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 86e41f4b71Sopenharmony_ci| action | () => void | No| Action triggered when the menu option is clicked.| 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci## EditorEventInfo 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciProvides the information about the selected content. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 97e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 98e41f4b71Sopenharmony_ci| content | [RichEditorSelection](ts-basic-components-richeditor.md#richeditorselection) | No| Information about the selected content.| 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci## Attributes 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ciThe [universal attributes](ts-universal-attributes-size.md) are not supported. The default width is 256 vp, and the height is adaptive. 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci## Events 105e41f4b71Sopenharmony_ciThe [universal events](ts-universal-events-click.md) are not supported. 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci## Example 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci```ts 110e41f4b71Sopenharmony_ciimport { SelectionMenu, EditorMenuOptions, ExpandedMenuOptions, EditorEventInfo, SelectionMenuOptions } from '@kit.ArkUI' 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci@Entry 113e41f4b71Sopenharmony_ci@Component 114e41f4b71Sopenharmony_cistruct Index { 115e41f4b71Sopenharmony_ci @State select: boolean = true 116e41f4b71Sopenharmony_ci controller: RichEditorController = new RichEditorController(); 117e41f4b71Sopenharmony_ci options: RichEditorOptions = { controller: this.controller } 118e41f4b71Sopenharmony_ci @State message: string = 'Hello word' 119e41f4b71Sopenharmony_ci @State textSize: number = 30 120e41f4b71Sopenharmony_ci @State fontWeight: FontWeight = FontWeight.Normal 121e41f4b71Sopenharmony_ci @State start: number = -1 122e41f4b71Sopenharmony_ci @State end: number = -1 123e41f4b71Sopenharmony_ci @State visibleValue: Visibility = Visibility.Visible 124e41f4b71Sopenharmony_ci @State colorTransparent: Color = Color.Transparent 125e41f4b71Sopenharmony_ci @State textStyle: RichEditorTextStyle = {} 126e41f4b71Sopenharmony_ci private editorMenuOptions: Array<EditorMenuOptions> = 127e41f4b71Sopenharmony_ci [ 128e41f4b71Sopenharmony_ci { icon: $r("app.media.ic_notepad_textbold"), action: () => { 129e41f4b71Sopenharmony_ci if (this.controller) { 130e41f4b71Sopenharmony_ci let selection = this.controller.getSelection(); 131e41f4b71Sopenharmony_ci let spans = selection.spans 132e41f4b71Sopenharmony_ci spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 133e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 134e41f4b71Sopenharmony_ci let span = item as RichEditorTextSpanResult 135e41f4b71Sopenharmony_ci this.textStyle = span.textStyle 136e41f4b71Sopenharmony_ci let start = span.offsetInSpan[0] 137e41f4b71Sopenharmony_ci let end = span.offsetInSpan[1] 138e41f4b71Sopenharmony_ci let offset = span.spanPosition.spanRange[0] 139e41f4b71Sopenharmony_ci if (this.textStyle.fontWeight != 11) { 140e41f4b71Sopenharmony_ci this.textStyle.fontWeight = FontWeight.Bolder 141e41f4b71Sopenharmony_ci } else { 142e41f4b71Sopenharmony_ci this.textStyle.fontWeight = FontWeight.Normal 143e41f4b71Sopenharmony_ci } 144e41f4b71Sopenharmony_ci this.controller.updateSpanStyle({ 145e41f4b71Sopenharmony_ci start: offset + start, 146e41f4b71Sopenharmony_ci end: offset + end, 147e41f4b71Sopenharmony_ci textStyle: this.textStyle 148e41f4b71Sopenharmony_ci }) 149e41f4b71Sopenharmony_ci } 150e41f4b71Sopenharmony_ci }) 151e41f4b71Sopenharmony_ci } 152e41f4b71Sopenharmony_ci } }, 153e41f4b71Sopenharmony_ci { icon: $r("app.media.ic_notepad_texttilt"), action: () => { 154e41f4b71Sopenharmony_ci if (this.controller) { 155e41f4b71Sopenharmony_ci let selection = this.controller.getSelection(); 156e41f4b71Sopenharmony_ci let spans = selection.spans 157e41f4b71Sopenharmony_ci spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 158e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 159e41f4b71Sopenharmony_ci let span = item as RichEditorTextSpanResult 160e41f4b71Sopenharmony_ci this.textStyle = span.textStyle 161e41f4b71Sopenharmony_ci let start = span.offsetInSpan[0] 162e41f4b71Sopenharmony_ci let end = span.offsetInSpan[1] 163e41f4b71Sopenharmony_ci let offset = span.spanPosition.spanRange[0] 164e41f4b71Sopenharmony_ci if (this.textStyle.fontStyle == FontStyle.Italic) { 165e41f4b71Sopenharmony_ci this.textStyle.fontStyle = FontStyle.Normal 166e41f4b71Sopenharmony_ci } else { 167e41f4b71Sopenharmony_ci this.textStyle.fontStyle = FontStyle.Italic 168e41f4b71Sopenharmony_ci } 169e41f4b71Sopenharmony_ci this.controller.updateSpanStyle({ 170e41f4b71Sopenharmony_ci start: offset + start, 171e41f4b71Sopenharmony_ci end: offset + end, 172e41f4b71Sopenharmony_ci textStyle: this.textStyle 173e41f4b71Sopenharmony_ci }) 174e41f4b71Sopenharmony_ci } 175e41f4b71Sopenharmony_ci }) 176e41f4b71Sopenharmony_ci } 177e41f4b71Sopenharmony_ci } }, 178e41f4b71Sopenharmony_ci { icon: $r("app.media.ic_notepad_underline"), 179e41f4b71Sopenharmony_ci action: () => { 180e41f4b71Sopenharmony_ci if (this.controller) { 181e41f4b71Sopenharmony_ci let selection = this.controller.getSelection(); 182e41f4b71Sopenharmony_ci let spans = selection.spans 183e41f4b71Sopenharmony_ci spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 184e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 185e41f4b71Sopenharmony_ci let span = item as RichEditorTextSpanResult 186e41f4b71Sopenharmony_ci this.textStyle = span.textStyle 187e41f4b71Sopenharmony_ci let start = span.offsetInSpan[0] 188e41f4b71Sopenharmony_ci let end = span.offsetInSpan[1] 189e41f4b71Sopenharmony_ci let offset = span.spanPosition.spanRange[0] 190e41f4b71Sopenharmony_ci if (this.textStyle.decoration) { 191e41f4b71Sopenharmony_ci if (this.textStyle.decoration.type == TextDecorationType.Underline) { 192e41f4b71Sopenharmony_ci this.textStyle.decoration.type = TextDecorationType.None 193e41f4b71Sopenharmony_ci } else { 194e41f4b71Sopenharmony_ci this.textStyle.decoration.type = TextDecorationType.Underline 195e41f4b71Sopenharmony_ci } 196e41f4b71Sopenharmony_ci } else { 197e41f4b71Sopenharmony_ci this.textStyle.decoration = { type: TextDecorationType.Underline, color: Color.Black } 198e41f4b71Sopenharmony_ci } 199e41f4b71Sopenharmony_ci this.controller.updateSpanStyle({ 200e41f4b71Sopenharmony_ci start: offset + start, 201e41f4b71Sopenharmony_ci end: offset + end, 202e41f4b71Sopenharmony_ci textStyle: this.textStyle 203e41f4b71Sopenharmony_ci }) 204e41f4b71Sopenharmony_ci } 205e41f4b71Sopenharmony_ci }) 206e41f4b71Sopenharmony_ci } 207e41f4b71Sopenharmony_ci } 208e41f4b71Sopenharmony_ci }, 209e41f4b71Sopenharmony_ci { icon: $r("app.media.app_icon"), action: () => { 210e41f4b71Sopenharmony_ci }, builder: (): void => this.sliderPanel() }, 211e41f4b71Sopenharmony_ci { icon: $r("app.media.ic_notepad_textcolor"), action: () => { 212e41f4b71Sopenharmony_ci if (this.controller) { 213e41f4b71Sopenharmony_ci let selection = this.controller.getSelection(); 214e41f4b71Sopenharmony_ci let spans = selection.spans 215e41f4b71Sopenharmony_ci spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 216e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 217e41f4b71Sopenharmony_ci let span = item as RichEditorTextSpanResult 218e41f4b71Sopenharmony_ci this.textStyle = span.textStyle 219e41f4b71Sopenharmony_ci let start = span.offsetInSpan[0] 220e41f4b71Sopenharmony_ci let end = span.offsetInSpan[1] 221e41f4b71Sopenharmony_ci let offset = span.spanPosition.spanRange[0] 222e41f4b71Sopenharmony_ci if (this.textStyle.fontColor == Color.Orange || this.textStyle.fontColor == '#FFFFA500') { 223e41f4b71Sopenharmony_ci this.textStyle.fontColor = Color.Black 224e41f4b71Sopenharmony_ci } else { 225e41f4b71Sopenharmony_ci this.textStyle.fontColor = Color.Orange 226e41f4b71Sopenharmony_ci } 227e41f4b71Sopenharmony_ci this.controller.updateSpanStyle({ 228e41f4b71Sopenharmony_ci start: offset + start, 229e41f4b71Sopenharmony_ci end: offset + end, 230e41f4b71Sopenharmony_ci textStyle: this.textStyle 231e41f4b71Sopenharmony_ci }) 232e41f4b71Sopenharmony_ci } 233e41f4b71Sopenharmony_ci }) 234e41f4b71Sopenharmony_ci } 235e41f4b71Sopenharmony_ci } }] 236e41f4b71Sopenharmony_ci private expandedMenuOptions: Array<ExpandedMenuOptions> = 237e41f4b71Sopenharmony_ci [{ startIcon: $r("app.media.icon"), content: 'Dictionary', action: () => { 238e41f4b71Sopenharmony_ci } }, { startIcon: $r("app.media.icon"), content: 'Translate', action: () => { 239e41f4b71Sopenharmony_ci } }, { startIcon: $r("app.media.icon"), content: 'Search', action: () => { 240e41f4b71Sopenharmony_ci } }] 241e41f4b71Sopenharmony_ci private expandedMenuOptions1: Array<ExpandedMenuOptions> = [] 242e41f4b71Sopenharmony_ci private editorMenuOptions1: Array<EditorMenuOptions> = [] 243e41f4b71Sopenharmony_ci private selectionMenuOptions: SelectionMenuOptions = { 244e41f4b71Sopenharmony_ci editorMenuOptions: this.editorMenuOptions, 245e41f4b71Sopenharmony_ci expandedMenuOptions: this.expandedMenuOptions, 246e41f4b71Sopenharmony_ci controller: this.controller, 247e41f4b71Sopenharmony_ci onCut: (event?: EditorEventInfo) => { 248e41f4b71Sopenharmony_ci if (event && event.content) { 249e41f4b71Sopenharmony_ci event.content.spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 250e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 251e41f4b71Sopenharmony_ci let span = item as RichEditorTextSpanResult 252e41f4b71Sopenharmony_ci console.info('test cut' + span.value) 253e41f4b71Sopenharmony_ci console.info('test start ' + span.offsetInSpan[0] + ' end: ' + span.offsetInSpan[1]) 254e41f4b71Sopenharmony_ci } 255e41f4b71Sopenharmony_ci }) 256e41f4b71Sopenharmony_ci } 257e41f4b71Sopenharmony_ci }, 258e41f4b71Sopenharmony_ci onPaste: (event?: EditorEventInfo) => { 259e41f4b71Sopenharmony_ci if (event && event.content) { 260e41f4b71Sopenharmony_ci event.content.spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 261e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 262e41f4b71Sopenharmony_ci let span = item as RichEditorTextSpanResult 263e41f4b71Sopenharmony_ci console.info('test onPaste' + span.value) 264e41f4b71Sopenharmony_ci console.info('test start ' + span.offsetInSpan[0] + ' end: ' + span.offsetInSpan[1]) 265e41f4b71Sopenharmony_ci } 266e41f4b71Sopenharmony_ci }) 267e41f4b71Sopenharmony_ci } 268e41f4b71Sopenharmony_ci }, 269e41f4b71Sopenharmony_ci onCopy: (event?: EditorEventInfo) => { 270e41f4b71Sopenharmony_ci if (event && event.content) { 271e41f4b71Sopenharmony_ci event.content.spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 272e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 273e41f4b71Sopenharmony_ci let span = item as RichEditorTextSpanResult 274e41f4b71Sopenharmony_ci console.info('test cut' + span.value) 275e41f4b71Sopenharmony_ci console.info('test start ' + span.offsetInSpan[0] + ' end: ' + span.offsetInSpan[1]) 276e41f4b71Sopenharmony_ci } 277e41f4b71Sopenharmony_ci }) 278e41f4b71Sopenharmony_ci } 279e41f4b71Sopenharmony_ci }, 280e41f4b71Sopenharmony_ci onSelectAll: (event?: EditorEventInfo) => { 281e41f4b71Sopenharmony_ci if (event && event.content) { 282e41f4b71Sopenharmony_ci event.content.spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 283e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 284e41f4b71Sopenharmony_ci let span = item as RichEditorTextSpanResult 285e41f4b71Sopenharmony_ci console.info('test onPaste' + span.value) 286e41f4b71Sopenharmony_ci console.info('test start ' + span.offsetInSpan[0] + ' end: ' + span.offsetInSpan[1]) 287e41f4b71Sopenharmony_ci } 288e41f4b71Sopenharmony_ci }) 289e41f4b71Sopenharmony_ci } 290e41f4b71Sopenharmony_ci } 291e41f4b71Sopenharmony_ci } 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci @Builder sliderPanel() { 294e41f4b71Sopenharmony_ci Column() { 295e41f4b71Sopenharmony_ci Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 296e41f4b71Sopenharmony_ci Text('A').fontSize(15) 297e41f4b71Sopenharmony_ci Slider({ value: this.textSize, step: 10, style: SliderStyle.InSet }) 298e41f4b71Sopenharmony_ci .width(210) 299e41f4b71Sopenharmony_ci .onChange((value: number, mode: SliderChangeMode) => { 300e41f4b71Sopenharmony_ci if (this.controller) { 301e41f4b71Sopenharmony_ci let selection = this.controller.getSelection(); 302e41f4b71Sopenharmony_ci if (mode == SliderChangeMode.End) { 303e41f4b71Sopenharmony_ci if (this.textSize == undefined) { 304e41f4b71Sopenharmony_ci this.textSize = 0 305e41f4b71Sopenharmony_ci } 306e41f4b71Sopenharmony_ci let spans = selection.spans 307e41f4b71Sopenharmony_ci spans.forEach((item: RichEditorTextSpanResult | RichEditorImageSpanResult, index) => { 308e41f4b71Sopenharmony_ci if (typeof (item as RichEditorTextSpanResult)['textStyle'] != 'undefined') { 309e41f4b71Sopenharmony_ci this.textSize = Math.max(this.textSize, (item as RichEditorTextSpanResult).textStyle.fontSize) 310e41f4b71Sopenharmony_ci } 311e41f4b71Sopenharmony_ci }) 312e41f4b71Sopenharmony_ci } 313e41f4b71Sopenharmony_ci if (mode == SliderChangeMode.Moving || mode == SliderChangeMode.Click) { 314e41f4b71Sopenharmony_ci this.start = selection.selection[0] 315e41f4b71Sopenharmony_ci this.end = selection.selection[1] 316e41f4b71Sopenharmony_ci this.textSize = value 317e41f4b71Sopenharmony_ci this.controller.updateSpanStyle({ 318e41f4b71Sopenharmony_ci start: this.start, 319e41f4b71Sopenharmony_ci end: this.end, 320e41f4b71Sopenharmony_ci textStyle: { fontSize: this.textSize } 321e41f4b71Sopenharmony_ci }) 322e41f4b71Sopenharmony_ci } 323e41f4b71Sopenharmony_ci } 324e41f4b71Sopenharmony_ci }) 325e41f4b71Sopenharmony_ci Text('A').fontSize(20).fontWeight(FontWeight.Medium) 326e41f4b71Sopenharmony_ci }.borderRadius($r('sys.float.ohos_id_corner_radius_card')) 327e41f4b71Sopenharmony_ci } 328e41f4b71Sopenharmony_ci .shadow(ShadowStyle.OUTER_DEFAULT_MD) 329e41f4b71Sopenharmony_ci .backgroundColor(Color.White) 330e41f4b71Sopenharmony_ci .borderRadius($r('sys.float.ohos_id_corner_radius_card')) 331e41f4b71Sopenharmony_ci .padding(15) 332e41f4b71Sopenharmony_ci .height(48) 333e41f4b71Sopenharmony_ci } 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci @Builder 336e41f4b71Sopenharmony_ci MyMenu() { 337e41f4b71Sopenharmony_ci Column() { 338e41f4b71Sopenharmony_ci SelectionMenu(this.selectionMenuOptions) 339e41f4b71Sopenharmony_ci } 340e41f4b71Sopenharmony_ci .width(256) 341e41f4b71Sopenharmony_ci .backgroundColor(Color.Transparent) 342e41f4b71Sopenharmony_ci } 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci @Builder 345e41f4b71Sopenharmony_ci MyMenu2() { 346e41f4b71Sopenharmony_ci Column() { 347e41f4b71Sopenharmony_ci SelectionMenu({ 348e41f4b71Sopenharmony_ci editorMenuOptions: this.editorMenuOptions, 349e41f4b71Sopenharmony_ci expandedMenuOptions: this.expandedMenuOptions1, 350e41f4b71Sopenharmony_ci controller: this.controller, 351e41f4b71Sopenharmony_ci }) 352e41f4b71Sopenharmony_ci } 353e41f4b71Sopenharmony_ci .width(256) 354e41f4b71Sopenharmony_ci .backgroundColor(Color.Transparent) 355e41f4b71Sopenharmony_ci } 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci @Builder 358e41f4b71Sopenharmony_ci MyMenu3() { 359e41f4b71Sopenharmony_ci Column() { 360e41f4b71Sopenharmony_ci SelectionMenu({ 361e41f4b71Sopenharmony_ci editorMenuOptions: this.editorMenuOptions1, 362e41f4b71Sopenharmony_ci expandedMenuOptions: this.expandedMenuOptions, 363e41f4b71Sopenharmony_ci controller: this.controller, 364e41f4b71Sopenharmony_ci }) 365e41f4b71Sopenharmony_ci } 366e41f4b71Sopenharmony_ci .width(256) 367e41f4b71Sopenharmony_ci .backgroundColor(Color.Transparent) 368e41f4b71Sopenharmony_ci } 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci build() { 371e41f4b71Sopenharmony_ci Column() { 372e41f4b71Sopenharmony_ci Button("SetSelection") 373e41f4b71Sopenharmony_ci .onClick((event: ClickEvent) => { 374e41f4b71Sopenharmony_ci if (this.controller) { 375e41f4b71Sopenharmony_ci this.controller.setSelection(0, 2) 376e41f4b71Sopenharmony_ci } 377e41f4b71Sopenharmony_ci }) 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci RichEditor(this.options) 380e41f4b71Sopenharmony_ci .onReady(() => { 381e41f4b71Sopenharmony_ci this.controller.addTextSpan(this.message, { style: { fontColor: Color.Orange, fontSize: 30 } }) 382e41f4b71Sopenharmony_ci this.controller.addTextSpan(this.message, { style: { fontColor: Color.Black, fontSize: 25 } }) 383e41f4b71Sopenharmony_ci }) 384e41f4b71Sopenharmony_ci .onSelect((value: RichEditorSelection) => { 385e41f4b71Sopenharmony_ci if (value.selection[0] == -1 && value.selection[1] == -1) { 386e41f4b71Sopenharmony_ci return 387e41f4b71Sopenharmony_ci } 388e41f4b71Sopenharmony_ci this.start = value.selection[0] 389e41f4b71Sopenharmony_ci this.end = value.selection[1] 390e41f4b71Sopenharmony_ci }) 391e41f4b71Sopenharmony_ci .bindSelectionMenu(RichEditorSpanType.TEXT, this.MyMenu3(), RichEditorResponseType.RIGHT_CLICK) 392e41f4b71Sopenharmony_ci .bindSelectionMenu(RichEditorSpanType.TEXT, this.MyMenu2(), RichEditorResponseType.SELECT) 393e41f4b71Sopenharmony_ci .borderWidth(1) 394e41f4b71Sopenharmony_ci .borderColor(Color.Red) 395e41f4b71Sopenharmony_ci .width(200) 396e41f4b71Sopenharmony_ci .height(200) 397e41f4b71Sopenharmony_ci } 398e41f4b71Sopenharmony_ci } 399e41f4b71Sopenharmony_ci} 400e41f4b71Sopenharmony_ci``` 401e41f4b71Sopenharmony_ci> **NOTE** 402e41f4b71Sopenharmony_ci> 403e41f4b71Sopenharmony_ci> Icons in bold and italics are not preset in the system. The sample code uses the default icons. You need to replace the icons in **editorMenuOptions** with the desired icons. 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci 406