tencent cloud

All product documents
Tencent Cloud Super App as a Service
Rich Text
Last updated: 2025-03-20 18:01:56
Rich Text
Last updated: 2025-03-20 18:01:56

EditorContext

Feature Description: An EditorContext instance can be obtained through wx.createSelectorQuery. The EditorContext is bound to an editor component through an id, thereby manipulating the corresponding editor component.

.blur

This method is used via EditorContext.blur(Object object).
Feature Description: The editor loses focus, concurrently retracting the keyboard.
Parameter and Description: Object
Attribute
Type
Default value
Required
Description
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

.clear

This method is used via EditorContext.clear(Object object)
Feature Description: Empties the content of the editor.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

.format

This method is used via EditorContext.format(string name, string value).
Feature Description: Modifies the style.
Parameter and Description:
string name, the attribute;
string value, value.
A list of styles that support the setting:
name
value
bold
-
italic
-
underline
-
strike
-
ins
-
script
sub / super
header
H1 / H2 / h3 / H4 / h5 / H6
align
left / center / right / justify
direction
rtl
indent
-1 / +1
list
ordered / bullet / check
color
hex color
backgroundColor
hex color
margin/marginTop/marginBottom/marginLeft/marginRight
css style
padding/paddingTop/paddingBottom/paddingLeft/paddingRight
css style
font/fontSize/fontStyle/fontVariant/fontWeight/fontFamily
css style
lineHeight
css style
letterSpacing
css style
textDecoration
css style
textIndent
css style
wordWrap
css style
wordBreak
css style
whiteSpace
css style
Setting a style on a selection that has already been styled removes the style. css style represents the allowed values specified in css.

.getContents

This method is used via EditorContext.getContents().
Feature Description: Gets the content of the editor.
Parameter and Description: Object.

.getSelectionText

This method is used via EditorContext.getSelectionText(Object object).
Feature Description: Gets the plain text content within the selected area of the editor. When the editor loses focus or a section is not selected, the returned content is empty.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
object.success callback function
Arguments Object.res
Attribute
Type
Description
text
string
Plain text content

.insertDivider

This method is used via EditorContext.insertDivider(Object object)
Feature Description: Inserts a divider.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

.insertlmage

This method is used via EditorContext.insertlmage(Object object).
Feature Description: Inserts an image.
When the address is a temporary file, the HTML format content of the editor obtained adds the attribute data-local to the tag, and the data-local field is added to the image attributes attribute in the data format content, which is the address of the temporary file passed in.
Developers can opt to upload images to the server during the submission phase, replacing them once the network address is obtained. For HTML content, the src value should be replaced, while for delta content, the insert {image: abc} value should be substituted.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
src
string
-
Yes
Image address, only http(s), base64, temp files are supported.
nowrap
boolean
false
No
Whether to automatically line feed after inserting a picture, default line feed
alt
string
-
No
Alternative text when images cannot be displayed
width
string
-
No
Image width (pixels/percentage)
height
string
-
No
Image height (pixels/percentage)
extClass
string
-
No
Class name added to the image img tag
data
Object
-
No
data is serialized as name=value;name1=value2 and hooked to the attribute data-custom.
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Sample code
this.editorCtx.insertImage({
src: 'xx',
width: '100px',
height: '50px',
extClass: className
})

.insertText

This method is used via EditorContext.insertText(Object object).
Feature Description: Overwrites the current selected area, setting a segment of text.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
text
string
-
No
Text Content
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

.redo

This method is used via EditorContext.redo(Object object).
Feature Description: Restoration.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

.removeFormat

This method is used via EditorContext.removeFormat(Object object).
Feature Description: Clears the style of the current selected area.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

.scrolllntoView

This method is used via EditorContext.scrollIntoView().
Feature Description: Enables the editor cursor to scroll within the visible area of the window.

.setContents

This method is used via EditorContext.setContents(Object object).
Feature Description: Initializes the editor content. When both html and delta exist, only delta takes effect.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
html
string
-
No
HTML content with tags
delta
Object
-
No
A delta object representing the content
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

.undo

This method is used via EditorContext.undo(Object object).
Feature Description: Undo.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support