WO2024066995A1 - 一种文本代码的编辑方法及系统 - Google Patents

一种文本代码的编辑方法及系统 Download PDF

Info

Publication number
WO2024066995A1
WO2024066995A1 PCT/CN2023/117325 CN2023117325W WO2024066995A1 WO 2024066995 A1 WO2024066995 A1 WO 2024066995A1 CN 2023117325 W CN2023117325 W CN 2023117325W WO 2024066995 A1 WO2024066995 A1 WO 2024066995A1
Authority
WO
WIPO (PCT)
Prior art keywords
data structure
code block
editing area
text data
code
Prior art date
Application number
PCT/CN2023/117325
Other languages
English (en)
French (fr)
Inventor
袁含晨
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2024066995A1 publication Critical patent/WO2024066995A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/33Intelligent editors

Definitions

  • the embodiments of the present application relate to the field of computer technology, and in particular, to a method and system for editing text codes.
  • the integrated development environment provides a text code editor in which software developers can edit text codes to implement corresponding software functions.
  • the embodiments of the present application provide a text code editing method and system, which supports the editing and storage of multiple sets of text codes, facilitates software developers to quickly replace codes, realizes the replacement or optimization of software functions, and can improve editing efficiency.
  • an embodiment of the present application provides a method for editing a text code, which can be applied to a text code editing system, wherein the editing system performs the following steps: receiving a first operation instruction from a user, wherein the first operation instruction is used to instruct to replace a first code block in the first editing area with a second code block, wherein the second code block is one of the candidate code blocks for replacing the first code block.
  • the first text data structure corresponding to the first editing area is updated; wherein the updated first text data structure does not contain a first subtext data structure for indicating the first code block, and the updated first text data structure contains a second subtext data structure for indicating the second code block.
  • the second code block is displayed in the first editing area.
  • code blocks can be quickly replaced. For example, if a software developer needs to replace or optimize a software function, the original code block can be replaced with an alternative code block, which can effectively improve editing efficiency.
  • the second code block is displayed in the second editing area.
  • Such a display design facilitates the user to quickly determine or locate the alternative code block of the first code block, which can enhance the user's editing experience. Based on this, the editing system can display the first code block in the second editing area according to the updated first text data structure.
  • the second text data structure corresponding to the second editing area before the first text data structure corresponding to the first editing area is updated, the second text data structure corresponding to the second editing area includes the second sub-text data structure and does not include the first sub-text data structure; after the first text data structure corresponding to the first editing area is updated, the second text data structure corresponding to the second editing area includes the first sub-text data structure and does not include the second sub-text data structure.
  • the change of the underlying logic i.e., the text data structure, drives the change of the code block displayed in the front-end interface editing area, thereby ensuring the normal operation of the text code.
  • the updating of the first text data structure corresponding to the first editing area according to the first operation instruction includes: determining the first subtext data structure and the second subtext data structure according to the first operation instruction; replacing the first subtext data structure in the first text data structure with the second subtext data structure according to the mapping relationship between the first subtext data structure and the second subtext data structure.
  • the editing system may receive a second operation instruction from the user, where the second operation instruction is used to indicate one or more of the following: deleting a specified code block in the first editing area, copying a specified code block in the first editing area, pasting the copied code block to a specified position in the first editing area, moving a specified code block in the first editing area to a specified position in the first editing area, or adding a code block to the first editing area.
  • the editing system updates the first text data structure according to the second operation instruction; further, according to the first text data structure, the updated first text is displayed in the first editing area.
  • Code blocks corresponding to data structures In such a design, the text code in the code file is divided into multiple code blocks, which makes it easier for users to edit the code blocks as a whole and improves editing efficiency.
  • the editing system can also determine the code block in the first editing area according to the first text data structure of the first editing area. Such a design can divide the text code displayed in the first editing area into multiple code blocks.
  • an embodiment of the present application provides a text code editing system, comprising: a user interaction unit, for receiving a first operation instruction from a user, wherein the first operation instruction is used to instruct to replace a first code block in the first editing area with a second code block, and the second code block is one of the alternative code blocks for replacing the first code block; a processing unit, for updating a first text data structure corresponding to the first editing area according to the first operation instruction; wherein the updated first text data structure does not include a first sub-text data structure for indicating the first code block, and the updated first text data structure includes a second sub-text data structure for indicating the second code block; the processing unit is also used to display the second code block in the first editing area according to the updated first text data structure.
  • the processing unit is also used to display the first code block in the second editing area according to the updated first text data structure.
  • the second text data structure corresponding to the second editing area includes the second sub-text data structure and does not include the first sub-text data structure; after the processing unit updates the first text data structure corresponding to the first editing area, the second text data structure corresponding to the second editing area includes the first sub-text data structure and does not include the second sub-text data structure.
  • the processing unit is specifically used to: determine the first sub-text data structure and the second sub-text data structure according to the first operation instruction; and replace the first sub-text data structure in the first text data structure with the second sub-text data structure according to the mapping relationship between the first sub-text data structure and the second sub-text data structure.
  • the user interaction unit is also used to receive a second operation instruction from the user, and the second operation instruction is used to indicate one or more of the following: deleting a specified code block in the first editing area, copying a specified code block in the first editing area, pasting the copied code block to a specified position in the first editing area, moving the specified code block in the first editing area to a specified position in the first editing area, or adding a code block in the first editing area; the processing unit is also used to update the first text data structure according to the second operation instruction; the processing unit is also used to display the updated code block corresponding to the first text data structure in the first editing area.
  • the processing unit before the user interaction unit receives the first operation instruction from the user, the processing unit is further used to determine the code block in the first editing area according to the first text data structure of the first editing area.
  • an embodiment of the present application provides a computing device, comprising a processor and a memory; the memory is used to store computer execution instructions; the processor is used to execute the computer execution instructions stored in the memory, so that the computing device executes the method in the first aspect and any possible design of the first aspect.
  • an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes computer program instructions.
  • the computer program instructions When the computer program instructions are executed by a computer device, the computer device executes the method in the first aspect and any possible design of the first aspect.
  • an embodiment of the present application provides a computer program product, which includes instructions.
  • the instructions When the instructions are executed by a computer device, the computer device executes the method in the first aspect and any possible design of the first aspect.
  • FIG1 is a schematic diagram of the architecture of a text code editing system provided in an embodiment of the present application.
  • FIG2 is a flow chart of a text code editing method provided in an embodiment of the present application.
  • FIG3A is a schematic diagram of a text code display provided in an embodiment of the present application.
  • FIG3B is one of schematic diagrams of text code display provided in an embodiment of the present application.
  • FIG3C is a schematic diagram of a text code display provided in an embodiment of the present application.
  • FIG4A is one of the schematic diagrams of the text data structure provided in the embodiment of the present application.
  • FIG4B is one of the schematic diagrams of the text data structure provided in the embodiment of the present application.
  • FIG5A is one of the schematic diagrams of the text data structure provided in an embodiment of the present application.
  • FIG5B is one of the schematic diagrams of the text data structure provided in the embodiment of the present application.
  • FIG6A is one of schematic diagrams of text code display provided in an embodiment of the present application.
  • FIG6B is a schematic diagram of a text code display provided in an embodiment of the present application.
  • FIG6C is one of schematic diagrams of text code display provided in an embodiment of the present application.
  • FIG7 is a flow chart of another text code editing method provided in an embodiment of the present application.
  • FIG8 is one of schematic diagrams of text code display provided in an embodiment of the present application.
  • FIG9 is one of schematic diagrams of text code display provided in an embodiment of the present application.
  • FIG. 10 is a schematic diagram of the structure of a computing device provided in an embodiment of the present application.
  • the at least one (item) involved in the embodiments of the present application indicates one (item) or more (items). More than one (item) refers to two (items) or more than two (items).
  • "And/or" describes the association relationship of the associated objects, indicating that three relationships may exist. For example, A and/or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character "/" generally indicates that the related objects before and after are in an "or” relationship.
  • the editing system 100 of the text code mainly includes a user interaction unit, a processing unit and a storage unit.
  • the user interaction unit interacts with the user (such as a software developer) to provide the user with the function of editing and displaying the text code.
  • the user interaction unit can provide the user with a text code editor, and the user edits the text code in the text code editor, that is, the user interaction unit receives the user's operation instruction for editing the text code through the text code editor; the processing unit can analyze the operation instruction, create or update the relevant text code in the storage unit, and the text data structure corresponding to the text code.
  • the text code is edited and stored in units of code files.
  • a code file corresponds to a page in a software program, that is, the text code in a code file is used to implement the software function of a page in the software program.
  • the text code editor supports the creation of one or more code files, and provides an independent editing area for each code file.
  • the editing area can also be replaced with an editing window. Users can edit the text code in the editing area corresponding to the code file, and accordingly, the text code is displayed in the editing area.
  • the processing unit can monitor and parse the user's operations in the text code editor, and save the code file created and edited by the user in the text code editor in the storage unit; and the processing unit can also parse the text code in the code file, generate a text data structure (text struct) corresponding to the code file, and save the text data structure corresponding to the code file in the storage unit.
  • the text data structure corresponding to a code file includes multiple nodes for indicating the text code in the code file, and the connection relationship between the nodes can reflect the execution (or, running) logic or execution (or, running) order of the text code in the code file.
  • the text data structure can be a tree structure, and a text data structure can correspond to one or more trees.
  • the tree is a hierarchical set composed of a certain number of nodes.
  • a node without a parent node in a tree can be called a root node, and each node in a tree except the root node has one and only one parent node.
  • the method name, structure name or class name in the text code indicated by the node can be saved in the node, or the node can be named as the method name, structure name or class name in the text code indicated by the node.
  • the node can be saved or named as class, function, block, int, set, get, etc.
  • the processing unit can also be described as a text manager, and the nodes in the aforementioned text data structure can also be described as data elements or text nodes.
  • the processing unit can also perform semantic analysis on the text code in the code file to determine (or, identify) the code in the code file. It can be understood that the text data structure corresponding to the code file includes a sub-text data structure for indicating any code block in the multiple code blocks, and the sub-text data structure corresponding to any code block includes one or more nodes.
  • the text code editing system provided in the embodiment of the present application can be an IDE platform.
  • the IDE platform can be built in a local operating system, such as a Windows system, or it can also be other operating systems.
  • the text code editor provided by the user interaction unit can be a text code editor of the front-end interface in the IDE platform, such as vscode, intellij, sublime or other code editors.
  • the storage unit can occupy the resources of the computer memory, or it can be understood that the storage unit belongs to the memory.
  • a code file in the IDE platform can correspond to an editing area in the text code editor, that is, the text code included in the code file can be displayed in the editing area corresponding to the code file.
  • an embodiment of the present application provides a method for editing text code, which can be applied to the aforementioned text code editing system, such as an IDE platform.
  • it is supported to set alternative code blocks. For example, if a user needs to replace or optimize a software function, the original code block can be replaced with an alternative code block, which can effectively improve editing efficiency.
  • the editing method provided in the embodiment of the present application is described in detail below in conjunction with FIG. 2 .
  • the editing method can be executed by the aforementioned text code editing system (hereinafter referred to as the editing system).
  • the editing system receives a first operation instruction from the user.
  • the first operation instruction can be used to instruct to replace the first code block in the first editing area with the second code block.
  • the first code block is a code block in any code file stored in the editing system
  • the second code block is, for example, an alternative code block of the first code block.
  • the alternative code block of the first code block can be used to replace the first code block, and the number of alternative code blocks of the first code block can be 1 or more. It can be understood that when the number of alternative code blocks is 1, that is, the alternative code block of the first code block refers to the second code block; or, when the number of alternative code blocks is greater than 1, the second code block is one of the alternative code blocks of the first code block.
  • the position of the first code block in the first editing area is recorded as the first position, and the first position can be the position of one or more lines of text code included in the first code block in the first editing area.
  • the first code block and the alternative code block of the first code block can be regarded as candidate code blocks that can be inserted into the first position.
  • the alternative code block it is equivalent to providing multiple sets of text codes. For example, if a user (such as a software developer) needs to replace or optimize a software function, the original code block can be replaced with an alternative code block, which is equivalent to replacing one set of text code with another set of text code, thereby optimizing, modifying or upgrading the software function.
  • one code file corresponds to two editing areas, for example, a first editing area and a second editing area.
  • the first editing area displays a set of text codes that are currently in effect, or can also be replaced by the description that the first editing area displays a set of text codes to be run, and the set of text codes displayed in the first editing area can include multiple code blocks;
  • the second editing area displays alternative code blocks for some or all of the code blocks in the first editing area, wherein the number of alternative code blocks for a code block can be one or more, and it can be understood that the alternative code blocks in the second editing area are not effective or do not run.
  • an editing area that displays alternative code blocks is additionally provided to facilitate users to quickly select replacement code blocks with corresponding alternative code blocks, thereby realizing switching between multiple sets of text codes.
  • the first code block is displayed in the first editing area
  • the second code block is displayed in the second editing area.
  • the code display method shown in Figure 3A can be referred to.
  • the first editing area and the second editing area of the code file 1 are displayed side by side, and the first code block includes the text code from the r1th line to the r2th line in the first editing area, and the second code block includes the text code from the r1th line to the r3th line in the second editing area.
  • r1, r2, and r3 are all positive integers, and r2 and r3 can be the same or different.
  • the second code block displayed in the second editing area is the same as the starting line of the first code block displayed in the first editing area, and such a design can facilitate users to quickly determine the alternative code blocks of the first code block.
  • An optional box is set on the second code block. When the user checks the optional box, it is equivalent to inputting the first operation instruction, and the editing system can receive the first operation instruction input by the user. The user checks the optional box, indicating that the user desires to replace the first code block in the first coding area with the second code block, so the first operation instruction may indicate to replace the first code block in the first coding area with the second code block.
  • S201 may also be replaced with: in response to the user's operation, determining the user's first operation instruction.
  • the first editing area and the second editing area of the code file 1 are displayed side by side, and the first code block includes the text code from line r1 to line r2 in the first editing area; the second editing area uses line r1 as the starting position to display multiple alternative code blocks for the first code block.
  • the text code of one of the alternative code blocks is completely displayed in the second editing area, such as occupying lines r1 to r3 in the second editing area, and r1, r2, and r3 are all positive integers. r2 and r3 may be the same or different.
  • An alternative code block that displays the text code completely is recorded as the second code block, and a second drop-down option box is set at the position where the second code block is located; the remaining alternative code blocks except the second code block are displayed in the second drop-down option box with identification information, without displaying the complete text code.
  • the identification information of an alternative code block can be the number, name or other information that can uniquely indicate the alternative code block of the alternative code block, and the embodiment of the present application is not limited to this.
  • the second code block displayed in the second editing area is the same as the starting line of the first code block displayed in the first editing area, and the user can quickly determine the alternative code block of the first code block based on the position of the first code block.
  • the identification information of all alternative code blocks of the first code block can be included in the second drop-down option box, supporting the user to select an alternative code block as the second code block in the second drop-down option box, which is fully displayed in the second editing area.
  • FIG3B illustrates the numbers of all alternative code blocks including the first code block in the second drop-down option box, such as Alternative 1, Alternative 2, and Alternative 3; wherein the alternative code block indicated by Alternative 1 is displayed in the second editing area as a complete text code.
  • an optional box may be provided on the second code block.
  • the editing system may receive the first operation instruction input by the user.
  • the user checks the optional box, indicating that the user desires to replace the first code block in the first coding area with the second code block, so the first operation instruction may indicate to replace the first code block in the first coding area with the second code block.
  • S201 may also be replaced with the description: in response to the user's operation, determining the user's first operation instruction.
  • a code file corresponds to an editing area, for example, called the first editing area.
  • the first editing area displays a set of text codes currently in effect, or can also be replaced by describing that the first editing area displays a set of text codes to be run, and the set of text codes displayed in the first editing area can include multiple code blocks.
  • the multiple code blocks in the first editing area include the first code block, and the editing system stores the alternative code blocks of the first code block.
  • the number of the alternative code blocks of the first code block can be 1 or more.
  • a first drop-down option box is provided at the position where the first code block is located, and the first drop-down option box can include the identification of all the alternative code blocks of the first code block.
  • the identification of an alternative code block is, for example, the number, name or other information that can be used to indicate the alternative code block of the alternative code block, and the embodiment of the present application does not limit this.
  • the first code block displayed in the first editing area is an effective and executable code block, and the alternative code blocks of the first code block are not displayed, nor are they effective or not run.
  • the first drop-down option box includes the numbers of all alternative code blocks of the first code block, such as Alternative 1, Alternative 2, and Alternative 3.
  • the alternative code block checked by the user is recorded as the second code block (for example, the user checked "Alternative 1"), and the user checks the second code block, indicating that the user expects to replace the first code block in the first coding area with the second code block, so the first operation instruction can indicate that the first code block in the first coding area is replaced with the second code block.
  • S201 can also be replaced with the description: in response to the user's operation, determine the user's first operation instruction.
  • S201 is performed by a user interaction unit in the editing system, and the user interaction unit receives a first operation instruction from the user.
  • the user interaction unit provides a text code editor for the user, when the user triggers an editing operation of replacing a first code block in a first editing area with a second code block in the text code editor, the user interaction unit receives the first operation instruction from the user.
  • S202 The editing system updates a first text data structure corresponding to a first editing area according to a first operation instruction.
  • the storage unit of the editing system can pre-store the first text data structure corresponding to the first editing area, and the connection relationship between the nodes included in the first text data structure can reflect the execution logic or execution order of the complete text code displayed in the first editing area.
  • the first text data structure can include a sub-text data structure for indicating any code block in the multiple code blocks.
  • the storage unit of the editing system can also pre-store the second text data structure. The second text data structure is used to indicate the alternative code blocks of some or all code blocks in the text code displayed in the first editing area.
  • the second text data structure may include the sub-text data structure corresponding to each alternative code block, and there is no connection relationship between the sub-text data structures corresponding to different alternative code blocks. It can be understood that the second text data structure includes multiple independent sub-text data structures. Among them, the sub-text data structure corresponding to an alternative code block can reflect the execution logic or execution order of the text code in the alternative code block. Taking the first code block in which the complete text code is displayed in the first editing area, and the candidate code blocks of the first code block include the second code block and the third code block as an example, the second text data structure may include a second subtext data structure for indicating the second code block, and the second text data structure includes a third subtext data structure for indicating the third code block. The second subtext data structure and the third subtext data structure are independent of each other and have no connection relationship.
  • mapping relationship between the subtext data structure corresponding to the code block and the subtext data structure corresponding to each alternative code block of the code block.
  • the alternative code blocks of the first code block include the second code block and the third code block
  • the first subtext data structure corresponding to the first code block and the second subtext data structure corresponding to the second code block have a mapping relationship.
  • the first subtext data structure corresponding to the first code block and the third subtext data structure corresponding to the third code block have a mapping relationship. Structures have mapping relationships.
  • the editing system can determine the first subtext data structure corresponding to the first code block and the second subtext data structure corresponding to the second code block; further, the editing system can replace the first subtext data structure in the first text data structure in the first editing area with the second subtext data structure based on the mapping relationship between the first subtext data structure and the second subtext data structure.
  • the editing system can determine the position of the second subtext structure to be inserted into the first text data structure based on the mapping relationship.
  • the root node in the first subtext data structure is located at position 1 in the first text data structure.
  • the editing system executes S202, the root node in the second subtext data structure can be inserted into position 1 in the first text data structure.
  • the first text data structure contains a first subtext data structure for indicating the first code block
  • the second text data structure contains a second subtext data structure for indicating the second code block.
  • the updated first text data structure does not contain the first subtext data structure, but contains the second subtext data structure; accordingly, in S202, the editing system can also update the second text data structure according to the first operation instruction, so in FIG4B, the updated second text data structure contains the first subtext data structure, but does not contain the second subtext data structure.
  • the drop-down option box on the second code block includes the identification information of multiple candidate code blocks of the first code block.
  • the first text data structure includes a first subtext data structure for indicating the first code block
  • the second text data structure includes a second subtext data structure for indicating the second code block, and a third subtext data structure for indicating the third code block.
  • the updated first text data structure does not include the first subtext data structure, but includes the second subtext data structure; accordingly, in S202, the editing system can also update the second text data structure according to the first operation instruction, so in Figure 5B, the updated second text data structure includes the first subtext data structure and the third subtext data structure, but does not include the second subtext data structure.
  • the corresponding FIG. 3C illustrates that the first code block is displayed in the first editing area, and the first drop-down option box includes the numbering of all the alternative code blocks of the first code block.
  • the alternative code blocks of the first code block including the second code block and the third code block it can be seen from FIG. 5A that before executing S202, the first text data structure includes a first subtext data structure for indicating the first code block, and the second text data structure includes a second subtext data structure for indicating the second code block, and a third subtext data structure for indicating the third code block.
  • there is no connection relationship between the second subtext data structure and the third subtext data structure it can be referred to again in FIG.
  • the editing system can also update the second text data structure according to the first operation instruction, so in FIG. 5B, the updated second text data structure includes the first subtext data structure and the third subtext data structure, but does not include the second subtext data structure.
  • the solution in step S202 can be executed by a processing unit in the editing system, that is, the processing unit can update the first text data structure corresponding to the first editing area according to the first operation instruction.
  • the processing unit can update the first text data structure corresponding to the first editing area according to the first operation instruction.
  • S203 The editing system displays the second code block in the first editing area according to the updated first text data structure.
  • step S203 can be understood as the processing feedback of the editing system on the user operation.
  • step S203 can be performed by a processing unit in the editing system, that is, the processing unit can display the second code block in the first editing area according to the updated first text data structure.
  • the position in the first editing area that originally displayed the first code block will be changed to display the second code block.
  • the text code of the first editing area has changed.
  • the text code of the first editing area before S201 is recorded as the first set of text codes
  • the text code of the first editing area after executing S201 to S203 is recorded as the second set of text codes.
  • the difference between the first set of text codes and the second set of text codes is that the first set of text codes includes the first code block but does not include the second code block; the second set of text codes includes the second code block but does not include the first code block.
  • the result shown in FIG6A can be obtained. That is, in response to the operation of the user checking the optional box of the second code block shown in FIG3A, by executing S202 and S203, the processing result shown in FIG6A is obtained, and the processing result is that the second code block is displayed at the position where the first code block originally was in the first editing area. Accordingly, The first code block is displayed at the position where the second code block was originally located in the second editing area, which can be understood as swapping the positions of the first code block and the second code block.
  • the result shown in FIG. 6B can be obtained. That is, in response to the operation of the user checking the optional box of the second code block shown in FIG. 3A , by executing S202 and S203, the processing result shown in FIG. 6B is obtained, and the processing result is that the second code block is displayed to the position where the first code block was originally located in the first editing area, and accordingly, the first code block is displayed at the position where the second code block was originally located in the second editing area. It can be understood that the positions of the first code block and the second code block are interchanged.
  • the second drop-down option box in FIG. 6B is located at the position where the first code block is located in the second editing area.
  • the result illustrated in FIG. 6C can be obtained. That is, in response to the operation of the user selecting Alternative 1 in the first drop-down option box illustrated in FIG. 3C , the alternative code block indicated by Alternative 1 is regarded as the second code block.
  • the processing result is that the second code block is displayed at the position where the original first code block is located in the first editing area, and the first drop-down option box includes the number of the first code block (for example, Alternative 4), and does not include the number of the second code block (such as Alternative 1), that is, it can be understood that after S202 and S203, the first code block can be regarded as the alternative code block of the second code block, and the first code block can be recorded in the first drop-down option box with a number (for example, Alternative 4).
  • the editing system can store and display the alternative code blocks of some or all code blocks in the set of text codes, and can establish a mapping relationship between the code blocks and the corresponding alternative code blocks based on the text data structure.
  • the alternative code blocks it is equivalent to providing multiple sets of text codes. For example, if the user (such as a software developer) needs to replace or optimize the software function, the alternative code blocks can be used to replace the original code blocks, which is equivalent to replacing one set of text codes with another set of text codes, so that the optimization, modification or upgrade of the software function can be realized, which can effectively improve the editing efficiency.
  • the editing system can also support the user to perform other editing operations on the code block in the first editing area except switching the alternative code block, such as adding, deleting, copying, pasting, moving, etc., which can improve the editing efficiency of the text code in the first editing area.
  • an editing method is introduced, which can be used to edit the code block.
  • the editing system receives a second operation instruction from the user.
  • the second operation instruction is used to indicate one or more of the following: deleting the specified code block in the first editing area, copying the specified code block in the first editing area, pasting the copied code block to the specified position in the first editing area, moving the specified code block in the first editing area to the specified position in the first editing area, or adding a code block in the first editing area.
  • the aforementioned designated code block may include one or more code blocks in the first editing area indicated by the user through the second operation instruction.
  • the designated position may be a position in the first editing area indicated by the user through the second operation instruction.
  • the specified code block refers to the fourth code block in the first editing area, and the fourth code block includes the text code from the r4th line to the r5th line in the first editing area.
  • the editing system can receive the second operation instruction entered by the user, that is, the second operation instruction is used to indicate that the fourth code block is moved to the specified position in the first editing area, and the specified position includes multiple lines with the r6th line as the starting line and the r7th line as the ending line.
  • the difference between r7 and r6 is equal to the difference between r5 and r4.
  • the way of dividing the code block can realize the grouping of the text code in the code file, and a code block is taken as a whole. In such a design, the user can directly perform an editing operation on the entire code block without first selecting the text code to be moved and then moving it, which can improve editing efficiency and user experience.
  • step S701 may be performed by a user interaction unit in the editing system, and the user interaction unit receives the second operation instruction of the user.
  • the user interaction unit provides a text code editor for the user, and when the user triggers an editing operation of a specified code block in the text code editor, the user interaction unit receives the second operation instruction of the user.
  • S702 The editing system updates the first text data structure corresponding to the first editing area according to the second operation instruction.
  • the definition of the first text data structure may be understood by referring to the description in S202, and will not be elaborated in detail in this embodiment of the present application.
  • the editing system can determine the user's editing requirements for the code block in the first editing area according to the second operation instruction, and then The subtext data structure in the first text data structure corresponding to the first editing area is modified according to the editing requirements.
  • the editing system can determine that the user expects to delete the specified code block from the first editing area; further, the editing system can delete the sub-text data structure corresponding to the specified code block in the first text data structure.
  • the second operation instruction instructs to copy the specified code block in the first editing area, and to paste the copied code block to the specified position in the first editing area. Then the editing system can determine that the user expects to copy and paste the specified code block in the first editing area, and indicates the specified position of the paste.
  • the editing system can determine the fourth sub-text data structure corresponding to the fourth code block and the fifth sub-text data structure corresponding to the fifth code block in the first text data structure; and then according to the specific code execution logic, such as executing the fifth code block first and then executing the copied and pasted fourth code block, the editing system can retain the original fourth sub-text data structure in the first text data structure, and insert the fourth sub-text data structure after the leaf node of the fifth sub-text data structure.
  • the editing system can determine that the user expects to move the specified code block in the first editing area and indicates the specified position (or target position) of the move; then, the editing system can delete the subtext data structure corresponding to the specified code block in the first text data structure.
  • the editing system can determine the fourth subtext data structure corresponding to the fourth code block and the fifth subtext data structure corresponding to the fifth code block in the first text data structure; then, according to the specific code execution logic, such as executing the fifth code block first and then executing the copied and pasted fourth code block, the editing system can move the original fourth subtext data structure in the first text data structure and insert it behind the leaf node of the fifth subtext data structure.
  • the second operation instruction instructs to add a code block in the first editing area, and the user enters the text code of the new code block in the first editing area.
  • the editing system can then obtain the text code and input position of the new code block entered by the user through the first editing area, and then the editing system can add a node corresponding to the new code block in the first text data structure according to specific code execution logic.
  • the solution in step S702 can be executed by a processing unit in the editing system, that is, the processing unit can update the first text data structure corresponding to the first editing area according to the second operation instruction.
  • the processing unit updates the first text data structure can be understood with reference to the above content, and this embodiment of the application will not be repeated.
  • S703 The editing system displays the code block corresponding to the updated first text data structure in the first editing area according to the updated first text data structure.
  • step S703 can be understood as the processing feedback of the editing system to the user operation.
  • step S703 can be performed by a processing unit in the editing system, that is, the processing unit can display the code block corresponding to the updated first text data structure in the first editing area according to the updated first text data structure.
  • the result shown in Figure 9 can be obtained. That is, in response to the user's move operation on the fourth code block shown in Figure 8, by executing S702 and S703, the processing result shown in Figure 9 is obtained, and the processing result is that the fourth code block is displayed at the position of the r6th line to the r7th line in the first editing area.
  • the embodiment shown in Figure 7 may be applied in combination with the embodiment shown in Figure 2 above.
  • a user may edit part or all of the code blocks in the first editing area introduced in the embodiment shown in Figure 2 based on the method provided by the embodiment shown in Figure 7; or, the embodiment shown in Figure 7 may not be combined with the embodiment shown in Figure 2, but may be applied separately.
  • the embodiments of the present application are not limited to this, and do not limit the execution order of the two embodiments of Figures 2 and 7.
  • the embodiments of the present application further provide a computing device 1000.
  • the computing device 1000 includes: a bus 102, a processor 104, a memory 106, and a communication interface 108.
  • the processor 104, the memory 106, and the communication interface 108 communicate with each other through the bus 102.
  • the computing device 1000 can be a laptop computer, a desktop computer, a server, or a terminal device. It should be understood that the present application does not limit the number of processors and memories of the computing device 1000.
  • the bus 102 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc.
  • the bus may be divided into an address bus, a data bus, a control bus, etc.
  • FIG. 10 is represented by only one line, but does not mean that there is only one bus or one type of bus.
  • the bus 104 may include a path for transmitting information between various components of the computing device 1000 (e.g., the memory 106, the processor 104, and the communication interface 108).
  • the processor 104 may include a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
  • CPU central processing unit
  • GPU graphics processing unit
  • MP microprocessor
  • DSP digital signal processor
  • processors such as DSP.
  • the memory 106 may include a volatile memory, such as a memory, for example, a random access memory (RAM).
  • the memory 106 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid state drive (SSD).
  • ROM read-only memory
  • HDD hard disk drive
  • SSD solid state drive
  • the memory is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to this.
  • the memory in the embodiment of the present application may also be a circuit or any other device that can realize a storage function, used to store program instructions and/or data.
  • the memory 106 stores executable program codes, and the processor 104 executes the executable program codes to respectively implement the functions of the aforementioned user interaction unit and the processing unit, thereby implementing the text code editing method. That is, the memory 106 stores instructions for the text code editing system to execute the text code editing method. The memory 106 also stores code files and text data structures corresponding to the code files.
  • the communication interface 108 uses, for example but not limited to, a transceiver module such as a network interface card or a transceiver to implement communication between the computing device 1000 and other devices or a communication network.
  • a transceiver module such as a network interface card or a transceiver to implement communication between the computing device 1000 and other devices or a communication network.
  • the communication interface 108 in the computing device 1000 may also be an input-output circuit that can input information (or receive information) and output information (or send information).
  • the processor is an integrated processor or microprocessor or integrated circuit or logic circuit, and the processor can determine output information based on input information.
  • the coupling in the embodiment of the present application is an indirect coupling or communication connection between devices, units or modules, which can be electrical, mechanical or other forms, and is used for information exchange between devices, units or modules.
  • the processor 104 may cooperate with the memory 106 and the communication interface 108.
  • the specific connection medium between the above-mentioned processor 104, memory 106 and communication interface 108 is not limited in the embodiment of the present application.
  • the embodiment of the present application also provides a computer program product including instructions.
  • the computer program product may be a software or program product including instructions that can be run on a computing device or stored in any available medium.
  • the computing device cluster executes the above-mentioned editing system applied to text code for executing the editing method of the text code, or the computing device cluster executes the above-mentioned editing system applied to text code for executing the editing method of the text code.
  • the embodiment of the present application also provides a computer-readable storage medium.
  • the computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media.
  • the available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk).
  • the computer-readable storage medium includes instructions that instruct a computing device cluster to execute the above-mentioned editing system applied to the text code for executing the editing method of the text code, or instruct a computing device cluster to execute the above-mentioned editing system applied to the text code for executing the editing method of the text code.
  • the examples may reference each other, for example, the methods and/or terms between method embodiments may reference each other, for example, the functions and/or terms between system embodiments may reference each other, for example, the functions and/or terms between system examples and method examples may reference each other.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Artificial Intelligence (AREA)
  • Stored Programmes (AREA)
  • Document Processing Apparatus (AREA)

Abstract

本申请提供一种文本代码的编辑方法及系统,应用于计算机技术领域。该方法包括:接收用户的第一操作指令,第一操作指令用于指示将第一编辑区中的第一代码块替换为第二代码块,第二代码块为用于替换第一代码块的备选代码块中的一个;根据第一操作指令,更新第一编辑区对应的第一文本数据结构;其中,更新后的第一文本数据结构中不包含用于指示第一代码块的第一子文本数据结构,且更新后的第一文本数据结构中包含用于指示第二代码块的第二子文本数据结构;根据更新后的第一文本数据结构,在第一编辑区中显示第二代码块。本申请能够提升编辑效率。

Description

一种文本代码的编辑方法及系统
相关申请的交叉引用
本申请要求在2022年09月29日提交中华人民共和国知识产权局、申请号为202211204858.0、申请名称为“一种文本代码的编辑方法及系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及计算机技术领域,尤其涉及一种文本代码的编辑方法及系统。
背景技术
集成开发环境(integrated development environment,IDE)提供文本代码编辑器,软件开发人员可以在文本代码编辑器中编辑文本代码,以实现相应的软件功能。
软件开发人员在通过文本代码编辑器实现软件功能时,通常会反复修改文本代码,最终在文本代码编辑器中只保留一套用于实现软件功能的文本代码,较为单一。如果软件开发人员需要更换或优化软件功能,则需要重新对该套文本代码进行修改,效率低下。
发明内容
本申请实施例提供一种文本代码的编辑方法及系统,支持多套文本代码的编辑与存储,便于软件开发人员快速替换代码,实现软件功能的更换或优化,能够提升编辑效率。
第一方面,本申请实施例提供一种文本代码的编辑方法,该编辑方法可以应用于文本代码的编辑系统,由该编辑系统执行如下步骤:接收用户的第一操作指令,所述第一操作指令用于指示将所述第一编辑区中的第一代码块替换为第二代码块,所述第二代码块为用于替换所述第一代码块的备选代码块中的一个。根据所述第一操作指令,更新所述第一编辑区对应的第一文本数据结构;其中,更新后的所述第一文本数据结构中不包含用于指示所述第一代码块的第一子文本数据结构,且更新后的所述第一文本数据结构中包含用于指示所述第二代码块的第二子文本数据结构。以及,根据更新后的所述第一文本数据结构,在所述第一编辑区中显示所述第二代码块。
上述设计中,通过设置备选代码块,可以实现快速更换代码块。例如,如果软件开发人员需要更换或优化软件功能,则利用备选代码块替换原有代码块即可,能够有效提升编辑效率。
在一种可能的设计中,在编辑系统获取用户的第一操作指令之前,所述第二代码块显示在第二编辑区中。这样的显示设计,便于用户快速确定或定位第一代码块的备选代码块,能够提升用户的编辑体验。基于此,编辑系统可以根据更新后的所述第一文本数据结构,在所述第二编辑区中显示所述第一代码块。
在一种可能的设计中,在更新所述第一编辑区对应的第一文本数据结构之前,所述第二编辑区对应的第二文本数据结构包含所述第二子文本数据结构,且不包含所述第一子文本数据结构;在更新所述第一编辑区对应的第一文本数据结构之后,所述第二编辑区对应的所述第二文本数据结构包含所述第一子文本数据结构,且不包含所述第二子文本数据结构。这样的设计中,通过底层逻辑即文本数据结构的变更,带动前端界面编辑区中显示代码块的变更,能够保证文本代码的正常运行。
在一种可能的设计中,所述第一子文本数据结构与用于指示所述第一代码块的备选代码块的文本数据结构之间存在映射关系;所述根据所述第一操作指令,更新所述第一编辑区对应的第一文本数据结构,包括:根据所述第一操作指令,确定所述第一子文本数据结构和所述第二子文本数据结构;根据所述第一子文本数据结构与所述第二子文本数据结构之间的映射关系,将所述第一文本数据结构中的所述第一子文本数据结构替换为所述第二子文本数据结构。这样的设计,便于快速替换文本数据结构中的子文本数据结构。
在一种可能的设计中,编辑系统可以接收所述用户的第二操作指令,所述第二操作指令用于指示如下中的一项或多项:删除所述第一编辑区中的指定代码块,对所述第一编辑区中的指定代码块进行复制,将复制的代码块粘贴到所述第一编辑区中的指定位置,将所述第一编辑区中的指定代码块移动到第一编辑区中指定位置,或,在所述第一编辑区中添加代码块。编辑系统根据所述第二操作指令,更新所述第一文本数据结构;进而,根据所述第一文本数据结构,在所述第一编辑区中显示更新后的所述第一文本 数据结构对应的代码块。这样的设计中,将代码文件中的文本代码划分为多个代码块,便于用户对代码块整体进行编辑操作,能够提升编辑效率。
在一种可能的设计中,编辑系统在获取用户的第一操作指令之前,还可以根据所述第一编辑区的第一文本数据结构确定所述第一编辑区中的代码块。这样的设计,可以将第一编辑区中显示的文本代码划分为多个代码块。
第二方面,本申请实施例提供一种文本代码的编辑系统,包括:用户交互单元,用于接收用户的第一操作指令,所述第一操作指令用于指示将所述第一编辑区中的第一代码块替换为第二代码块,所述第二代码块为用于替换所述第一代码块的备选代码块中的一个;处理单元,用于根据所述第一操作指令,更新所述第一编辑区对应的第一文本数据结构;其中,更新后的所述第一文本数据结构中不包含用于指示所述第一代码块的第一子文本数据结构,且更新后的所述第一文本数据结构中包含用于指示所述第二代码块的第二子文本数据结构;所述处理单元,还用于根据更新后的所述第一文本数据结构,在所述第一编辑区中显示所述第二代码块。
在一种可能的设计中,在用户交互单元接收用户的第一操作指令之前,所述第二代码块显示在第二编辑区中;所述处理单元,还用于根据更新后的所述第一文本数据结构,在所述第二编辑区中显示所述第一代码块。
在一种可能的设计中,在所述处理单元更新所述第一编辑区对应的第一文本数据结构之前,所述第二编辑区对应的第二文本数据结构包含所述第二子文本数据结构,且不包含所述第一子文本数据结构;在所述处理单元更新所述第一编辑区对应的第一文本数据结构之后,所述第二编辑区对应的第二文本数据结构包含所述第一子文本数据结构,且不包含所述第二子文本数据结构。
在一种可能的设计中,所述第一子文本数据结构和用于指示所述第一代码块的备选代码块的文本数据结构之间存在映射关系;所述处理单元,具体用于:根据所述第一操作指令,确定所述第一子文本数据结构和所述第二子文本数据结构;根据所述第一子文本数据结构与所述第二子文本数据结构之间的映射关系,将所述第一文本数据结构中的所述第一子文本数据结构替换为所述第二子文本数据结构。
在一种可能的设计中,所述用户交互单元,还用于接收所述用户的第二操作指令,所述第二操作指令用于指示如下中的一项或多项:删除所述第一编辑区中的指定代码块,对所述第一编辑区中的指定代码块进行复制,将复制的代码块粘贴到所述第一编辑区中的指定位置,将所述第一编辑区中的指定代码块移动到第一编辑区中指定位置,或,在所述第一编辑区中添加代码块;所述处理单元,还用于根据所述第二操作指令,更新所述第一文本数据结构;所述处理单元,还用于在所述第一编辑区中显示更新后的所述第一文本数据结构对应的代码块。
在一种可能的设计中,在用户交互单元接收用户的第一操作指令之前,所述处理单元,还用于根据所述第一编辑区的第一文本数据结构确定所述第一编辑区中的代码块。
第三方面,本申请实施例提供一种计算设备,所述计算设备包括处理器和存储器;所述存储器用于存储计算机执行指令;所述处理器用于执行所述存储器所存储的计算机执行指令,以使所述计算设备执行第一方面及第一方面的任意一个可能的设计中的方法。
第四方面,本申请实施例提供一种计算机可读存储介质,所述计算机可读存储介质包括计算机程序指令,当所述计算机程序指令被计算机设备运行时,使得所述计算机设备执行第一方面及第一方面的任意一个可能设计中的方法。
第五方面,本申请实施例提供一种计算机程序产品,所述计算机程序产品包含指令,当所述指令被计算机设备运行时,使得所述计算机设备执行第一方面及第一方面的任意一个可能设计中的方法。
附图说明
图1为本申请实施例提供的一种文本代码的编辑系统的架构示意图;
图2为本申请实施例提供的一种文本代码的编辑方法流程示意图;
图3A为本申请实施例提供的文本代码显示的示意图之一;
图3B为本申请实施例提供的文本代码显示的示意图之一;
图3C为本申请实施例提供的文本代码显示的示意图之一;
图4A为本申请实施例提供的文本数据结构示意图之一;
图4B为本申请实施例提供的文本数据结构示意图之一;
图5A为本申请实施例提供的文本数据结构示意图之一;
图5B为本申请实施例提供的文本数据结构示意图之一;
图6A为本申请实施例提供的文本代码显示的示意图之一;
图6B为本申请实施例提供的文本代码显示的示意图之一;
图6C为本申请实施例提供的文本代码显示的示意图之一;
图7为本申请实施例提供的另一种文本代码的编辑方法流程示意图;
图8为本申请实施例提供的文本代码显示的示意图之一;
图9为本申请实施例提供的文本代码显示的示意图之一;
图10为本申请实施例提供的计算设备的结构示意图。
具体实施方式
为了使本申请实施例的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施例作进一步地详细描述。
本申请实施例如下涉及的至少一个(项),指示一个(项)或多个(项)。多个(项),是指两个(项)或两个(项)以上。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。字符“/”一般表示前后关联对象是一种“或”的关系。
本申请实施例如下描述中所提到的术语“包括”和“具有”以及它们的任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括其他没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其它步骤或单元。需要说明的是,本申请实施例中,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请实施例中被描述为“示例性的”或者“例如”的任何方法或设计方案不应被解释为比其它方法或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。
本申请实施例提供的技术可以应用于文本代码的编辑系统。如图1示意,该文本代码的编辑系统100主要包括用户交互单元、处理单元以及存储单元。其中,用户交互单元与用户(例如软件开发人员)交互,为用户提供文本代码编辑、显示的功能。例如用户交互单元可以为用户提供文本代码编辑器,用户在文本代码编辑器中编辑文本代码,即用户交互单元通过文本代码编辑器接收用户的编辑文本代码的操作指令;处理单元可以分析该操作指令,在存储单元中创建或者更新相关的文本代码,以及文本代码对应的文本数据结构。
具体地,文本代码以代码文件为单位进行编辑以及存储,例如在软件功能实现场景中,一个代码文件对应软件程序中的一个页面,即一个代码文件中的文本代码用于实现软件程序中一个页面的软件功能。文本代码编辑器中支持创建一个或多个代码文件,针对各个代码文件提供独立的编辑区,编辑区也可以替换描述为编辑窗口。用户可以在代码文件对应的编辑区中编辑文本代码,相应地,文本代码显示在编辑区中。
处理单元可以监控并解析用户在文本代码编辑器中的操作,将用户在文本代码编辑器中创建编辑的代码文件保存在存储单元;以及处理单元还可以解析代码文件中的文本代码,生成代码文件对应的文本数据结构(text struct),并将代码文件对应的文本数据结构保存在存储单元。其中,一个代码文件对应的文本数据结构包括用于指示该代码文件中的文本代码的多个节点,节点之间的连接关系可以反映该代码文件中文本代码的执行(或,运行)逻辑或执行(或,运行)顺序。可选的,文本数据结构可以是一种树结构,一个文本数据结构可以对应一个或多个树。针对一个树而言,该树是由一定数量的节点组成的一个有层次关系的集合,一个树中没有父节点的节点可以称为根节点,一个树中除根节点以外的每个节点有且只有一个父节点。
可选的,可以在节点中保存该节点所指示文本代码中的方法名称、结构体名称或类名称,或者将节点命名为该节点所指示文本代码中的方法名称、结构体名称或类名称。例如,节点可以保存或者命名为class、function、block、int、set、get等等。可选的,处理单元也可以描述为文本管理单元(text manager),前述文本数据结构中的节点也可以描述为数据元素、或文本节点。
处理单元还可以对代码文件中的文本代码进行语义分析,以确定(或,识别)该代码文件中的代码 块。可以理解的是,该代码文件对应的文本数据结构中包括用于指示多个代码块中任一代码块的子文本数据结构,任一代码块对应的子文本数据结构包括一个或多个节点。
作为示例,本申请实施例提供的文本代码的编辑系统可以是IDE平台。IDE平台可以在本地操作系统中搭建,该操作系统例如为Windows系统,或者也可以是其他操作系统。其中,用户交互单元提供的文本代码编辑器可以是IDE平台中前端界面的文本代码编辑器,例如该文本代码编辑器可以是vscode、intellij、sublime或者其他代码编辑器。存储单元可以占用计算机内存的资源,或者可以理解为,存储单元属于内存。目前,IDE平台中的一个代码文件可对应于文本代码编辑器中的一个编辑区,即,该代码文件包括的文本代码可以显示在该代码文件对应的编辑区。软件开发人员可以在该代码文件对应的编辑区中修改文本代码,最终只保留用于实现软件功能的一套文本代码。这样实现软件功能的方式只有一套代码方案,较为单一。如果软件开发人员需要更换或优化软件功能,则需要重新对该套文本代码进行修改,效率低下。
基于此,本申请实施例提供一种文本代码的编辑方法,该方法可以应用于前述文本代码的编辑系统,如应用于IDE平台。在本申请实施例中,支持设置备选代码块,例如,如果用户需要更换或优化软件功能,则利用备选代码块替换原有代码块即可,能够有效提升编辑效率。
下面结合图2对本申请实施例提供的编辑方法进行详细说明如图2示意,该编辑方法可由前述的文本代码的编辑系统(以下简称编辑系统)执行。
S201,编辑系统接收用户的第一操作指令。第一操作指令可用于指示将第一编辑区中的第一代码块替换为第二代码块。其中,第一代码块是编辑系统存储的任一代码文件中的一个代码块,第二代码块例如为第一代码块的备选代码块。其中,第一代码块的备选代码块可用于替换第一代码块,第一代码块的备选代码块的数量可以为1个或多个。可以理解的是,当备选代码块的数量为1个时,即第一代码块的备选代码块指的是第二代码块;或者,当备选代码块的数量大于1个时,第二代码块是第一代码块的备选代码块中的一个。此外,将第一代码块在第一编辑区中的位置记作第一位置,该第一位置可以是第一代码块包括的一行或多行文本代码在第一编辑区中的位置。基于此,还可以理解的是,第一代码块和第一代码块的备选代码块均可以看作是能够插入该第一位置的候选代码块。通过设置备选代码块,相当于提供了多套文本代码。例如,如果用户(例如软件开发人员)需要更换或优化软件功能,则可利用备选代码块替换原有代码块,相当于用一套文本代码替换了另一套文本代码,从而可以实现软件功能的优化、修改或升级等。
在一种可选的实施方式中,一个代码文件对应两个编辑区,例如分别为第一编辑区和第二编辑区。其中,第一编辑区显示当前生效的一套文本代码,或者也可以替换描述为第一编辑区显示待运行的一套文本代码,第一编辑区显示的一套文本代码可包含多个代码块;第二编辑区显示第一编辑区中的部分或全部代码块的备选代码块,其中,一个代码块的备选代码块的数量可以是1个或多个,可以理解为,第二编辑区中的备选代码块不生效或不运行。在显示生效文本代码的编辑区基础上,另外设置显示备选代码块的编辑区,便于用户快速选择替换代码块为相应的备选代码块,实现多套文本代码之间的切换。
在S201中,第一代码块显示在第一编辑区,第二代码块显示在第二编辑区。以第一代码块的备选代码块数量为1个为例,可参考如图3A示意的代码显示方式。代码文件1的第一编辑区和第二编辑区并排显示,第一代码块包括第一编辑区中第r1行到第r2行的文本代码,第二代码块包括第二编辑区中第r1行到第r3行的文本代码。其中,r1、r2、r3均为正整数,r2与r3可以相同或者不同。也可以理解为,第二编辑区中显示的第二代码块与第一编辑区中显示的第一代码块的起始行相同,这样的设计可以方便用户快速确定第一代码块的备选代码块。第二代码块上设置有一个可选框,当用户勾选该可选框时,相当于输入了第一操作指令,则编辑系统可以接收用户输入的第一操作指令。用户勾选该可选框,表明用户期望将第一编码区中的第一代码块替换为第二代码块,因此第一操作指令可指示将第一编码区中的第一代码块替换为第二代码块。可选的,S201也可以替换描述为:响应于用户的操作,确定该用户的第一操作指令。
再以第一代码块的备选代码块的数量为多个为例,可参考如图3B示意的代码显示方式。代码文件1的第一编辑区和第二编辑区并排显示,第一代码块包括第一编辑区中第r1行到第r2行的文本代码;第二编辑区中以第r1行为起始位置,显示第一代码块的多个备选代码块。其中一个备选代码块的文本代码完整的显示于第二编辑区中,如占用第二编辑区中第r1行到第r3行,r1、r2、r3均为正整数, r2与r3可以相同或者不同。将文本代码完整显示的一个备选代码块记作第二代码块,第二代码块所在的位置上设置有第二下拉选项框;除第二代码块之外剩余的备选代码块以标识信息显示于该第二下拉选项框中,而不显示完整的文本代码。其中,一个备选代码块的标识信息可以是该备选代码块的编号,名称或者其他能够唯一指示该备选代码块的信息,本申请实施例对此不予限制。通过这样的设计使得第二编辑区中显示的第二代码块与第一编辑区中显示的第一代码块的起始行相同,用户可以基于第一代码块的位置,快速确定第一代码块的备选代码块。可选的,第二下拉选项框中可以包括第一代码块的全部备选代码块的标识信息,支持用户自行在该第二下拉选项框中选择一个备选代码块作为第二代码块,完整的显示在第二编辑区中。这样的设计能够增加与用户的交互,提升用户体验感。作为示例,图3B示意出第二下拉选项框中包括第一代码块的全部备选代码块的编号,如记作备选1、备选2、备选3;其中,备选1所指示的备选代码块以完整的文本代码显示在第二编辑区。
此外,第二代码块上可以设置有一个可选框,当用户勾选该可选框时,相当于输入了第一操作指令,则编辑系统可以接收用户输入的第一操作指令。用户勾选该可选框,表明用户期望将第一编码区中的第一代码块替换为第二代码块,因此第一操作指令可指示将第一编码区中的第一代码块替换为第二代码块。可选的,S201也可以替换描述为:响应于用户的操作,确定该用户的第一操作指令。
在另一种可选的实施方式中,一个代码文件对应一个编辑区,例如称为第一编辑区。其中,第一编辑区显示当前生效的一套文本代码,或者也可以替换描述为第一编辑区显示待运行的一套文本代码,第一编辑区显示的一套文本代码可包含多个代码块。在S201中,第一编辑区中的多个代码块包括第一代码块,编辑系统中存储第一代码块的备选代码块,第一代码块的备选代码块的数量可以是1个或多个。该第一代码块所在的位置上设置有第一下拉选项框,该第一下拉选项框中可以包括第一代码块的全部备选代码块的标识,一个备选代码块的标识例如为该备选代码块的编号、名称或者其他能够用于指示该备选代码块的信息,本申请实施例对此不予限制。可以理解,在S201中,显示在第一编辑区中的第一代码块为生效的可运行的代码块,第一代码块的备选代码块未显示,也不生效或不运行。可参见图3C,第一下拉选项框中包括第一代码块的全部备选代码块的编号,如分别为备选1、备选2、备选3。当用户在第一下拉选项框中勾选其中一个备选代码块时,相当于输入了第一操作指令,则编辑系统可以接收用户输入的第一操作指令。例如,将用户勾选的备选代码块记作第二代码块(例如用户勾选的是“备选1”),用户勾选该第二代码块,表明用户期望将第一编码区中的第一代码块替换为第二代码块,因此第一操作指令可指示将第一编码区中的第一代码块替换为第二代码块。可选的,S201也可以替换描述为:响应于用户的操作,确定该用户的第一操作指令。
可选的,该S201由编辑系统中的用户交互单元执行,用户交互单元接收用户的第一操作指令。如用户交互单元为用户提供文本代码编辑器,用户在文本代码编辑器中触发将第一编辑区中的第一代码块替换为第二代码块的编辑操作时,用户交互单元接收用户的第一操作指令。
S202,编辑系统根据第一操作指令,更新第一编辑区对应的第一文本数据结构。
例如,编辑系统的存储单元可以预先存储第一编辑区对应的第一文本数据结构,第一文本数据结构包括的节点之间的连接关系可以反映第一编辑区中所显示的完整的文本代码的执行逻辑或执行顺序。可以理解的,对应第一编辑区显示的文本代码中的多个代码块,第一文本数据结构可以包含用于指示该多个代码块中任一代码块的子文本数据结构。类似地,编辑系统的存储单元还可以预先存储第二文本数据结构。第二文本数据结构用于指示在第一编辑区显示的文本代码中的部分或全部代码块的备选代码块。其中,第二文本数据结构可包括各个备选代码块对应的子文本数据结构,不同的备选代码块对应的子文本数据结构之间不存在连接关系,可以理解为,第二文本数据结构包括多个独立的子文本数据结构。其中,一个备选代码块对应的子文本数据结构可以反映该备选代码块中的文本代码的执行逻辑或执行顺序。以在第一编辑区中显示完整文本代码的第一代码块、第一代码块的备选代码块包括第二代码块和第三代码块为例,第二文本数据结构可包括用于指示第二代码块的第二子文本数据结构,第二文本数据结构包括用于指示第三代码块的第三子文本数据结构。第二子文本数据结构与第三子文本数据结构相互独立,不存在连接关系。
针对第一编辑区中的任一个有备选代码块的代码块而言,该代码块对应的子文本数据结构与该代码块的每个备选代码块对应的子文本数据结构之间具有映射关系,以第一代码块的备选代码块包括第二代码块和第三代码块为例,第一代码块对应的第一子文本数据结构与第二代码块对应的第二子文本数据结构具有映射关系。第一代码块对应的第一子文本数据结构与第三代码块对应的第三子文本数据 结构具有映射关系。
在S201中介绍了,第一操作指令指示将第一编辑区中的第一代码块替换为第二代码块。编辑系统接收第一操作指令后,可以确定第一代码块对应的第一子文本数据结构以及第二代码块对应的第二子文本数据结构;进而,编辑系统可以基于第一子文本数据结构和第二子文本数据结构之间的映射关系,将第一编辑区中的第一文本数据结构中的第一子文本数据结构替换为第二子文本数据结构。例如,第一子文本数据结构中根节点的位置和第二子文本数据结构中根节点的位置之间具有映射关系,编辑系统基于该映射关系可以确定将第二子文本结构插入第一文本数据结构中的哪个位置。在执行S202之前,第一子文本数据结构中根节点位于第一文本数据结构中的位置1。那么编辑系统执行S202时,可以将第二子文本数据结构中的根节点插入到第一文本数据结构中的位置1。这样的设计能够减少对文本代码的执行逻辑的干扰,确保第一编辑区中文本代码的正常运行。
例如,对应于图3A示意的第一代码块显示在第一编辑区,第二代码块显示在第二编辑区的情况,可参见图4A,在执行S202之前,第一文本数据结构中包含用于指示第一代码块的第一子文本数据结构,第二文本数据结构中包含用于指示第二代码块的第二子文本数据结构。可再参考图4B,在执行S202之后,更新后的第一文本数据结构中不包含第一子文本数据结构,但包含第二子文本数据结构;相应地,在S202中,编辑系统还可以根据第一操作指令更新第二文本数据结构,因此图4B中,更新后的第二文本数据结构中包含第一子文本数据结构,但不包含第二子文本数据结构。
又例如,对应于图3B示意第一代码块显示在第一编辑区,第二代码块显示在第二编辑区的情况,第二代码块上的下拉选项框中包括第一代码块的多个备选代码块的标识信息。以该多个备选代码块包括第二代码块和第三代码块为例,可参见图5A,在执行S202之前,第一文本数据结构中包含用于指示第一代码块的第一子文本数据结构,第二文本数据结构中包含用于指示第二代码块的第二子文本数据结构、以及用于指示第三代码块的第三子文本数据结构。其中,第二子文本数据结构与第三子文本数据结构之间不存在连接关系。可再参考图5B,在执行S202之后,更新后的第一文本数据结构中不包含第一子文本数据结构,但包含第二子文本数据结构;相应地,在S202中,编辑系统还可以根据第一操作指令更新第二文本数据结构,因此图5B中,更新后的第二文本数据结构中包含第一子文本数据结构以及第三子文本数据结构,但不包含第二子文本数据结构。
再例如,对应图3C示意第一代码块显示在第一编辑区,第一下拉选项框中包括第一代码块的全部备选代码块的编号的情况。以该第一代码块的备选代码块包括第二代码块和第三代码块为例,可参见图5A,在执行S202之前,第一文本数据结构中包含用于指示第一代码块的第一子文本数据结构,第二文本数据结构中包含用于指示第二代码块的第二子文本数据结构、以及用于指示第三代码块的第三子文本数据结构。其中,第二子文本数据结构与第三子文本数据结构之间不存在连接关系。可再参考图5B,在执行S202之后,更新后的第一文本数据结构中不包含第一子文本数据结构,但包含第二子文本数据结构;相应地,在S202中,编辑系统还可以根据第一操作指令更新第二文本数据结构,因此图5B中,更新后的第二文本数据结构中包含第一子文本数据结构以及第三子文本数据结构,但不包含第二子文本数据结构。
可选的,该步骤S202中的方案可以由编辑系统中的处理单元执行,即处理单元可以根据第一操作指令,更新第一编辑区对应的第一文本数据结构。处理单元更新第一文本数据结构的方式可参照前述内容理解,本申请实施例对此不进行赘述。
S203,编辑系统根据更新后的第一文本数据结构,在第一编辑区中显示第二代码块。
S203可以理解为编辑系统对用户操作的处理反馈。可选的,该步骤S203中可以由编辑系统中的处理单元执行,即处理单元可以根据更新后的第一文本数据结构,在第一编辑区中显示第二代码块。
在经过S201~S203之后,第一编辑区中原本显示第一代码块的位置会改为显示第二代码块。可以理解的是,经过S201~S203,第一编辑区的文本代码发生了变化,例如将S201之前第一编辑区的文本代码记作第一套文本代码,将在执行S201~S203之后第一编辑区的文本代码记作第二套文本代码。其中,第一套文本代码和第二套文本代码的区别在于:第一套文本代码中包括第一代码块,但不包括第二代码块;第二套文本代码中包括第二代码块,但不包括第一代码块。
示例性的,在图3A的基础上,通过执行S202和S203,可得到图6A示意的结果。即,响应于图3A示意的用户勾选了第二代码块的可选框的操作,通过执行S202和S203,得到了图6A中示意的处理结果,该处理结果为,将第二代码块显示到了第一编辑区中原来第一代码块所在的位置,相应地, 第二编辑区中第二代码块原来所在的位置上显示了第一代码块。可理解为,互换了第一代码块和第二代码块的位置。
示例性的,在图3B的基础上,通过执行S202和S203,可得到图6B示意的结果。即,响应于图3A示意的用户勾选了第二代码块的可选框的操作,通过执行S202和S203,得到了图6B中示意的处理结果,该处理结果为,将第二代码块显示到第一编辑区中原来第一代码块所在的位置,相应地,第二编辑区中第二代码块原来所在的位置上显示了第一代码块。可理解为,互换了第一代码块和第二代码块的位置。执行S202和S203之后,图6B中第二下拉选项框位于第二编辑区中第二代码块原来所在的位置上;或者也可以替换描述为:执行S202和S203之后,图6B中第二下拉选项框位于第二编辑区中第一代码块所在的位置。
示例性的,在图3C的基础上,通过执行S202和S203,可得到图6C示意的结果。即,响应于图3C示意的用户勾选第一下拉选项框中备选1的操作,即将备选1指示的备选代码块看作第二代码块。通过执行S202和S203,得到了图6C中示意的处理结果,该处理结果为,在第一编辑区中原来第一代码块所在的位置显示第二代码块,而第一下拉选项框中包括第一代码块的编号(例如备选4),不包括第二代码块的编号(如备选1),也即可以理解的是经过S202和S203后,第一代码块可以看作第二代码块的备选代码块,可以将第一代码块以编号(例如备选4)记录于第一下拉选项框中。
本申请实施例中,针对一套可运行的文本代码,编辑系统可以存储以及显示该套文本代码中的部分或全部代码块的备选代码块,并可以基于文本数据结构建立代码块和相应的备选代码块之间的映射关系,通过设置备选代码块,相当于提供了多套文本代码。例如,如果用户(例如软件开发人员)需要更换或优化软件功能,则可利用备选代码块替换原有代码块,相当于用一套文本代码替换了另一套文本代码,从而可以实现软件功能的优化、修改或升级等,能够有效提升编辑效率。
此外,基于代码文件中的代码块的划分,编辑系统还可以支持用户在第一编辑区中对代码块进行除切换备选代码块之外的其他编辑操作,例如增加、删除、复制、粘贴、移动等编辑操作,能够提升对第一编辑区中文本代码的编辑效率。可参见图7,介绍一种编辑方法,该方法可用于对代码块进行编辑。
S701,编辑系统接收用户的第二操作指令。
其中,所述第二操作指令用于指示如下中的一项或多项:删除所述第一编辑区中的指定代码块,对所述第一编辑区中的指定代码块进行复制,将复制的代码块粘贴到所述第一编辑区中的指定位置,将所述第一编辑区中的指定代码块移动到第一编辑区中指定位置,或,在所述第一编辑区中添加代码块。
可以理解的是,前述指定代码块可以包括用户通过第二操作指令指示的所述第一编辑区中的一个或多个代码块。指定位置可以是用户通过第二操作指令指示的第一编辑区中的位置。用户在第一编辑区中编辑新增的代码块的文本代码时,编辑系统可以接收到用于指示在第一编辑区中添加代码块的第二操作指令,第二操作指令中携带新增的代码块,该新增的代码块包括一行或多行文本代码。
以用户第二操作指令用于指示将所述第一编辑区中的指定代码块移动到第一编辑区中指定位置为例。可参见图8,指定代码块指的是第一编辑区中的第四代码块,该第四代码块包括第一编辑区中第r4行到第r5行的文本代码。当用户将第一编辑区中的第四代码块移动到以第r6行为起始行的位置时,相当于输入了第二操作指令,则编辑系统可以接收用户输入的第二操作指令,即第二操作指令用于指示将所述第四代码块移动到第一编辑区中的指定位置,该指定位置包括以第r6行为起始行,第r7行为终止行的多行。其中,r7与r6之间的差值等于r5与r4之间的差值。划分代码块的方式可以实现将代码文件中的文本代码分组,一个代码块作为一个整体,在这样的设计中,用户可以直接对代码块整体进行一次编辑操作,无需先选中需要移动的文本代码,再进行移动,能够提升编辑效率以及用户体验。
可选的,该步骤S701可以由编辑系统中的用户交互单元执行,用户交互单元接收用户的第二操作指令。如用户交互单元为用户提供文本代码编辑器,用户在文本代码编辑器中触发指定代码块的编辑操作时,用户交互单元接收用户的第二操作指令。
S702,编辑系统根据第二操作指令,更新第一编辑区对应的第一文本数据结构。
其中,有关第一文本数据结构的定义可参照S202中的描述理解,本申请实施例对此不进行赘述。
编辑系统根据第二操作指令,可以确定用户对于第一编辑区中代码块的编辑需求,进而按照用户 的编辑需求对第一编辑区对应的第一文本数据结构中的子文本数据结构进行修改。
例如,第二操作指令指示删除所述第一编辑区中的指定代码块,那么编辑系统可以确定用户期望从第一编辑中删除该指定代码块;进而,编辑系统可以在第一文本数据结构中删除与该指定代码块对应的子文本数据结构。
例如,第二操作指令指示复制所述第一编辑区中的指定代码块,以及将复制的代码块粘贴到第一编辑区中指定位置。那么编辑系统可以确定用户期望对第一编辑区中的指定代码块进行复制粘贴,且指示了粘贴的指定位置。以用户期望将第一编辑区中第四代码块复制并粘贴到第一编辑区中第五代码块之后的位置为例,编辑系统可以在第一文本数据结构中确定第四代码块对应的第四子文本数据结构以及第五代码块对应的第五子文本数据结构;进而按照特定的代码执行逻辑,如先执行完第五代码块再执行复制粘贴的第四代码块,编辑系统可以保留第一文本数据结构中原有的第四子文本数据结构基础上,在第五子文本数据结构的叶子节点后再插入第四子文本数据结构。
例如,第二操作指令指示将所述第一编辑区中的指定代码块移动到第一编辑区中的指定位置,那么编辑系统可以确定用户期望在第一编辑区中移动指定代码块,且指示了移动的指定位置(或称,目标位置);进而,编辑系统可以在第一文本数据结构中删除与该指定代码块对应的子文本数据结构。以用户期望将第一编辑区中第四代码块移动到第一编辑区中第五代码块之后的位置为例,编辑系统可以在第一文本数据结构中确定第四代码块对应的第四子文本数据结构以及第五代码块对应的第五子文本数据结构;进而按照特定的代码执行逻辑,如先执行完第五代码块再执行复制粘贴的第四代码块,编辑系统可以将第一文本数据结构中原有的第四子文本数据结构,移动插入到在第五子文本数据结构的叶子节点的后面。
又如,第二操作指令指示在所述第一编辑区中添加代码块,用户在第一编辑区中输入新代码块的文本代码,那么编辑系统可以通过用户第一编辑区获取用户输入的新代码块的文本代码以及输入位置,进而编辑系统可以按照特定的代码执行逻辑,在第一文本数据结构中添加新代码块对应的节点。
可选的,该步骤S702中的方案可以由编辑系统中的处理单元执行,即处理单元可以根据第二操作指令,更新第一编辑区对应的第一文本数据结构。处理单元更新第一文本数据结构的方式可参照前述内容理解,本申请实施例对此不进行赘述。
S703,编辑系统根据更新后的第一文本数据结构,在第一编辑区中显示更新后的第一文本数据结构对应的代码块。
S703可以理解为编辑系统对用户操作的处理反馈。可选的,该步骤S703中可以由编辑系统中的处理单元执行,即处理单元可以根据更新后的第一文本数据结构,在第一编辑区中显示更新后的第一文本数据结构对应的代码块。
例如,在图8的基础上,通过执行S702~S703,可得到图9示意的结果。即,响应于图8示意用户对第四代码块的移动操作,通过执行S702和S703,得到了图9中示意的处理结果,该处理结果为将第四代码块显示到了第一编辑区中第r6行到第r7行的位置。
可选的,图7所示的实施例与上述图2所示的实施例可以结合应用,例如用户可以基于图7所示的实施例提供的方式,对图2所示的实施例介绍的第一编辑区中的部分代码块或全部代码块进行编辑操作;或者,图7所示的实施例与图2所示的实施例也可以不结合,而是分别单独应用,本申请实施例对此不予限制,且不限制图2和图7这两个实施例的执行顺序。
基于上述实施例,本申请实施例还提供了一种计算设备1000。如图10所示,计算设备1000包括:总线102、处理器104、存储器106和通信接口108。处理器104、存储器106和通信接口108之间通过总线102通信。计算设备1000可以是笔记本电脑、台式电脑、服务器或终端设备。应理解,本申请不限定计算设备1000的处理器、存储器的个数。
总线102可以是外设部件互连标准(peripheral component interconnect,PCI)总线或扩展工业标准结构(extended industry standard architecture,EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,图10中仅用一条线表示,但并不表示仅有一根总线或一种类型的总线。总线104可包括在计算设备1000各个部件(例如,存储器106、处理器104、通信接口108)之间传送信息的通路。
处理器104可以包括中央处理器(central processing unit,CPU)、图形处理器(graphics processing unit,GPU)、微处理器(micro processor,MP)或者数字信号处理器(digital signal processor,
DSP)等处理器中的任意一种或多种。
存储器106可以包括易失性存储器(volatile memory),如内存,例如随机存取存储器(random access memory,RAM)。存储器106还可以包括非易失性存储器(non-volatile memory),例如只读存储器(read-only memory,ROM),快闪存储器,机械硬盘(hard disk drive,HDD)或固态硬盘(solid state drive,SSD。存储器是能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其他介质,但不限于此。本申请实施例中的存储器还可以是电路或者其它任意能够实现存储功能的装置,用于存储程序指令和/或数据。
例如,存储器106中存储有可执行的程序代码,处理器104执行该可执行的程序代码以分别实现前述用户交互单元、处理单元的功能,从而实现文本代码的编辑方法。也即,存储器106上存有文本代码的编辑系统用于执行文本代码的编辑方法的指令。存储器106中还存储有代码文件,以及代码文件对应的文本数据结构。
通信接口108使用例如但不限于网络接口卡、收发器一类的收发模块,来实现计算设备1000与其他设备或通信网络之间的通信。当该计算设备1000为芯片类的装置或者电路时,该计算设备1000中的通信接口108也可以是输入输出电路,可以输入信息(或称,接收信息)和输出信息(或称,发送信息),处理器为集成的处理器或者微处理器或者集成电路或则逻辑电路,处理器可以根据输入信息确定输出信息。
本申请实施例中的耦合是装置、单元或模块之间的间接耦合或通信连接,可以是电性,机械或其它的形式,用于装置、单元或模块之间的信息交互。处理器104可能和存储器106、通信接口108协同操作。本申请实施例中不限定上述处理器104、存储器106以及通信接口108之间的具体连接介质。
本申请实施例还提供了一种包含指令的计算机程序产品。所述计算机程序产品可以是包含指令的,能够运行在计算设备上或被储存在任何可用介质中的软件或程序产品。当所述计算机程序产品在计算设备集群上运行时,使得计算设备集群执行上述应用于文本代码的编辑系统用于执行文本代码的编辑方法,或使得计算设备集群执行上述应用于文本代码的编辑系统用于执行文本代码的编辑方法。
本申请实施例还提供了一种计算机可读存储介质。所述计算机可读存储介质可以是计算设备能够存储的任何可用介质或者是包含一个或多个可用介质的数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘)等。该计算机可读存储介质包括指令,所述指令指示计算设备集群执行上述应用于文本代码的编辑系统用于执行文本代码的编辑方法,或指示计算设备集群执行上述应用于文本代码的编辑系统用于执行文本代码的编辑方法。
在本申请实施例中,在无逻辑矛盾的前提下,各示例之间可以相互引用,例如方法实施例之间的方法和/或术语可以相互引用,例如系统实施例之间的功能和/或术语可以相互引用,例如系统示例和方法示例之间的功能和/或术语可以相互引用。
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的保护范围。

Claims (15)

  1. 一种文本代码的编辑方法,其特征在于,包括:
    接收用户的第一操作指令,所述第一操作指令用于指示将所述第一编辑区中的第一代码块替换为第二代码块,所述第二代码块为用于替换所述第一代码块的备选代码块中的一个;
    根据所述第一操作指令,更新所述第一编辑区对应的第一文本数据结构;其中,更新后的所述第一文本数据结构中不包含用于指示所述第一代码块的第一子文本数据结构,且更新后的所述第一文本数据结构中包含用于指示所述第二代码块的第二子文本数据结构;
    根据更新后的所述第一文本数据结构,在所述第一编辑区中显示所述第二代码块。
  2. 如权利要求1所述的方法,其特征在于,在获取用户的第一操作指令之前,所述第二代码块显示在第二编辑区中;所述方法还包括:
    根据更新后的所述第一文本数据结构,在所述第二编辑区中显示所述第一代码块。
  3. 如权利要求2所述的方法,其特征在于,
    在更新所述第一编辑区对应的第一文本数据结构之前,所述第二编辑区对应的第二文本数据结构包含所述第二子文本数据结构,且不包含所述第一子文本数据结构;
    在更新所述第一编辑区对应的第一文本数据结构之后,所述第二编辑区对应的所述第二文本数据结构包含所述第一子文本数据结构,且不包含所述第二子文本数据结构。
  4. 如权利要求1-3任一项所述的方法,其特征在于,所述第一子文本数据结构与用于指示所述第一代码块的备选代码块的文本数据结构之间存在映射关系;所述根据所述第一操作指令,更新所述第一编辑区对应的第一文本数据结构,包括:
    根据所述第一操作指令,确定所述第一子文本数据结构和所述第二子文本数据结构;
    根据所述第一子文本数据结构与所述第二子文本数据结构之间的映射关系,将所述第一文本数据结构中的所述第一子文本数据结构替换为所述第二子文本数据结构。
  5. 如权利要求1-4任一项所述的方法,其特征在于,还包括:
    接收所述用户的第二操作指令,所述第二操作指令用于指示如下中的一项或多项:删除所述第一编辑区中的指定代码块,对所述第一编辑区中的指定代码块进行复制,将复制的代码块粘贴到所述第一编辑区中的指定位置,将所述第一编辑区中的指定代码块移动到第一编辑区中指定位置,或,在所述第一编辑区中添加代码块;
    根据所述第二操作指令,更新所述第一文本数据结构;
    根据所述第一文本数据结构,在所述第一编辑区中显示更新后的所述第一文本数据结构对应的代码块。
  6. 如权利要求1-5任一项所述的方法,其特征在于,在获取用户的第一操作指令之前,还包括:
    根据所述第一编辑区的第一文本数据结构确定所述第一编辑区中的代码块。
  7. 一种文本代码的编辑系统,其特征在于,包括:
    用户交互单元,用于接收用户的第一操作指令,所述第一操作指令用于指示将所述第一编辑区中的第一代码块替换为第二代码块,所述第二代码块为用于替换所述第一代码块的备选代码块中的一个;
    处理单元,用于根据所述第一操作指令,更新所述第一编辑区对应的第一文本数据结构;其中,更新后的所述第一文本数据结构中不包含用于指示所述第一代码块的第一子文本数据结构,且更新后的所述第一文本数据结构中包含用于指示所述第二代码块的第二子文本数据结构;
    所述处理单元,还用于根据更新后的所述第一文本数据结构,在所述第一编辑区中显示所述第二代码块。
  8. 如权利要求7所述的系统,其特征在于,在所述用户交互单元接收用户的第一操作指令之前,所述第二代码块显示在第二编辑区中;所述处理单元,还用于根据更新后的所述第一文本数据结构,在所述第二编辑区中显示所述第一代码块。
  9. 如权利要求8所述的系统,其特征在于,在所述处理单元更新所述第一编辑区对应的第一文本数据结构之前,所述第二编辑区对应的第二文本数据结构包含所述第二子文本数据结构,且不包含所述第一子文本数据结构;在所述处理单元更新所述第一编辑区对应的第一文本数据结构之后,所述第二编辑区对应的第二文本数据结构包含所述第一子文本数据结构,且不包含所述第二子文本数据结构。
  10. 如权利要求8-9任一项所述的系统,其特征在于,所述第一子文本数据结构和用于指示所述第一代码块的备选代码块的文本数据结构之间存在映射关系;所述处理单元,具体用于:
    根据所述第一操作指令,确定所述第一子文本数据结构和所述第二子文本数据结构;
    根据所述第一子文本数据结构与所述第二子文本数据结构之间的映射关系,将所述第一文本数据结构中的所述第一子文本数据结构替换为所述第二子文本数据结构。
  11. 如权利要求8-10任一项所述的系统,其特征在于,
    所述用户交互单元,还用于接收所述用户的第二操作指令,所述第二操作指令用于指示如下中的一项或多项:删除所述第一编辑区中的指定代码块,对所述第一编辑区中的指定代码块进行复制,将复制的代码块粘贴到所述第一编辑区中的指定位置,将所述第一编辑区中的指定代码块移动到第一编辑区中指定位置,或,在所述第一编辑区中添加代码块;
    所述处理单元,还用于根据所述第二操作指令,更新所述第一文本数据结构;
    所述处理单元,还用于在所述第一编辑区中显示更新后的所述第一文本数据结构对应的代码块。
  12. 如权利要求8-11任一项所述的系统,其特征在于,在所述用户交互单元接收用户的第一操作指令之前,所述处理单元,还用于根据所述第一编辑区的第一文本数据结构确定所述第一编辑区中的代码块。
  13. 一种计算设备,其特征在于,所述计算设备包括处理器和存储器;
    所述存储器用于存储计算机执行指令;
    所述处理器用于执行所述存储器所存储的计算机执行指令,以使所述计算设备执行如权利要求1-6任一项所述的方法。
  14. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括计算机程序指令,当所述计算机程序指令被计算机设备运行时,使得所述计算机设备执行如权利要求1-6中任一项所述的方法。
  15. 一种计算机程序产品,其特征在于,所述计算机程序产品包含指令,当所述指令被计算机设备运行时,使得所述计算机设备执行如权利要求的1-6中任一项所述的方法。
PCT/CN2023/117325 2022-09-29 2023-09-06 一种文本代码的编辑方法及系统 WO2024066995A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211204858.0 2022-09-29
CN202211204858.0A CN115688698A (zh) 2022-09-29 2022-09-29 一种文本代码的编辑方法及系统

Publications (1)

Publication Number Publication Date
WO2024066995A1 true WO2024066995A1 (zh) 2024-04-04

Family

ID=85064686

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/117325 WO2024066995A1 (zh) 2022-09-29 2023-09-06 一种文本代码的编辑方法及系统

Country Status (2)

Country Link
CN (1) CN115688698A (zh)
WO (1) WO2024066995A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115688698A (zh) * 2022-09-29 2023-02-03 华为技术有限公司 一种文本代码的编辑方法及系统

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8677332B1 (en) * 2012-06-26 2014-03-18 Google Inc. Executing multiple child code blocks via a single compiled parent code block
CN112307723A (zh) * 2020-08-31 2021-02-02 北京字节跳动网络技术有限公司 生成代码文档的方法、装置和电子设备
CN113609823A (zh) * 2021-07-14 2021-11-05 Oppo广东移动通信有限公司 问卷逻辑的编辑方法、装置、终端设备及存储介质
CN115016778A (zh) * 2022-03-02 2022-09-06 山东浪潮工业互联网产业股份有限公司 一种基于WebIDE的应用开发方法、设备及介质
WO2022184077A1 (zh) * 2021-03-02 2022-09-09 北京字跳网络技术有限公司 文档编辑的方法、装置、终端及非暂时性存储介质
CN115688698A (zh) * 2022-09-29 2023-02-03 华为技术有限公司 一种文本代码的编辑方法及系统

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8677332B1 (en) * 2012-06-26 2014-03-18 Google Inc. Executing multiple child code blocks via a single compiled parent code block
CN112307723A (zh) * 2020-08-31 2021-02-02 北京字节跳动网络技术有限公司 生成代码文档的方法、装置和电子设备
WO2022184077A1 (zh) * 2021-03-02 2022-09-09 北京字跳网络技术有限公司 文档编辑的方法、装置、终端及非暂时性存储介质
CN113609823A (zh) * 2021-07-14 2021-11-05 Oppo广东移动通信有限公司 问卷逻辑的编辑方法、装置、终端设备及存储介质
CN115016778A (zh) * 2022-03-02 2022-09-06 山东浪潮工业互联网产业股份有限公司 一种基于WebIDE的应用开发方法、设备及介质
CN115688698A (zh) * 2022-09-29 2023-02-03 华为技术有限公司 一种文本代码的编辑方法及系统

Also Published As

Publication number Publication date
CN115688698A (zh) 2023-02-03

Similar Documents

Publication Publication Date Title
US7096420B1 (en) Method and system for automatically documenting system command file tags and generating skeleton documentation content therefrom
CN108388622B (zh) Api接口动态生成方法、装置、计算机设备及存储介质
US20050251738A1 (en) Document revision support program and computer readable medium on which the support program is recorded and document revision support device
WO2021037050A1 (zh) 一种代码变更方法及装置
WO2024066995A1 (zh) 一种文本代码的编辑方法及系统
JP2006107466A (ja) 電子文書で使用するために複数のデータソースのデータをマージする方法、システム、およびコンピュータ読み取り可能媒体
CN111984300B (zh) 代码复制方法及装置、电子设备和计算机可读存储介质
US20120185516A1 (en) Computer data file merging based on file metadata
CN110688145A (zh) Android MVP代码自动生成方法、装置、介质、电子设备
CN113656005A (zh) 应用组件库构建方法、应用组件配置方法及相关装置
JP2023553220A (ja) マルチインスタンスプロセスのためのプロセスマイニング
CN107526838B (zh) 数据库集群扩容的方法和装置
US11573772B2 (en) Mechanism for information propagation and resolution in graph-based programming languages
JP2516703B2 (ja) 論理自動生成方法および論理自動生成システム
US20210311756A1 (en) Generating and preserving default configurations of a system
US20080077849A1 (en) Mechanism for associating annotations with model items
US7716653B2 (en) Configurable importers and resource writers for converting data into another format
US11977559B2 (en) Providing instant and distributed access to a source blob via copy-on-read blobs and link blobs
EP4363992A1 (en) Method and apparatus for implementing changes to a file system that is emulated with an object storage system
CN109032616A (zh) 一种字库烧写方法、电子设备和存储介质
WO2021093442A1 (zh) 一种边缘辅助部署第三方应用到微控制器方法及系统
CN113901025A (zh) 数据库管理方法、装置、设备和存储介质
US8868578B2 (en) Building information technology services from a library of elements
US20230319137A1 (en) Domain specific provider contracts for core data services
US9824170B1 (en) Message filtering for electronic design automation systems

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23870234

Country of ref document: EP

Kind code of ref document: A1