Rich text editing implementation method and device, electronic equipment and storage medium

By counting the word count and determining the rich text style index position of the text to be edited on the browser page, rich text editing is achieved without additional plug-ins, solving the problem that the new version of the browser may abolish the rich text editing method, and realizing the browser's internal Universal and convenient rich text editing.

CN119089869APending Publication Date: 2024-12-06IOL WUHAN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411199850.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

In the prior art, the new version of the browser may abolish the rich text editing method, making it an urgent problem to be solved by implementing rich text editing on the browser page.

Method used

By obtaining the text to be edited and the rich text attributes, including rich text styles and full text indexes, counting the number of words on the text segments, determining the starting and ending positions of the rich text styles, and performing rich text editing based on this position, achieving rich text without introducing additional plug-ins edit.

Benefits of technology

It realizes universal and convenient rich text editing "out of the box" in all types of browsers, avoiding the risk of abandonment due to browser version updates and improving the universality of rich text editing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119089869A_ABST
    Figure CN119089869A_ABST
Patent Text Reader

Abstract

The invention provides a rich text editing implementation method and device, electronic equipment and a storage medium, and is applied to a browser, the method comprises the following steps: obtaining a to-be-edited text and a rich text attribute; obtaining the text length of each text segment of the to-be-edited text; determining to-be-edited starting and ending positions of the rich text style based on the full-text index of the rich text style and the text length of each text segment; and based on the rich text style, performing rich text editing on the target text contained in the to-be-edited starting and ending position to obtain a rich text edited text. According to the method provided by the invention, on the basis of the full-text index of the rich text style, the text length of each text segment and the to-be-edited starting and ending position of the rich text style, rich text editing is performed on the text contained in the to-be-edited starting and ending position on the basis of the rich text style to obtain the rich text edited text, no extra plug-in needs to be introduced, and the user experience is improved. The use effect of'instant use after box opening 'is achieved in various types of browsers, and universal and convenient rich text editing is realized in browser webpages.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for implementing rich text editing. Background Art

[0002] The original text in the document may have many styles, such as font color, font size, bold, italic, etc. The translation of these original texts needs to be edited in rich text. Although there are many ways of editing rich text in the industry, they all need to introduce the developed public modules. That is, the underlying architecture of Cat Editor needs to rely on the developed public modules for secondary development. In addition, the browser also provides some native rich text editing methods.

[0003] However, current browser manufacturers have announced that they may abolish the current rich text editing method in new versions of browsers at any time. Therefore, implementing rich text editing on browser pages is a problem that needs to be solved urgently. Summary of the invention

[0004] The present invention provides a method, device, electronic device and storage medium for implementing rich text editing, so as to solve the defect in the prior art that rich text editing may not be implemented on a new version of a browser at any time.

[0005] The present invention provides a rich text editing implementation method, which is applied to a browser and includes: Obtaining the text to be edited and rich text attributes, wherein the rich text attributes include a rich text style and a full-text index of the rich text style; Performing word count on each text segment of the text to be edited to obtain the text length of each text segment; Determining the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment; Based on the rich text style, rich text editing is performed on the target text contained in the start and end positions to be edited to obtain a rich text editing text.

[0006] According to a rich text editing implementation method provided by the present invention, the determining of the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment includes: The text lengths of the text segments are sequentially accumulated until the accumulated result is not less than the full-text index, and the last accumulated text segment is used as the start and end text segments; Based on the full-text index and the text lengths of each accumulated text segment before the last accumulated text segment, obtaining the text segment index position; The start and end positions to be edited are determined based on the start and end text segments and the text segment index positions.

[0007] According to a rich text editing implementation method provided by the present invention, obtaining the text segment index position based on the full-text index and the text length of each accumulated text segment before the last accumulated text segment includes: Obtaining a text sequence number based on the full-text index minus the text length of each accumulated text segment before the last accumulated text segment; The text sequence number is used as the index position of the text segment.

[0008] According to a rich text editing implementation method provided by the present invention, the word count of each text segment of the text to be edited is performed to obtain the text length of each text segment, including: Perform word count on each text segment of the text to be edited to obtain a Dom node tree of the text to be edited; Based on the node length of the text node corresponding to each text segment in the Dom node tree, obtain the text length of each text segment; The node length is used to reflect the number of text displayed in the text segment corresponding to the text node on the browser page.

[0009] According to a rich text editing implementation method provided by the present invention, the word count of each text segment of the text to be edited is performed to obtain a Dom node tree of the text to be edited, including: The word count of the text to be edited is performed based on the document.getElementById function to obtain the Dom node tree of the text to be edited.

[0010] According to a rich text editing implementation method provided by the present invention, based on the rich text style, rich text editing is performed on the target text included in the start and end positions to be edited to obtain the rich text edited text, including: Copying the target text contained in the start and end positions to be edited to obtain a copied text; The rich text style is added to the copied text to obtain the rich text edit text.

[0011] The present invention also provides a rich text editing implementation device, which is applied to a browser and includes: An acquisition unit is used to acquire the text to be edited and rich text attributes, wherein the rich text attributes include a rich text style and a full-text index of the rich text style; A counting unit, which counts the number of words in each text segment of the text to be edited to obtain the text length of each text segment; A positioning unit, which determines the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment; The editing unit performs rich text editing on the target text contained in the start and end positions to be edited based on the rich text style to obtain a rich text editing text.

[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the rich text editing implementation method as described above is implemented.

[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the rich text editing implementation methods described above.

[0014] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned rich text editing implementation methods.

[0015] The rich text editing implementation method, device, electronic device and storage medium provided by the present invention perform word count on each text segment of the text to be edited to obtain the text length of each text segment, determine the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment, and perform rich text editing on the target text contained in the start and end positions to be edited based on the rich text style to obtain the rich text edited text. No additional plug-ins are required to be introduced, and an "out-of-the-box" usage effect is achieved in various types of browsers, thereby realizing universal and convenient rich text editing in browser web pages. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0017] Figure 1 This is one of the flowcharts of the rich text editing implementation method provided by the present invention; Figure 2 This is the second flow chart of the rich text editing implementation method provided by the present invention; Figure 3 It is a structural schematic diagram of the rich text editing implementation device provided by the present invention; Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0018] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0019] In view of the above problems, the present invention provides a rich text editing implementation method, which is applied to a browser and realizes rich text editing that can be used out of the box on the browser without additional modification of the underlying architecture. Figure 1 It is one of the flowcharts of the rich text editing implementation method provided by the present invention, such as Figure 1 As shown, the method includes: Step 110, obtaining the text to be edited and rich text attributes, wherein the rich text attributes include a rich text style and a full-text index of the rich text style; Step 120, counting the number of words in each text segment of the text to be edited to obtain the text length of each text segment; Step 130, determining the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment; Step 140: Based on the rich text style, rich text editing is performed on the target text contained in the start and end positions to be edited to obtain a rich text edit text.

[0020] Here, the text to be edited refers to the text displayed in the browser page without any style. It is understandable that when the text is displayed in the browser page, rich text operations can be accepted for the text to be edited, thereby achieving a more diverse and high-quality text display for the text to be edited. For example, in a webpage translation scenario, the text to be edited can be a translated text after the original text is translated into the target language. Thus, rich text operations can be performed on the text to be edited to restore the translated text without any style to a style consistent with the original text.

[0021] In addition, the rich text attributes here include rich text styles and full text indexes of rich text styles. The rich text styles here can include text display styles such as italics, bold, underline, and highlight. The full text index of a rich text style refers to the position of the start and end points of the rich text style in the entire text segment. For example, the full text index of an underline can be from the 13th character of the full text to the 17th character of the full text.

[0022] Specifically, first, the text of the current page of the browser can be obtained as the text to be edited, and the rich text attributes of the text to be edited can be obtained. The rich text attributes here can come from the rich text editing operation of the user, or the rich text attributes in the original text in the translation scenario.

[0023] Next, you can use the browser's built-in function to count the number of words in each text segment in the text to be edited to get the text length of each text segment. For example, the text to be edited contains three text segments, the text length of the first text segment is 5, the text length of the second text segment is 6, and the text length of the third text segment is 4.

[0024] Here, the text length of the text segment refers to the number of characters contained in the text segment. It should be noted that the full-text index of the rich text style includes a start full-text index at the start position and an end full-text index at the end position.

[0025] Furthermore, the text lengths of the text segments may be accumulated, and the accumulated results may be respectively calculated with the starting full-text index and the ending full-text index of the rich text style to obtain the start and end positions to be edited of the rich text style.

[0026] Finally, you can perform rich text editing on the target text contained in the start and end positions to be edited and add rich text styles to obtain rich text editing text.

[0027] The method provided by the embodiment of the present invention performs word count on each text segment of the text to be edited to obtain the text length of each text segment, determines the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment, and performs rich text editing on the target text contained in the start and end positions to be edited based on the rich text style to obtain the rich text edited text. No additional plug-ins are required to be introduced, and an "out-of-the-box" usage effect is achieved in various types of browsers, thereby realizing universal and convenient rich text editing in browser web pages.

[0028] Based on any of the above embodiments, step 130 includes: The text lengths of the text segments are sequentially accumulated until the accumulated result is not less than the full-text index, and the last accumulated text segment is used as the start and end text segments; Based on the full-text index and the text lengths of each accumulated text segment before the last accumulated text segment, obtaining the text segment index position; The start and end positions to be edited are determined based on the start and end text segments and the text segment index positions.

[0029] Specifically, first, when calculating the starting position to be edited in a rich text style, the text lengths of each text segment can be accumulated in sequence until the accumulated result is not less than the starting full-text index in the full-text index; when calculating the ending position to be edited in a rich text style, the text lengths of each text segment can be accumulated in sequence until the accumulated result is not less than the ending full-text index in the full-text index. Then, the last accumulated text segment can be positioned as the starting and ending text segments. For example, the text lengths of text segment 1, text segment 2, and text segment 3 are accumulated, and the accumulated result is not less than the starting full-text index for the first time, then text segment 3 can be positioned as the text segment with a starting point, and text segment 3 is the starting and ending text segments. It can be understood that the starting and ending text segments can include the starting text segment and the ending text segment.

[0030] It should be noted that the start and end text segments here can be used to locate the text segment where the start and end positions of the rich text style are located. Furthermore, in order to obtain the specific position of the rich text style in the start and end text segments, the text segment index position can be calculated through the full-text index and the text length of each accumulated text segment before the last accumulated text segment. For example, the full-text index can be subtracted from the text length of each accumulated text segment before the last accumulated text segment, and the resulting number is the specific position of the rich text style in the start and end text segments, which can be used as the text segment index position.

[0031] Finally, the start and end text segments and the text segment index positions can be used together as the start and end positions to be edited in the rich text style. For example, the start position to be edited can be the third text in the second text segment, and the end position to be edited can be the first text in the third text segment.

[0032] Based on any of the above embodiments, obtaining the text segment index position based on the full-text index and the text lengths of each accumulated text segment before the last accumulated text segment includes: Obtaining a text sequence number based on the full-text index minus the text length of each accumulated text segment before the last accumulated text segment; The text sequence number is used as the index position of the text segment.

[0033] Specifically, when calculating the starting position to be edited, the text sequence number can be obtained by subtracting the text length of each accumulated text segment before the last accumulated text segment from the starting full-text index. The last accumulated text segment here refers to the last accumulated text until the accumulated result is not less than the starting full-text index in the full-text index. Similarly, when calculating the ending position to be edited, the text sequence number can be obtained by subtracting the text length of each accumulated text segment before the last accumulated text segment from the ending full-text index. The last accumulated text segment here refers to the last accumulated text until the accumulated result is not less than the ending full-text index in the full-text index.

[0034] Next, the text sequence number can be used as the text segment index position. For example, if the text length of text segment 1 is 6, the text length of text segment 2 is 7, the starting full-text index position is the 13th text, and the ending full-text index position is the 17th text, then the text segment index position of the starting position to be edited is the 7th text of the second text segment, and the text segment index position of the ending position to be edited is the 4th text of the third text segment.

[0035] Based on any of the above embodiments, the step of performing word count on each text segment of the text to be edited to obtain the text length of each text segment includes: Perform word count on each text segment of the text to be edited to obtain a Dom node tree of the text to be edited; Based on the node length of the text node corresponding to each text segment in the Dom node tree, obtain the text length of each text segment; The node length is used to reflect the number of text displayed in the text segment corresponding to the text node on the browser page.

[0036] Specifically, the text segment whose word count is to be counted in the text to be edited can be obtained through the browser's built-in function, and the text segment can be used as a text node to obtain the Dom node tree corresponding to the text to be edited. It should be noted that the Dom node tree here contains multiple types of nodes, including text nodes, attribute nodes, element nodes, etc.

[0037] Then, the node length of the text node corresponding to each text segment in the Dom node tree can be used as the text length of each text segment. For example, the node length of the text node can be obtained through the length attribute in the text node, and the node length can be used as the text length.

[0038] It should be noted that the node length here is used to reflect the number of text segments corresponding to the text node displayed on the browser page. For example, if a text segment on the browser page is displayed as "Today's weather is very good!", the node length of this text node is 7.

[0039] It should be emphasized that some HTML text is different from the original HTML text when it is presented on the browser page. For example, it is 6 characters in HTML, but it is rendered as a space on the page. If the number of characters in the text node is counted according to the original HTML text, the text length of the text segment may not match the number of characters displayed on the actual browser page, which will lead to inaccurate positioning of the start and end positions of rich text editing. In the embodiment of the present invention, the node length is used to reflect the number of text displayed on the browser page of the text segment corresponding to the text node, which ensures that the text length obtained when performing rich text operations is consistent with the actual display character length on the browser page, solves the problem of text rendering conflicts, and ensures the accuracy of rich text editing.

[0040] Based on any of the above embodiments, the step of performing word count on each text segment of the text to be edited to obtain a Dom node tree of the text to be edited includes: The word count of the text to be edited is performed based on the document.getElementById function to obtain the Dom node tree of the text to be edited.

[0041] Specifically, the node whose word count is required for the text to be edited can be obtained through the document.getElementById function to obtain the Dom node tree of the text to be edited. It should be noted that the Dom node tree obtained here does not directly store the "length" of the text segment, that is, the number of characters. The Dom node tree may include text, other elements, comments, etc., which all exist as child nodes of the Dom node tree.

[0042] Based on any of the above embodiments, based on the rich text style, performing rich text editing on the target text included in the start and end positions to be edited to obtain the rich text edited text includes: Copying the target text contained in the start and end positions to be edited to obtain a copied text; The rich text style is added to the copied text to obtain the rich text edit text.

[0043] Specifically, you can use the cloneContent() method of the range object to copy and save the HTML text within the start and end position range to be edited to obtain the copied text. You can also use the deleteContents() method to delete all the HTML text within the start and end position range to be edited. Then, add rich text styles to the copied text. For example, This is a test text, which means to bold "This is a test text". Furthermore, you can convert the copied text with the rich text style added into a node through the browser document.createRange().createContextualFragment(). Finally, you can use the insertNode() of the range object to insert the converted node into the original position of the text to be edited, and the rich text editing is completed, and the rich text editing text is obtained.

[0044] It should be noted that the document.execCommand() method is still the mainstream in the industry. However, major browser manufacturers have announced that they will no longer maintain this method, that is, it may be abandoned in future browser versions. The rich text editing method provided by the embodiment of the present invention will not be abandoned due to browser version updates, and does not require the introduction of additional plug-ins. It can be completed using the browser's native API combination, achieving the effect of independent research and development, with controllable risks, and realizing rich text editing on any browser page, thereby improving the versatility of the rich text editing method.

[0045] Based on any of the above embodiments, Figure 2 This is the second flow chart of the rich text editing implementation method provided by the present invention. Figure 2 As shown, the method includes: Step 210, obtaining the length of each text node; Step 220, based on the length of each text node and the full-text index of the rich text style, obtain the text nodes and positions of the start point and the end point; Step 230, wrapping the content within the range of the start point and the end point based on the browser range object; Specifically, you can get a range object through the document.createRange() method that comes with the browser. Range has setStart (starting position) and setEnd (ending position), and the two method parameters are (Node, Offset) Node: the coordinates are set to the nodes where the rich text style start and end points are located; Offset: set to the position of the rich text style start and end points in the node. Then, using the text node and index obtained by 1 and 2, you can set the starting position and end position.

[0046] Step 240, based on the rich text style, transform the HTML text wrapped by the range object, and insert the transformed text into the starting point and the end point.

[0047] As long as it is text on the browser page, the method provided by the embodiment of the present invention can be used to edit rich text without modifying the editor, so that it can be used out of the box.

[0048] Based on any of the above embodiments, Figure 3 It is a schematic diagram of the structure of the rich text editing implementation device provided by the present invention, which is applied to a browser, such as Figure 3 As shown, the device comprises: An acquisition unit 310 acquires the text to be edited and rich text attributes, wherein the rich text attributes include a rich text style and a full-text index of the rich text style; A counting unit 320 performs word counting on each text segment of the text to be edited to obtain the text length of each text segment; A positioning unit 330 determines the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment; The editing unit 340 performs rich text editing on the target text included in the start and end positions to be edited based on the rich text style to obtain a rich text editing text.

[0049] The device provided by the embodiment of the present invention counts the number of words in each text segment of the text to be edited to obtain the text length of each text segment, determines the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment, and performs rich text editing on the target text contained in the start and end positions to be edited based on the rich text style to obtain the rich text edited text. There is no need to introduce additional plug-ins, and an "out-of-the-box" usage effect is achieved in various types of browsers, and universal and convenient rich text editing is realized in browser web pages.

[0050] Based on any of the above embodiments, the positioning unit is specifically used for: The text lengths of the text segments are sequentially accumulated until the accumulated result is not less than the full-text index, and the last accumulated text segment is used as the start and end text segments; Based on the full-text index and the text lengths of each accumulated text segment before the last accumulated text segment, obtaining the text segment index position; The start and end positions to be edited are determined based on the start and end text segments and the text segment index positions.

[0051] Based on any of the above embodiments, the positioning unit is further specifically used for: Obtaining a text sequence number based on the full-text index minus the text length of each accumulated text segment before the last accumulated text segment; The text sequence number is used as the index position of the text segment.

[0052] Based on any of the above embodiments, the statistical unit is specifically used for: Perform word count on each text segment of the text to be edited to obtain a Dom node tree of the text to be edited; Based on the node length of the text node corresponding to each text segment in the Dom node tree, obtain the text length of each text segment; The node length is used to reflect the number of text displayed in the text segment corresponding to the text node on the browser page.

[0053] Based on any of the above embodiments, the statistical unit is further specifically used for: The word count of the text to be edited is performed based on the document.getElementById function to obtain the Dom node tree of the text to be edited.

[0054] Based on any of the above embodiments, the editing unit is specifically used for: Copying the target text contained in the start and end positions to be edited to obtain a copied text; The rich text style is added to the copied text to obtain the rich text edit text.

[0055] Figure 4 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the rich text editing implementation method, which includes: obtaining the text to be edited and the rich text attribute, wherein the rich text attribute includes the rich text style and the full text index of the rich text style; performing word count on each text segment of the text to be edited to obtain the text length of each text segment; determining the start and end positions of the rich text style to be edited based on the full text index of the rich text style and the text length of each text segment; and performing rich text editing on the target text included in the start and end positions to be edited based on the rich text style to obtain the rich text edited text.

[0056] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0057] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the rich text editing implementation method provided by the above-mentioned methods, which method includes: obtaining the text to be edited and rich text attributes, the rich text attributes including a rich text style and a full-text index of the rich text style; performing word count on each text segment of the text to be edited to obtain the text length of each text segment; determining the start and end positions to be edited of the rich text style based on the full-text index of the rich text style and the text length of each text segment; and based on the rich text style, performing rich text editing on the target text contained in the start and end positions to be edited to obtain a rich text edited text.

[0058] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the rich text editing implementation method provided by the above-mentioned methods, the method comprising: obtaining a text to be edited and rich text attributes, the rich text attributes comprising a rich text style and a full-text index of the rich text style; performing word count on each text segment of the text to be edited to obtain the text length of each text segment; determining the start and end positions to be edited of the rich text style based on the full-text index of the rich text style and the text length of each text segment; and performing rich text editing on the target text contained in the start and end positions to be edited based on the rich text style to obtain a rich text edited text.

[0059] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0060] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0061] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for implementing rich text editing, It is characterized in that Applies to browsers, including: Obtaining the text to be edited and rich text attributes, wherein the rich text attributes include a rich text style and a full-text index of the rich text style; Performing word count on each text segment of the text to be edited to obtain the text length of each text segment; Determining the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment; Based on the rich text style, rich text editing is performed on the target text contained in the start and end positions to be edited to obtain a rich text editing text.

2. The rich text editing implementation method according to claim 1, It is characterized in that The step of determining the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment includes: The text lengths of the text segments are sequentially accumulated until the accumulated result is not less than the full-text index, and the last accumulated text segment is used as the start and end text segments; Based on the full-text index and the text lengths of each accumulated text segment before the last accumulated text segment, obtaining the text segment index position; The start and end positions to be edited are determined based on the start and end text segments and the text segment index positions.

3. The rich text editing implementation method according to claim 2, It is characterized in that The obtaining of the text segment index position based on the full-text index and the text length of each accumulated text segment before the last accumulated text segment comprises: Obtaining a text sequence number based on the full-text index minus the text length of each accumulated text segment before the last accumulated text segment; The text sequence number is used as the index position of the text segment.

4. The rich text editing implementation method according to any one of claims 1 to 3, It is characterized in that The step of performing word count on each text segment of the text to be edited to obtain the text length of each text segment includes: Perform word count on each text segment of the text to be edited to obtain a Dom node tree of the text to be edited; Based on the node length of the text node corresponding to each text segment in the Dom node tree, obtain the text length of each text segment; The node length is used to reflect the number of text displayed in the text segment corresponding to the text node on the browser page.

5. The rich text editing implementation method according to claim 4, It is characterized in that The step of performing word count on each text segment of the text to be edited to obtain a Dom node tree of the text to be edited includes: The word count of the text to be edited is performed based on the document.getElementById function to obtain the Dom node tree of the text to be edited.

6. The rich text editing implementation method according to any one of claims 1 to 3, It is characterized in that The step of performing rich text editing on the target text contained in the start and end positions to be edited based on the rich text style to obtain rich text edited text includes: Copying the target text contained in the start and end positions to be edited to obtain a copied text; The rich text style is added to the copied text to obtain the rich text edit text.

7. A device for implementing rich text editing, It is characterized in that Applies to browsers, including: An acquisition unit is used to acquire the text to be edited and rich text attributes, wherein the rich text attributes include a rich text style and a full-text index of the rich text style; A counting unit, which counts the number of words in each text segment of the text to be edited to obtain the text length of each text segment; A positioning unit, which determines the start and end positions of the rich text style to be edited based on the full-text index of the rich text style and the text length of each text segment; The editing unit performs rich text editing on the target text contained in the start and end positions to be edited based on the rich text style to obtain a rich text editing text.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the rich text editing implementation method as described in any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the rich text editing implementation method as described in any one of claims 1 to 6 is implemented.

10. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the rich text editing implementation method as described in any one of claims 1 to 6 is implemented.