Program preview method and device
By generating an editing operation sequence, and based on the differences between the original code and the update code, incremental update program preview is achieved, which solves the cumbersome and time-consuming problem of program preview in the existing technology, real-time preview and efficient development of code editing are realized.
Patent Information
- Application Number
- CN202510291090.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-12
- Publication Date
- 2025-08-01
AI Technical Summary
In the prior art, the program preview process is cumbersome and time-consuming. After adding or modifying components on a low-code platform, developers must regenerate and compile code packages to preview on the mobile side, resulting in inefficient development.
By generating an editing operation sequence, the application page is previewed based on the differences between the original code and the update code, and the application page is initially updated to avoid reloading the entire code file.
Realize the real-time preview function of code editing, improve development efficiency and user experience, and reduce the amount of data transmission and the update time of preview pages.
Smart Images

Figure CN120407344A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a program preview method and device. Background Art
[0002] Program preview allows developers to instantly view and test how their code will run in a specific environment (such as a mobile device) during the software development process. Program preview is crucial for ensuring that an app's user interface (UI), interaction logic, and functionality meet expectations. It allows developers to identify and fix issues during the coding process, thereby improving development efficiency and software quality.
[0003] Current technical solutions allow developers to quickly build application interfaces and logic using a drag-and-drop approach through low-code platforms, generating runnable source code. However, every time a developer adds or modifies a component on the platform, the source code must be regenerated and recompiled into a runnable code package before it can be previewed on a mobile device by scanning a QR code. This process is cumbersome and time-consuming, significantly reducing development efficiency. Summary of the Invention
[0004] The present invention provides a program preview method and device to solve the defects in the prior art.
[0005] The present invention provides a program preview method, comprising the following steps: Identify the original and updated code of the program; generating an editing operation sequence based on the difference between each character in the original code and the character at the same position in the updated code, wherein the editing operation sequence refers to the editing operations performed at the same position during the process of converting the original code to the updated code; The editing operation sequence is sent to the terminal, so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
[0006] According to a program preview method provided by the present invention, generating an editing operation sequence based on the difference between each character in the original code and the characters at the same position in the updated code includes: determining, based on differences between each character in the original code and the character at the same position in the updated code, editing parameters for each position in the process of converting the original code into the updated code; Taking the end position as the backtracking starting point, based on the editing parameters of each position, backtrack to the starting position to determine the editing operation information of each position; The editing operation sequence is generated based on the editing operation information of each position.
[0007] A program preview method provided by the present invention, which takes the end position as the backtracking starting point, and based on the editing parameters of each position, backtracks to the starting position to determine the editing operation information of each position, including: Based on the editing parameters of each position, construct an editing operation matrix, where the lower right corner position of the editing operation matrix is the end position, and the upper left corner position is the starting position; Taking the end position as the backtracking starting point, based on the editing parameters of each position, backtrack to the starting position to determine the editing operation information of each position.
[0008] A program preview method provided by the present invention, where the constructing an editing operation matrix based on the editing parameters of each position includes: Based on the character length of the original code and the character length of the updated code, construct an initialization matrix; Fill the editing parameters of each position into the initialization matrix to obtain a filled matrix; When the character at the current position in the original code is the same as the character at the corresponding current position in the updated code, use the element value at the upper left corner position of the current position in the filled matrix as the element value of the current position; When the character at the current position in the original code is different from the character at the corresponding current position in the updated code, determine the element value of the current position based on the element value at the upper left corner position, the element value at the left position, and the element value at the upper position in the filled matrix; After traversing the characters at each position, use the filled matrix as the editing operation matrix.
[0009] A program preview method provided by the present invention, where the editing parameters include at least one of an edit distance, an edit direction, and an edit type.
[0010] A program preview method provided by the present invention, where the sending the editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page and displays the updated preview application page includes: Convert the editing operation sequence into a standard format, and send the converted editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page and displays the updated preview application page.
[0011] The present invention also provides a program preview device, including the following units: A determination unit for determining the original code and the updated code of the program; A generating unit, configured to generate an editing operation sequence based on the differences between the characters in the original code and the characters at the same positions in the updated code, where the editing operation sequence refers to the editing operations performed at the same positions during the process of converting the original code into the updated code; A sending unit, configured to send the editing operation sequence to a terminal, so that the terminal incrementally updates a program preview application page based on the editing operation sequence and displays the updated preview application page.
[0012] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the program preview method described in any of the above is implemented.
[0013] The present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the program preview method described in any of the above is implemented.
[0014] The present invention also provides a computer program product, including a computer program. When the computer program is executed by a processor, the program preview method described in any of the above is implemented.
[0015] For the program preview method and apparatus provided by the present invention, since the editing operation sequence contains all the editing operation information during the process of converting the original code into the updated code, the terminal can perform incremental updates based on the editing operation information instead of reloading the entire code file. This incremental update method greatly reduces the data transmission volume and enables the preview application page to quickly reflect the latest state of the code, thereby realizing the real-time preview function of code editing. Description of the Drawings
[0016] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0017] Figure 1 It is a flowchart of the program preview method provided by the present invention.
[0018] Figure 2 It is a flowchart of the editing operation sequence generation method provided by the present invention.
[0019] Figure 3 It is a structural diagram of the program preview apparatus provided by the present invention.
[0020] Figure 4It is a schematic structural diagram of the electronic device provided by the present invention. Specific Embodiments
[0021] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions in the present invention will be clearly and completely described below with reference to the accompanying drawings in the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present invention without making creative efforts shall fall within the protection scope of the present invention.
[0022] Currently, developers can quickly build application interfaces and logic frameworks through drag-and-drop operations with the help of a low-code platform, and then automatically generate executable source code. However, this solution has significant deficiencies in the mobile preview phase. Specifically, developers initialize a low-code project in a low-code integrated development environment (IDE), use the functions of dragging and dropping interface elements and configuring data sources to design and produce the source code of a mobile application. Subsequently, the low-code IDE is responsible for compiling the generated source code into a mobile-executable format and uploading the compiled code package to the server of the mini-program platform. The server receives and processes the code package to generate an accessible link address. The development tool then uses the link address returned by the server to dynamically generate a QR code. After scanning this QR code by mobile users, they can access the link, download, and load the code package for preview.
[0023] However, the problem with this solution is that whenever developers add or adjust components on the platform, they must regenerate the code and compile it again into a runnable code package in order to preview the change effect on the mobile device by scanning the code. This series of steps is both cumbersome and time-consuming, seriously restricting the development efficiency, because developers cannot immediately preview the changes they make on the mobile device and must go through the complete processes of code generation, compilation, and deployment.
[0024] To solve the above problems, the present invention provides a program preview method. Figure 1 It is a schematic flowchart of the program preview method provided by the present invention. As Figure 1 shown, the method includes step 110, step 120, and step 130.
[0025] Step 110: Determine the original code and updated code of the program.
[0026] Here, the original code refers to the code state before editing, that is, the code version before the user starts editing or the last time the code was saved. The updated code refers to the code state after editing, that is, the code version after the user makes changes to the original code in the current editing session.
[0027] Exemplarily, when a developer opens a file or starts a new project, the editor loads the current content of the file as the original code. The editor listens for the user's keyboard input, mouse clicks, and other possible editing operations (such as copy, paste, undo, etc.), and these inputs are captured in real time and applied to the code being edited currently, thereby generating updated code.
[0028] Step 120: Generate an editing operation sequence based on the differences between the characters in the original code and the characters at the same positions in the updated code. The editing operation sequence refers to the editing operations performed at the same position during the process of converting the original code into the updated code.
[0029] Step 130: Send the editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
[0030] Specifically, the differences between the characters in the original code and the characters at the same positions in the updated code can be understood as the character difference situations at the same positions when comparing the original code and the updated code. For example, if the character at a certain position in the original code is replaced by another character at the corresponding position in the updated code, or the character at that position is deleted or a new character is added in the updated code, then it is considered that there is a difference between the characters at these two positions.
[0031] The editing operation sequence is used to record the character change situations at each position during the process of converting the original code into the updated code, including but not limited to character insertion, deletion, replacement, etc. Since the editing operation sequence contains all the necessary modification information, the terminal can update only based on these changes instead of reloading the entire code file. This incremental update method greatly reduces the data transfer volume and enables the preview application page to quickly reflect the latest state of the code, thus realizing the real-time preview function of code editing. That is to say, after sending the editing operation sequence to the terminal, the terminal can incrementally update the program preview application page based on the editing operation sequence without the terminal loading the entire updated code file to update the program preview application page, realizing the real-time preview update of code editing and improving the development efficiency.
[0032] Compared with the traditional solution where developers have to regenerate the code and recompile it into a runnable code package every time they add or adjust components on the platform and then can preview the change effect on the mobile side by scanning the code, the embodiment of the present invention realizes incremental update by generating and sending the editing operation sequence to the terminal. This update method can observe the effect of code changes in real time without waiting for the entire page or application to be reloaded, which not only improves the development efficiency but also improves the user experience.
[0033] Exemplarily, character-level comparison can be performed on the original code and the updated code to determine whether the characters at the same position are the same, and to identify the positions of character differences. For each identified difference, a corresponding edit operation (such as operation type, position, content, etc.) is recorded. All the identified and recorded edit operations are combined into an edit operation sequence in the order in which they appear in the code. This sequence is an ordered set of instructions that, when executed in order, can convert the original code into the updated code.
[0034] For example, assume the original code is "hello world" and the updated code is "hello universe". Through character-level comparison, the following differences in characters at each position can be identified: The characters from the 6th to the 10th, "world", are deleted; at the 6th to the 13th positions, "universe" is inserted.
[0035] Based on these differences, an edit operation sequence can be generated, such as: Delete operation: positions 6 to 10, content "world". Insert operation: position 6, content "universe".
[0036] The program preview method provided by the embodiments of the present invention, since the edit operation sequence contains all the edit operation information during the process of converting the original code into the updated code, the terminal can perform incremental updates based on the edit operation information, rather than reloading the entire code file. This incremental update method greatly reduces the data transmission volume and enables the preview application page to quickly reflect the latest state of the code, thus realizing the real-time preview function of code editing.
[0037] Based on the above embodiments, based on the differences between the characters at each position in the original code and the characters at the same position in the updated code, an edit operation sequence is generated, including: Based on the differences between the characters at each position in the original code and the characters at the same position in the updated code, determine the edit parameters at each position during the process of converting the original code into the updated code; Taking the end position as the backtracking starting point, based on the edit parameters at each position, backtrack to the starting point position to determine the edit operation information at each position; Based on the edit operation information at each position, generate an edit operation sequence.
[0038] Specifically, the edit parameters at each position are used to describe the specific information on how to convert the characters at each position in the original code into the corresponding characters in the updated code. The edit parameters can include the operation type (insertion, deletion, replacement, etc.), the operation position, and the character corresponding to the operation type (for the replacement operation, the corresponding character is the replaced character; for the insertion operation, the corresponding character is the inserted character).
[0039] Considering that in some cases, there may be dependencies between editing operations. For example, an insertion operation may affect the positions of subsequent characters, thereby affecting the positions of other insertion, deletion, or replacement operations. In addition, if the editing operation sequence is directly determined based on the differences between the original code and the updated code, it may lead to a chaotic order of editing operations, and this chaotic order may make it difficult to accurately reproduce the user's editing process in subsequent processing (such as the undo / redo function).
[0040] Based on this, the embodiments of the present invention start from the end position and use the previously determined editing parameters to gradually trace back to the start position. During the backtracking process, according to the editing parameters of each position, the editing operation information of that position is determined, which can not only avoid the problem that the generated editing operation sequence cannot be correctly executed due to the dependency between editing operations, but also ensure that the generated editing operation sequence is arranged in the order from back to front, so as to accurately reproduce the user's editing process in some application scenarios (such as the undo / redo function) and process the editing operations more efficiently.
[0041] After determining the editing operation information of all positions, arrange the editing operation information of all positions in the order determined during the backtracking process to form an editing operation sequence. The editing operation sequence can be sent to the terminal for incrementally updating the program preview application page.
[0042] The embodiments of the present invention compare the differences between the original code and the updated code character by character, and use the backtracking method to determine the editing operation information from the end position to the start position, and finally generate an ordered editing operation sequence, which not only improves the generation efficiency of the editing operation sequence, but also ensures the accuracy and orderliness of the sequence.
[0043] Based on any of the above embodiments, taking the end position as the backtracking starting point, based on the editing parameters of each position, trace back to the start position to determine the editing operation information of each position, including: Based on the editing parameters of each position, construct an editing operation matrix, where the lower right position of the editing operation matrix is the end position and the upper left position is the start position; Taking the end position as the backtracking starting point, based on the editing parameters of each position, trace back to the start position to determine the editing operation information of each position.
[0044] Specifically, the editing operation matrix can be regarded as a two-dimensional data structure for recording and representing all possible editing operations and their state transitions from the start position to the end position. Each element in the matrix corresponds to a specific editing operation or state, and these operations or states are arranged in the matrix according to specific orders and rules.
[0045] In a matrix, the lower right corner is usually regarded as the end or target position, which represents the final state of the editing operation or the code state that the user expects to reach. The upper left corner in the matrix is usually regarded as the start or initial position, which represents the starting state of the editing operation or the code state before the user starts editing. Placing the starting position in the upper left corner of the matrix and forming a diagonal layout with the lower right corner helps to clearly display the editing path from the start to the end.
[0046] In addition, considering that placing the starting position and the end point in other positions (such as the edge of the matrix) may cause some areas to be not effectively utilized. For example, if the starting position is in the upper left corner but the end point is in the upper right corner, the lower left corner area of the matrix may remain blank because it has nothing to do with the editing path. Thus, it can be seen that in the embodiments of the present invention, placing the starting position and the end position at the diagonal positions of the matrix respectively can make full use of the space of the matrix and avoid leaving blank or redundant areas at the edge positions.
[0047] Since the end position represents the final state of the editing operation or the code state that the user expects to reach, that is, the state represented by the end position is a known state. Taking the end position as the starting point for backtracking, based on the editing parameters of each position, backtracking towards the starting position, and gradually reverse-deriving the editing operation information of each position until reaching the starting position.
[0048] Based on any of the above embodiments, an editing operation matrix is constructed based on the editing parameters of each position, including: An initialization matrix is constructed based on the character length of the original code and the character length of the updated code; The editing parameters of each position are filled into the initialization matrix to obtain a filled matrix; When the character at the current position in the original code is the same as the character at the corresponding current position in the updated code, the element value at the upper left corner position of the current position in the filled matrix is used as the element value of the current position; When the character at the current position in the original code is different from the character at the corresponding current position in the updated code, based on the element value at the upper left corner position, the element value at the left position, and the element value at the upper position of the current position in the filled matrix, the element value of the current position is determined; After traversing the characters of each position, the filled matrix is used as the editing operation matrix.
[0049] Specifically, the initialization matrix is used to represent the initial state, that is, the state where there is no editing operation. Here, all elements of the initialization matrix can be 0 or a certain reference value, and the embodiments of the present invention do not make specific limitations on this.
[0050] According to the character lengths of the original code and the updated code, a two-dimensional initialization matrix large enough can be constructed. Considering the editing cases from an empty string to a non-empty string or from a non-empty string to an empty string, the number of rows and columns of this initialization matrix can be respectively equal to the character lengths of the original code and the updated code plus one. Traverse each character position of the original code and the updated code. For each position, fill the matrix according to the editing parameters (such as the costs of insertion, deletion, and replacement).
[0051] If the character at the current position in the original code is the same as the character at the corresponding position in the updated code, it indicates that no editing operation is required. In this case, use the element value at the upper left corner position of the current position in the filled matrix (i.e., the previously accumulated editing cost) as the element value at the current position.
[0052] If the character at the current position in the original code is different from the character at the corresponding position in the updated code, it indicates that an editing operation (such as replacement) is to be performed. In this case, based on the element values at the upper left corner position (indicating not performing the current position editing but accumulating the previous costs), the left position (indicating inserting a character at the current position), and the upper position (indicating deleting a character from the current position) of the filled matrix, determine the element value at the current position. For example, in this case, the element value at the current position can be the minimum of the element values of these three positions plus the cost of the current editing operation (the cost of the current editing operation can be 1).
[0053] After traversing all character positions of the original code and the updated code, an editing operation matrix is obtained. The editing operation matrix contains the editing operations and their accumulated costs at each position from the original code to the updated code.
[0054] Based on any of the above embodiments, the editing parameters include at least one of the edit distance, edit direction, and edit type.
[0055] Specifically, the edit distance refers to the minimum number of editing operations required to convert one string to another. Editing operations usually include inserting a character, deleting a character, or replacing a character. Among them, the edit distance can be the Levenshtein distance. The main role of the edit distance in editing is to measure the similarity or difference degree between two strings. A smaller edit distance means that the two strings are more similar, while a larger edit distance indicates a greater difference between them.
[0056] The editing direction is used to describe the relative position or trend of operations during string editing. The editing type refers to the specific type of editing operation, such as insertion, deletion, replacement, etc. By determining the editing type, it is possible to accurately determine what operations need to be performed on the code to achieve the required transformation. The editing direction can indicate whether the editing operation is performed from left to right, from right to left, or in some other specific order.
[0057] For example, if the editing direction indicates "forward" and the current operation is increasing the length of the string, then possible editing types include insertion. If the editing direction is "backward" and the string length is decreasing, then the possible editing type is deletion.
[0058] Based on any of the above embodiments, send the editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page, including: Convert the editing operation sequence into a standard format and send the converted editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
[0059] Specifically, in order to enable seamless exchange and parsing of the editing operation sequence between different systems or components, the embodiments of the present invention convert the editing operation sequence into a standard format. Among them, the standard format can be the JSON format. After the editing operation sequence is converted into the JSON format, the converted editing operation sequence can be sent to the terminal through a network or other communication channels. Among them, the terminal can be any device or software that can receive and parse JSON format data, such as a web browser, a mobile application, or a desktop application.
[0060] After receiving the editing operation sequence, the terminal can gradually update the content of the program preview application page according to the editing operation sequence. Since incremental updates only update the changed content and do not change the unchanged content, it is more efficient than reloading the entire page, reducing the data transfer volume and rendering time. After incrementally updating the program preview application page, the terminal displays the updated program preview application page, so that users can see the effect of the editing operation in real time.
[0061] Based on any of the above embodiments, Figure 2 is a schematic flowchart of the method for generating an editing operation sequence provided by the present invention, as Figure 2 shown, the method includes: Determine the original code and the updated code of the program, and extract multiple strings from the original code that are different from the updated code. These strings can be regarded as pattern strings P. The strings corresponding to the pattern strings in the updated code are target strings T, that is, the target string T is the string obtained after updating the pattern string P. Among them, the corresponding pattern string P and target string T at the same place can be regarded as a difference segment, that is, there are N difference segments between the original code and the updated code.
[0062] Construct an initialization matrix D. The number of rows of this initialization matrix D is the character length of the pattern string P plus 1, and the number of columns is the length of the target string T plus 1. Initialize a variable x to represent the current matching position, with an initial value of 0.
[0063] At each position (i, j) of the initialization matrix D, fill the elements at the corresponding positions with the editing parameters at each position to obtain a filled matrix. In addition to recording the edit distance at each position, the elements in the filled matrix also record the edit direction at each position. This edit direction is used to represent from which direction the current position is reached, and different edit directions represent different edit types. For example, the following symbols can be used to represent each element: D[i][j]: Represents the edit distance at the current position.
[0064] INSERT: Represents reaching the current position from above, indicating an insertion operation.
[0065] DELETE: Represents reaching the current position from the left, indicating a deletion operation.
[0066] MATCH: Represents reaching the current position from the upper left, indicating a matching operation.
[0067] REPLACE: Represents reaching the current position from the upper right, indicating a replacement operation.
[0068] After obtaining the filled matrix, traverse the pattern strings P and target strings T in each difference segment. Taking difference segment 1 as an example, starting from the first character of the pattern string P corresponding to difference segment 1, traverse each character of the pattern string P. Correspondingly, also starting from the first character of the target string T corresponding to difference segment 1, traverse each character of the target string T.
[0069] Compare the target string character T[j] corresponding to difference segment 1 and the corresponding pattern string character P[i] according to the following method to calculate the value of D[i + 1][j + 1]: If T[j] is equal to P[i], then D[i + 1][j + 1] is equal to D[i][j].
[0070] Otherwise, D[i + 1][j + 1] is equal to the minimum of the following three values plus 1: D[i][j] (the value in the upper left corner of D[i + 1][j + 1]); D[i + 1][j] (the value to the left of D[i + 1][j + 1]); D[i][j + 1] (the value above D[i + 1][j + 1]).
[0071] Using the above method, continue to update the values of each element in the entire filled matrix until the element values at all positions in the difference segment 1 are calculated, obtaining the edit operation matrix 1 corresponding to this difference segment 1.
[0072] After that, perform the above steps for the difference segment 2, that is, fill to obtain the edit operation matrix 2 corresponding to the difference segment 2, until the comparison of all difference segments (for example, there are N difference segments) is completed, thereby obtaining the corresponding edit operation matrix N.
[0073] After obtaining all the edit operation matrices, backtracking can be used to obtain the edit operation sequence corresponding to each matrix, so as to obtain the corresponding N edit operation sequences for the N matrices. For example, the lower right corner position of the edit operation matrix can be used as the starting point, and backtrack to the upper left corner according to the edit direction in the edit parameters corresponding to the above positions. During the backtracking process, determine the edit operation according to the edit direction. By recording each edit operation according to the edit direction during the backtracking process, a complete edit operation sequence can be obtained, which includes insert, delete, match, and replace operations.
[0074] After obtaining the edit operation sequence, the N edit operation sequences can be converted into a JSON format protocol, and using the established websocket connection, send the converted JSON protocol edit operation sequence to the terminal, so that the terminal incrementally updates the program preview application page based on the edit operation sequence and displays the updated preview application page.
[0075] Among them, the websocket connection can be established based on the following steps: First, establish a WebSocket server and forward the JSON command protocol to the WebSocket server for the WebSocket server to use. Additionally, establish a WebSocket connection between the mobile device and the server through the WebSocket server to manage the WebSocket connections for the development tool and mobile device preview. Among them, WebSocket is an extension based on the HTTP protocol that provides a persistent, two-way communication channel, enabling the server to push data to the client in real time. The WebSocket handshake process generally includes: the client sending a WebSocket handshake request; the server responding to the handshake request; the client verifying the handshake response; and confirming the successful handshake and establishing a WebSocket connection.
[0076] After the program is first compiled in the development tool, inject a WebSocket client instance into the main process of the program's basic library, and establish a WebSocket connection between the development tool and the server through the WebSocket server for sending and receiving the JSON command protocol.
[0077] After the program that needs to be previewed on the mobile device is first compiled in the development tool, establish a WebSocket connection between the development tool and the server through the WebSocket server, so as to send the compiled JSON command protocol.
[0078] When updating the previewed program in the development tool, perform incremental compilation on the original code during program runtime to obtain the updated code. The development tool can determine the files with changes in the updated code and create a list of all files with changes to obtain a list of files with changes.
[0079] For each file in the file list, the Histogram algorithm can be used to quickly find the different segments at the same positions in the two versions of the code (original code and updated code) before and after the change during program runtime.
[0080] Next, the program preview device provided by the present invention will be described. The program preview device described below can be correspondingly referred to with the program preview method described above.
[0081] Based on any of the above embodiments, Figure 3 is a schematic structural diagram of the program preview device provided by the present invention, as Figure 3 shown. The device includes: A determination unit 310, configured to determine the original code and updated code of the program; A generating unit 320, configured to generate an editing operation sequence based on the differences between the characters in the original code and the characters at the same positions in the updated code, where the editing operation sequence refers to the editing operations performed at the same positions during the process of converting the original code into the updated code; A sending unit 330, configured to send the editing operation sequence to a terminal, so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
[0082] Based on any of the above embodiments, generating an editing operation sequence based on the differences between the characters in the original code and the characters at the same positions in the updated code includes: Determining the editing parameters at each position during the process of converting the original code into the updated code based on the differences between the characters in the original code and the characters at the same positions in the updated code; Taking the end position as the backtracking starting point, backtracking from the start position based on the editing parameters at each position to determine the editing operation information at each position; Generating an editing operation sequence based on the editing operation information at each position.
[0083] Based on any of the above embodiments, taking the end position as the backtracking starting point, backtracking from the start position based on the editing parameters at each position to determine the editing operation information at each position, including: Constructing an editing operation matrix based on the editing parameters at each position, where the lower right corner position of the editing operation matrix is the end position and the upper left corner position is the start position; Taking the end position as the backtracking starting point, backtracking from the start position based on the editing parameters at each position to determine the editing operation information at each position.
[0084] Based on any of the above embodiments, constructing an editing operation matrix based on the editing parameters at each position includes: Constructing an initialization matrix based on the character length of the original code and the character length of the updated code; Filling the editing parameters at each position into the initialization matrix to obtain a filled matrix; When the character at the current position in the original code is the same as the character at the corresponding current position in the updated code, taking the element value at the upper left corner position of the current position in the filled matrix as the element value at the current position; When the character at the current position in the original code is different from the character at the corresponding current position in the updated code, determining the element value at the current position based on the element value at the upper left corner position, the element value at the left position, and the element value at the upper position in the filled matrix; After traversing the characters at each position, taking the filled matrix as the editing operation matrix.
[0085] Based on any of the above embodiments, the editing parameter includes at least one of an edit distance, an edit direction, and an edit type.
[0086] Based on any of the above embodiments, sending the editing operation sequence to the terminal, so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page, includes: Converting the editing operation sequence into a standard format, and sending the converted editing operation sequence to the terminal, so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
[0087] Figure 4 is a schematic structural diagram of an electronic device provided by the present invention, as Figure 4 shown. The electronic device may include: a processor 410, a communications interface 420, a memory 430, and a communication bus 440. Among them, the processor 410, the communications interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logical instructions in the memory 430 to execute the program preview method, and the method includes: determining the original code and the updated code of the program; generating an editing operation sequence based on the differences between the characters at the same positions in the original code and the characters at the same positions in the updated code, where the editing operation sequence refers to the editing operations performed at the same positions during the process of converting the original code into the updated code; sending the editing operation sequence to the terminal, so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
[0088] In addition, when the logical instructions in the above-mentioned memory 430 can be implemented in the form of software function units and sold or used as an independent product, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that makes a contribution to the prior art, or a part of this technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc that can store program codes.
[0089] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the program preview method provided by each of the above methods. The method includes: determining the original code and the updated code of the program; generating an editing operation sequence based on the differences between the characters at the same positions in the original code and the updated code. The editing operation sequence refers to the editing operations performed at the same position during the process of converting the original code into the updated code; sending the editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
[0090] In another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is configured to execute the program preview method provided by each of the above methods. The method includes: determining the original code and the updated code of the program; generating an editing operation sequence based on the differences between the characters at the same positions in the original code and the updated code. The editing operation sequence refers to the editing operations performed at the same position during the process of converting the original code into the updated code; sending the editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
[0091] The device embodiments described above are merely illustrative. 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 to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative efforts.
[0092] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disc, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0093] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A program preview method, characterized in that, Including: Determine the original code and the updated code of the program; Generate an editing operation sequence based on the differences between the characters at the same positions in the original code and the updated code. The editing operation sequence refers to the editing operations performed at the same positions during the process of converting the original code into the updated code; Send the editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
2. The program preview method according to claim 1, characterized in that The generating an editing operation sequence based on the differences between the characters at the same positions in the original code and the updated code includes: Determine the editing parameters at each position during the process of converting the original code into the updated code based on the differences between the characters at the same positions in the original code and the updated code; Taking the end position as the backtracking starting point, backtrack from the starting point based on the editing parameters at each position to determine the editing operation information at each position; Generate the editing operation sequence based on the editing operation information at each position.
3. The program preview method according to claim 2, wherein The taking the end position as the backtracking starting point, backtracking from the starting point based on the editing parameters at each position to determine the editing operation information at each position includes: Construct an editing operation matrix based on the editing parameters at each position. The lower right corner position of the editing operation matrix is the end position, and the upper left corner position is the starting point; Taking the end position as the backtracking starting point, backtrack from the starting point based on the editing parameters at each position to determine the editing operation information at each position.
4. The program preview method according to claim 3, wherein The constructing an editing operation matrix based on the editing parameters at each position includes: Construct an initialization matrix based on the character length of the original code and the character length of the updated code; Fill the editing parameters at each position into the initialization matrix to obtain a filled matrix; When the character at the current position in the original code is the same as the character at the corresponding current position in the updated code, use the element value at the upper left corner position of the current position in the filled matrix as the element value of the current position; When the character at the current position in the original code is different from the character at the corresponding current position in the updated code, determine the element value of the current position based on the element value at the upper left corner position, the element value at the left position, and the element value at the upper position in the filled matrix; After traversing the characters at each position, use the filled matrix as the editing operation matrix.
5. The program preview method according to claim 2, wherein The editing parameters include at least one of an edit distance, an edit direction, and an edit type.
6. The program preview method according to any one of claims 1 to 5, characterized in that The sending the editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page includes: Convert the editing operation sequence into a standard format and send the converted editing operation sequence to the terminal so that the terminal incrementally updates the program preview application page based on the editing operation sequence and displays the updated preview application page.
7. A program preview device, characterized in that, Including: A determination unit for determining the original code and the updated code of the program; A generation unit, configured to generate an editing operation sequence based on the differences between the characters in the original code and the characters at the same positions in the updated code, where the editing operation sequence refers to the editing operations performed at the same positions during the process of converting the original code into the updated code; A sending unit, configured to send the editing operation sequence to a terminal, so that the terminal incrementally updates a program preview application page based on the editing operation sequence and displays the updated preview application page.
8. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the program preview method according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the program preview method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the program preview method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Page information updating method, apparatus, computer device, and storage medium
CN109471988A
Method and device for searching contract modification part, computer equipment and storage medium
CN109933754A
Text mining method and device, terminal and storage medium
CN110442876A
Front-end incremental updating method and device and application thereof
CN116909613A
Automatic identification method and system for intelligent equipment terminal of power distribution network
CN119011454A
Cited By
Multi-screen preview method for large model generation codes
CN120994156A
A method for generating a multi-screen preview of code by a large model
CN120994156B