How to determine the cursor at the beginning of the line in the rich text editor in the vue environment

By comparing the position information of the rich text editor cursor and its previous element in the Vue environment, the uncertainty problem of judging the beginning of the cursor line is solved, and efficient and concise cursor positioning is achieved. It is suitable for various web projects and improves development. efficiency and user experience.

CN118502733BActive Publication Date: 2024-09-27海看网络科技(山东)股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410976927.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2024-09-27
Estimated Expiration
2044-07-22

AI Technical Summary

Technical Problem

When using the rich text editor in the Vue environment, there are shortcomings in the method of determining whether the cursor is at the beginning of the line, especially when the cursor position changes uncertainly when inputting content, and the cursor position cannot be accurately determined when the pasted content lacks a specific identifier, resulting in monitoring High cost and complex operation.

Method used

Obtain the cursor position information provided by the rich text editor and the position information of the element before the cursor, compare the offset between the two to determine whether the cursor is at the beginning of the line, and adjust the cursor position cyclically when unsure to ensure the cursor shape Consistent to determine the beginning of the line.

Benefits of technology

It achieves the accuracy and simplicity of judging the beginning of the cursor line in the Vue environment, avoids a large number of key monitoring and dependence on specific identifiers, improves page fluency and operating experience, has stronger adaptability, and saves development time and costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118502733B
    Figure CN118502733B
Patent Text Reader

Abstract

The present invention relates to a method for determining whether a cursor is at the beginning of a line in a rich text editor under a vue environment, and relates to the technical field of editor cursor positioning. The present application uses a method provided by a rich text editor to obtain the first window position information of the current cursor in a window, and uses a method provided by a rich text editor to obtain the second window position information of the element before the current cursor in the window. The first and second window position information contain the following parameters of the respective cursors: height, width, distance from the top of the page, distance from the bottom of the page, distance from the left to the left of the page, and distance from the right to the left of the page; by comparing the offset between the second window position information and the first window position information, determine whether the current cursor is at the beginning of the line. The present application does not need to monitor whether the cursor is in the first line, which saves a lot of resource overhead, further improves the page fluency, and gives users a good operating experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of editor cursor positioning, and in particular to a method for determining that a cursor is at the beginning of a line in a rich text editor in a Vue environment. Background Art

[0002] When developing web projects using the Vue language, a rich text editor is usually used to develop certain specific functions. The rich text editor provides powerful text and paragraph editing capabilities, and a variety of plug-ins simplify and standardize complex functions. In addition, due to the characteristics of the rich text editor, it has good compatibility and extensibility.

[0003] In Vue language, the indentation of code needs to follow certain specifications. Therefore, during the code development process, determining whether the cursor position is at the beginning of the line is of great significance to the implementation of the indentation specification of Vue programming code. When using a rich text editor in a web project developed in a vue3 environment, you will encounter two situations: input content and pasting content. When continuously inputting content into the editing area, if the current input length exceeds the width of the control, the input content will automatically wrap. If the width of the current input content just meets one line, the cursor position will automatically stay at the end of the line. In this case, we usually use the 'enter' key to open a new line. When pasting content into the editing area of ​​the rich text editor wangEditor, we usually insert 'HTML' to retain the style of the pasted content. At this time, we will force a line break by matching '\n' or a custom identifier. At this time, we only need to find '\n' or a custom identifier to determine whether the current cursor is at the beginning of the line. In summary, when judging the position of the beginning of a line in the rich text editor wangEditor, we usually use the following two methods: by clicking the 'enter' key, the content is forced to wrap, and the cursor is at the beginning of the new line. Then we can record the response of the 'enter' key to determine whether the current cursor is at the beginning of the line. However, the disadvantage of this solution is that when we click the 'enter' key to perform a line break operation, if we continue to perform other operations, such as entering new content or deleting content, the cursor position will also change. Therefore, we cannot accurately determine whether the current cursor is at the beginning of the line, unless all subsequent operations after clicking the 'enter' key are in the monitored state. By analyzing the subsequent monitoring state to determine whether the current cursor is at the beginning of the line, we have to monitor events in various states, but because the user's behavior data is uncontrollable, we have to consider all possible operations of the current editor, resulting in high monitoring costs. For the pasted content in the editing area, we usually determine the position of the line break by judging specific identifiers such as line breaks or custom identifiers, and then move the cursor to that position to achieve the purpose of placing the cursor at the beginning of the line. However, this method will fail if the pasted content does not have a specific identifier (newline character or custom identifier). Summary of the invention

[0004] In order to solve the above technical problem or at least partially solve the above technical problem, the present invention provides a method for determining that a cursor is at the beginning of a line in a rich text editor in a Vue environment.

[0005] In a first aspect, the present invention provides a method for determining that a cursor is at the beginning of a line in a rich text editor in a vue environment, comprising: introducing a rich text editor into a vue-based web project, and configuring the rich text editor in vue;

[0006] Using the method provided by the rich text editor, the first window position information of the current cursor in the window is obtained, wherein the first window position information includes: the height and width of the current cursor, the distance from the top of the current cursor to the top of the page, the distance from the bottom of the current cursor to the top of the page, the distance from the left side of the current cursor to the left side of the page, and the distance from the right side of the current cursor to the left side of the page;

[0007] Using the method provided by the rich text editor, obtain the second window position information of the element before the current cursor in the window, wherein the second window position information includes: the height and width of the cursor itself after the change, the distance from the top of the cursor to the top of the page after the change, the distance from the bottom of the cursor to the top of the page after the change, the distance from the left side of the cursor to the left side of the page after the change, and the distance from the right side of the cursor to the left side of the page after the change;

[0008] Whether the current cursor is at the beginning of the line is determined by comparing the offset between the second window position information and the first window position information.

[0009] Furthermore, the introduction of the rich text editor into the vue-based web project and the configuration of the rich text editor in vue include: using the npm or yarn command to introduce the rich text editor into the vue-based web project; introducing the rich text editor into the vue page; and setting the basic properties of the rich text editor.

[0010] Furthermore, using the method provided by the rich text editor to obtain the first window position information of the current cursor in the window includes:

[0011] For the current cursor, execute the getSelection() method provided by the rich text editor window according to the default parameters to obtain all the text before the current cursor and use it as the current cursor Dom object;

[0012] Execute the getRangeAt(0) method of the current cursor Dom object to obtain the current cursor range;

[0013] Execute the native method getBoundintClientRect() of the current cursor range to obtain the display area of ​​the current cursor in the window and return the first window position information of the current cursor in the window.

[0014] Furthermore, the method provided by the rich text editor to obtain the second window position information of the element before the current cursor in the window includes:

[0015] The current cursor moves forward one position, so that the cursor occupies the position of the element before the current cursor after the change;

[0016] For the changed cursor, the getSelection() method provided by the rich text editor window is executed according to the default parameters to obtain all the text before the changed cursor and use it as the changed cursor Dom object;

[0017] After executing the change, the cursor Dom object comes with the method getRangeAt(0) to obtain the cursor range after the change;

[0018] Execute the native method getBoundintClientRect() of the changed cursor range to obtain the display area of ​​the changed cursor in the window and return the window position information of the changed cursor in the window, that is, obtain the second window position information of the element before the current cursor in the window;

[0019] Move the cursor back one position after the change and reset it.

[0020] Furthermore, determining whether the current cursor is at the beginning of a line by comparing the offset between the second window position information and the first window position information includes:

[0021] When the current cursor and the changed cursor have the same shape, if the distance from the top of the current cursor to the top of the page is greater than the distance from the bottom of the cursor to the top of the page after the change, and the distance from the right side of the cursor to the left side of the page after the change minus the distance from the left side of the current cursor to the left side of the page is equal to the width of the rich text editor, then the current cursor is judged to be at the beginning of the line, otherwise the current cursor is judged to be not at the beginning of the line.

[0022] Furthermore, when it is determined that the current cursor is not at the beginning of the line, the distance between the current cursor and the beginning of the line is obtained, including: the current cursor moves forward one more position to become a new current cursor, the number of times the current cursor is updated to obtain a new current cursor is recorded, and based on the new current cursor, it is determined again whether the new current cursor is at the beginning of the line; otherwise, the cycle is repeated until the new current cursor is at the beginning of the line, and the final number of times the current cursor is updated to obtain a new current cursor is used as the distance between the current cursor and the beginning of the line, and the new current cursor at the beginning of the line is reset to its original position according to the final number.

[0023] Furthermore, after determining the distance between the current cursor and the beginning of the line, an interactive prompt is given as to whether to move the current cursor to the beginning of the line. If the user determines to move the current cursor to the beginning of the line, the reset current cursor is moved to the beginning of the line according to the distance between the current cursor and the beginning of the line. If the user refuses to move the current cursor to the beginning of the line, the current cursor remains in place.

[0024] Furthermore, the height and width of the current cursor are compared with the height and width of the changed cursor to determine whether the current cursor shape is consistent with the changed cursor shape. When the current cursor shape is inconsistent with the changed cursor shape, a prompt is given to ensure that the current cursor shape is consistent with the changed cursor shape.

[0025] In a second aspect, the present invention provides a device for implementing a method for determining that a cursor is at the beginning of a line in a rich text editor in a Vue environment, comprising: at least one processing unit, the processing unit being connected to a storage unit via a bus unit, the storage unit storing a computer program, and when the computer program is executed by the processing unit, the method for determining that a cursor is at the beginning of a line in a rich text editor in a Vue environment is implemented.

[0026] In a third aspect, the present invention provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the method for determining that the cursor is at the beginning of a line in a rich text editor in a Vue environment as described.

[0027] The above technical solution provided by the embodiment of the present invention has the following advantages compared with the prior art:

[0028] This solution uses the rich text editor window and the native method of the rich text editor to obtain the cursor position information and compare it to determine whether the current cursor position is at the beginning of the line. There is no need to monitor the 'enter' key, nor is there any need to traverse the rich text editor content to see if it contains specific identifiers (such as '\n' or custom identifiers, etc.). The function of positioning at the beginning of the line can be implemented more simply, and a small amount of code can be used to implement the function. Since a large number of key monitoring is avoided, a large amount of resource overhead is saved, the page fluency is further improved, and the user is given a good operating experience. In addition, this application is suitable for various web projects, has better adaptability, and is more portable and operable. Therefore, it is easy to adapt in different projects, which can effectively improve development efficiency, greatly save project development time, and save a lot of R&D costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0031] Figure 1A flowchart of a method for determining that a cursor is at the beginning of a line in a rich text editor in a Vue environment provided by an embodiment of the present invention;

[0032] Figure 2 A flowchart of obtaining the first window position information of the current cursor in a window by using the method provided by a rich text editor provided by an embodiment of the present invention;

[0033] Figure 3 A schematic diagram of the location information returned by the getBoundingClientRect() method provided in an embodiment of the present invention;

[0034] Figure 4 A flowchart of obtaining the second window position information of an element before the current cursor in a window by using a method provided by a rich text editor provided by an embodiment of the present invention;

[0035] Figure 5 A flowchart for determining whether a current cursor is at the beginning of a line by comparing the offset between the second window position information and the first window position information, and determining the distance between the current cursor and the beginning of a line when the current cursor is not at the beginning of a line, provided by an embodiment of the present invention;

[0036] Figure 6 A schematic diagram of a device for implementing a method for determining that a cursor is at the beginning of a line in a rich text editor in a Vue environment provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments 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.

[0038] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0039] Example 1

[0040] like Figure 1As shown, the technology of the present invention realizes a method for determining that the cursor is at the beginning of a line in a rich text editor in a vue environment. Since this solution is used in a vue environment, it is necessary to first build a vue web project and introduce a rich text editor. How to build a vue web project is not within the scope of discussion of this case. Please refer to the vue official website for details. The main discussion is about the operations after building the web project. The specific operations are as follows:

[0041] Introduce the rich text editor into the vue-based web project and configure the rich text editor in vue.

[0042] Use the npm or yarn command to introduce the rich text editor into the Vue-based web project.

[0043] Take the rich text editor wangEditor as an example: use the following commands to introduce the wangEditor editor into the vue-based web project: yarn add @wangeditor / editor, yarn add @wangeditor / editor-for-vue@next.

[0044] Configure the rich text editor in the vue page, including:

[0045] Introduce rich text editor in vue page;

[0046] Taking wangEditor as an example, the wangEditor plug-in is introduced in the vue page through the following javascript code:

[0047] <template>

[0048]

[0049] <Toolbar

[0050] style="border-bottom: 1px solid #ccc"

[0051] :editor="editorRef"

[0052] :defaultConfig="toolbarConfig"

[0053] :mode="mode"

[0054] / >

[0055] <Editor

[0056] style="height: 500px; overflow-y: hidden;"

[0057] v-model="valueHtml"

[0058] :defaultConfig="editorConfig"

[0059] :mode="mode"

[0060] @onCreated="handleCreated"

[0061] / >

[0062]

[0063] < / template>

[0064] Among them, Toolbar and Editor are both built-in components of the rich text editor wangEditor.

[0065] Set the basic properties of the rich text editor;

[0066] Write the following javascript code to set the basic properties of the rich text editor wangEditor:

[0067] <script>

[0068] import '@wangeditor / editor / dist / css / style.css'

[0069] import {onBeforeUnmount, ref, shallowRef, onMounted} from 'vue'

[0070] import {Editor, Toolbar} from '@wangeditor / editor-for-vue'

[0071] export default {

[0072] components: { Editor, Toolbar},

[0073] setup() {

[0074] / / 用 shallowRef创建富文本编辑器实例

[0075] const editorRef = shallowRef()

[0076] / / 设置HTML内容

[0077] const valueHtml = ref('hello')

[0078] / / 设置模拟ajax异步获取内容

[0079] onMounted(() =>{

[0080] setTimeout(() =>{

[0081] valueHtml.value = ''

[0082] }, 1500)

[0083] })

[0084] / / 设置富文本编辑器组件配置

[0085] const toolbarConfig = {}

[0086] const editorConfig = { placeholder: '请输入内容...'}

[0087] / / 组件销毁时,也及时销毁富文本编辑器

[0088] onBeforeUnmount(() =>{

[0089] const editor = editorRef.value

[0090] if (editor == null) return

[0091] editor.destroy()

[0092] })

[0093] / / 记录 editor 实例。

[0094] const handleCreated = (editor) =>{

[0095] editorRef.value = editor

[0096] }

[0097] return {

[0098] editorRef,

[0099] valueHtml,

[0100] mode: 'default', / / 或 'simple'模式

[0101] toolbarConfig,

[0102] editorConfig,

[0103] handleCreated

[0104] };

[0105] }

[0106] }

[0107] < / script>

[0108] The basic configuration will not be expanded here. You can configure the corresponding toolbar, editor, and menu according to different needs.

[0109] Through the above process, the basic functions of the rich text editor wangEditor in the vue environment have been configured. The next step is the implementation process of this solution.

[0110] The first step is to use the method provided by the rich text editor to obtain the first window position information of the current cursor in the window, such as Figure 2 As shown, it includes: for the current cursor, executing the getSelection() method provided by the rich text editor window according to the default parameters to obtain all the text before the current cursor and use it as the current cursor Dom object; executing the method getRangeAt(0) provided by the current cursor Dom object to obtain the current cursor range; executing the native method getBoundintClientRect() of the current cursor range to obtain the display area of ​​the current cursor in the window and return the first window position information of the current cursor in the window.

[0111] The first window position information includes: the height and width of the current cursor, the distance from the top of the current cursor to the top of the page, the distance from the bottom of the current cursor to the top of the page, the distance from the left side of the current cursor to the left side of the page, and the distance from the right side of the current cursor to the left side of the page. Figure 3 As shown, Figure 3 The left in the text box refers to the distance from the left side of the cursor to the left side of the page. Figure 3 Right refers to the distance from the right side of the cursor to the left side of the page. Figure 3 Top refers to the distance between the cursor and the top of the page. Figure 3 Bottom refers to the distance from the bottom of the cursor to the top of the page.

[0112] There is no method to get the current cursor position in the rich text editor, but the getSelection() method is provided in the rich text editor window to get the text range selected by the user. In the getSelection() method provided by the window, the default parameter selects all the text before the cursor. Use the window.getSelection() method to get all the text before the current cursor and use it as the current cursor DOM object. Use the getRangeAt(0) method of the current cursor DOM object to get the current cursor range. For the current cursor DOM object, the parameter "0" of getRangeAt(0) points to the current cursor. Then use the native method getBoundintClientRect() of the current cursor range to get the display area of ​​the current cursor in the window. The getBoundintClientRect() method will return the first window position information of the current cursor. The first window position information includes: the width and height of the cursor itself, the distance from the top of the cursor to the top of the page, the distance from the bottom of the cursor to the top of the page, the distance from the left of the cursor to the left of the page, and the distance from the right of the cursor to the left of the page. Based on this information, we can accurately locate the current cursor position in the window.

[0113] We need to obtain the second window position information of the element before the cursor, and determine whether the current cursor is at the beginning of the line by comparing the offset of the first window position information and the second window position information.

[0114] Step 2: Use the method provided by the rich text editor to obtain the second window position information of the element before the current cursor in the window, such as Figure 4 As shown, including:

[0115] The current cursor is moved forward one position so that the cursor occupies the position of the element before the current cursor after the change. Specifically, the editor.moveReverse(1) method provided by the rich text editor is used to move the current cursor position forward one position.

[0116] For the changed cursor, the getSelection() method provided by the rich text editor window is executed according to the default parameters to obtain all the text before the changed cursor and use it as the changed cursor Dom object;

[0117] The method getRangeAt(0) provided by the changed cursor Dom object is executed to obtain the changed cursor range; wherein, for the changed cursor Dom object, the parameter "0" of getRangeAt(0) points to the current cursor.

[0118] Execute the native method getBoundintClientRect() of the changed cursor range to obtain the display area of ​​the changed cursor in the window and return the window position information of the changed cursor in the window, that is, obtain the second window position information of the element before the current cursor in the window;

[0119] Move the cursor back one position after the change. When obtaining the second window position information of the element before the current cursor in the window, the cursor is moved forward one position. It is necessary to reset the cursor, that is, move it back one position. Call the native method of the rich text editor wangEditor and use the editor.move(1) method to implement this function.

[0120] The second window position information includes: the height and width of the cursor after the change, the distance from the top of the cursor to the top of the page after the change, the distance from the bottom of the cursor to the top of the page after the change, the distance from the left side of the cursor to the left side of the page after the change, and the distance from the right side of the cursor to the left side of the page after the change.

[0121] Step 3: Determine whether the current cursor is at the beginning of the line by comparing the offset between the second window position information and the first window position information, and determine the distance between the current cursor and the beginning of the line if the current cursor is not at the beginning of the line, such as Figure 5 As shown, including:

[0122] Compare the height and width of the current cursor with the height and width of the changed cursor to determine whether the current cursor shape is consistent with the changed cursor shape. If the current cursor shape is inconsistent with the changed cursor shape, prompt to ensure that the current cursor shape is consistent with the changed cursor shape.

[0123] When the current cursor and the changed cursor have the same shape, if the distance from the top of the current cursor to the top of the page is greater than the distance from the bottom of the cursor to the top of the page after the change, and the distance from the right side of the cursor to the left side of the page after the change minus the distance from the left side of the current cursor to the left side of the page is equal to the width of the rich text editor, then the current cursor is judged to be at the beginning of the line, otherwise the current cursor is judged to be not at the beginning of the line.

[0124] In the first and second steps, we get the current cursor Dom object and the changed cursor Dom object, and further get the first window position information and the second window position information of the cursor in the current cursor Dom object and the changed cursor Dom object. The first window position information and the second window position information are based on the same reference system of the rich text editor window. When the current cursor and the changed cursor have the same shape, the two position information can be directly compared. If the current cursor object is at the beginning of the line, it means that the distance from the top of the current cursor to the top of the page is greater than the distance from the bottom of the cursor to the top of the page after the change, because there will be a margin between elements, or the line height is set between editor lines, and the distance from the right side of the cursor to the left side of the page after the change minus the distance from the left side of the current cursor to the left side of the page is equal to the width of the rich text editor. If these two conditions are met, then we can determine that the current cursor is at the beginning of the line.

[0125] When it is determined that the current cursor is not at the beginning of the line, the distance between the current cursor and the beginning of the line is obtained, including: the current cursor moves forward one more position to become a new current cursor, the number of times the current cursor is updated to obtain a new current cursor is recorded, and based on the new current cursor, it is determined again whether the new current cursor is at the beginning of the line; otherwise, the cycle is repeated until the new current cursor is at the beginning of the line, and the final number of times the current cursor is updated to obtain a new current cursor is used as the distance between the current cursor and the beginning of the line, and the new current cursor at the beginning of the line is reset to its original position according to the final number.

[0126] After determining the distance between the current cursor and the beginning of the line, an interactive prompt is given as to whether to move the current cursor to the beginning of the line. If the user determines to move the current cursor to the beginning of the line, the reset current cursor is moved to the beginning of the line according to the distance between the current cursor and the beginning of the line. Alternatively, a command to move the current cursor to the beginning of the line is defined and the command to move the current cursor to the beginning of the line is executed, and the distance between the current cursor and the beginning of the line is obtained, and the current cursor is moved to the beginning of the line according to the distance between the current cursor and the beginning of the line.

[0127] Example 2

[0128] See also Figure 6 As shown, an embodiment of the present invention provides a device for implementing a method for determining that a cursor is at the beginning of a line in a rich text editor under a vue environment, comprising: at least one processing unit, the processing unit is connected to a storage unit via a bus unit, the storage unit is a computer-readable storage medium, and can be used to store software programs, computer executable programs, and modules, such as the software programs, computer executable programs, and modules corresponding to a method for determining that a cursor is at the beginning of a line in a rich text editor under a vue environment in an embodiment of the present invention. The processing unit implements the above-mentioned method for determining that a cursor is at the beginning of a line in a rich text editor under a vue environment by running the software programs, computer executable programs, and modules stored in the storage unit, comprising:

[0129] The first window position information of the current cursor in the window is obtained by using the method provided by the rich text editor introduced into the vue-based web project, wherein the first window position information includes: the height and width of the current cursor itself, the distance from the top of the current cursor to the top of the page, the distance from the bottom of the current cursor to the top of the page, the distance from the left side of the current cursor to the left side of the page, and the distance from the right side of the current cursor to the left side of the page;

[0130] Using the method provided by the rich text editor, obtain the second window position information of the element before the current cursor in the window, wherein the second window position information includes: the height and width of the cursor itself after the change, the distance from the top of the cursor to the top of the page after the change, the distance from the bottom of the cursor to the top of the page after the change, the distance from the left side of the cursor to the left side of the page after the change, and the distance from the right side of the cursor to the left side of the page after the change;

[0131] Whether the current cursor is at the beginning of the line is determined by comparing the offset between the second window position information and the first window position information.

[0132] Of course, the storage unit in the device for implementing the method for determining that the cursor is at the beginning of a line in a rich text editor in a Vue environment provided by an embodiment of the present invention, the computer program stored in it is not limited to the method operation as described above, and can also execute related operations in the method for determining that the cursor is at the beginning of a line in a rich text editor in a Vue environment provided by any embodiment of the present invention.

[0133] Example 3

[0134] An embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program. When the computer program is executed, the method for determining that a cursor is at the beginning of a line in a rich text editor in a Vue environment is implemented, including:

[0135] The first window position information of the current cursor in the window is obtained by using the method provided by the rich text editor introduced into the vue-based web project, wherein the first window position information includes: the height and width of the current cursor itself, the distance from the top of the current cursor to the top of the page, the distance from the bottom of the current cursor to the top of the page, the distance from the left side of the current cursor to the left side of the page, and the distance from the right side of the current cursor to the left side of the page;

[0136] Using the method provided by the rich text editor, obtain the second window position information of the element before the current cursor in the window, wherein the second window position information includes: the height and width of the cursor itself after the change, the distance from the top of the cursor to the top of the page after the change, the distance from the bottom of the cursor to the top of the page after the change, the distance from the left side of the cursor to the left side of the page after the change, and the distance from the right side of the cursor to the left side of the page after the change;

[0137] Whether the current cursor is at the beginning of the line is determined by comparing the offset between the second window position information and the first window position information.

[0138] A computer-readable storage medium provided by an embodiment of the present invention, the computer program stored in the medium is not limited to the method operations described above, and can also execute related operations in a method for determining that the cursor is at the beginning of a line in a rich text editor in a Vue environment provided by any embodiment of the present invention.

[0139] In the embodiments provided by the present invention, it should be understood that the disclosed structures and methods can be implemented in other ways. For example, the structural embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, structures or units, which can be electrical, mechanical or other forms.

[0140] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0141] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0142] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for determining that the cursor is at the beginning of a line in a rich text editor in a vue environment, characterized in that: include: The method provided by the rich text editor introduced into the vue-based web project is used to obtain the first window position information of the current cursor in the window, including: for the current cursor, executing the getSelection() method provided by the rich text editor window according to the default parameters to obtain all the text before the current cursor and use it as the current cursor Dom object; executing the method getRangeAt(0) provided by the current cursor Dom object to obtain the current cursor range; executing the native method getBoundintClientRect() of the current cursor range to obtain the display area of ​​the current cursor in the window and return the first window position information of the current cursor in the window; wherein, the first window position information includes: the height and width of the current cursor itself, the distance from the top of the current cursor to the top of the page, the distance from the bottom of the current cursor to the top of the page, the distance from the left of the current cursor to the left of the page, and the distance from the right of the current cursor to the left of the page; The method provided by the rich text editor is used to obtain the second window position information of the element before the current cursor in the window, including: the current cursor is moved forward by one position so that the changed cursor occupies the position of the element before the current cursor; for the changed cursor, the getSelection() method provided by the rich text editor window is executed according to the default parameters to obtain all the text before the changed cursor and use it as the changed cursor Dom object; the method getRangeAt(0) provided by the changed cursor Dom object is executed to obtain the changed cursor range; the native method getBoundintClientRect() of the changed cursor range is executed to obtain the display area of ​​the changed cursor in the window and return the window position information of the changed cursor in the window, that is, the second window position information of the element before the current cursor in the window is obtained; the changed cursor is moved back by one position to reset; wherein, the second window position information includes: the height and width of the changed cursor itself, the distance from the top of the changed cursor to the top of the page, the distance from the bottom of the changed cursor to the top of the page, the distance from the left of the changed cursor to the left of the page, and the distance from the right of the changed cursor to the left of the page; Whether the current cursor is at the beginning of the line is determined by comparing the offset between the second window position information and the first window position information.

2. The method for determining that the cursor is at the beginning of a line in a rich text editor in a vue environment according to claim 1 is characterized in that: Introducing the rich text editor into a Vue-based web project and configuring the rich text editor in Vue includes: using the npm or yarn command to introduce the rich text editor into a Vue-based web project; introducing the rich text editor into the Vue page; and setting the basic properties of the rich text editor.

3. The method for determining that the cursor is at the beginning of a line in a rich text editor in a vue environment according to claim 1 is characterized in that: Determining whether the current cursor is at the beginning of a line by comparing the offset between the second window position information and the first window position information includes: When the current cursor and the changed cursor have the same shape, if the distance from the top of the current cursor to the top of the page is greater than the distance from the bottom of the cursor to the top of the page after the change, and the distance from the right side of the cursor to the left side of the page after the change minus the distance from the left side of the current cursor to the left side of the page is equal to the width of the rich text editor, then the current cursor is judged to be at the beginning of the line, otherwise the current cursor is judged to be not at the beginning of the line.

4. The method for determining that the cursor is at the beginning of a line in a rich text editor in a vue environment according to claim 3 is characterized in that: When it is determined that the current cursor is not at the beginning of the line, the distance between the current cursor and the beginning of the line is obtained, including: the current cursor moves forward one more position to become a new current cursor, the number of times the current cursor is updated to obtain a new current cursor is recorded, and based on the new current cursor, it is determined again whether the new current cursor is at the beginning of the line; otherwise, the cycle is repeated until the new current cursor is at the beginning of the line, and the final number of times the current cursor is updated to obtain a new current cursor is used as the distance between the current cursor and the beginning of the line, and the new current cursor at the beginning of the line is reset to its original position according to the final number.

5. The method for determining that the cursor is at the beginning of a line in a rich text editor in a vue environment according to claim 4 is characterized in that: After determining the distance between the current cursor and the beginning of the line, an interactive prompt is given as to whether to move the current cursor to the beginning of the line. If the user determines to move the current cursor to the beginning of the line, the reset current cursor is moved to the beginning of the line according to the distance between the current cursor and the beginning of the line.

6. The method for determining that the cursor is at the beginning of a line in a rich text editor in a vue environment according to claim 3 is characterized in that: Compare the height and width of the current cursor with the height and width of the changed cursor to determine whether the current cursor shape is consistent with the changed cursor shape. If the current cursor shape is inconsistent with the changed cursor shape, prompt to ensure that the current cursor shape is consistent with the changed cursor shape.

7. A device for implementing a method for determining that the cursor is at the beginning of a line in a rich text editor in a vue environment, characterized in that: include: At least one processing unit, the processing unit is connected to a storage unit via a bus unit, the storage unit stores a computer program, and when the computer program is executed by the processing unit, the method for determining that the cursor is at the beginning of a line in a rich text editor in a Vue environment as described in any one of claims 1-6 is implemented.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for determining that the cursor is at the beginning of a line in a rich text editor in a Vue environment is implemented as described in any one of claims 1 to 6.