File continuous viewable range determination method, electronic device, and medium
By using binary search and recursive functions to determine the continuous visible range within a file, the problem of discontinuous visible lines in a file is solved, thus improving operation speed and efficiency.
Patent Information
- Application Number
- CN202511309807.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-15
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2045-09-15
AI Technical Summary
In existing technologies, the visible lines within a file are not necessarily continuous, making it difficult to determine the continuous visible range in large-scale files, which affects the efficiency of operations such as lexical highlighting and debugging.
A binary search method combined with a recursive function is used to determine all folded lines within the visible range to be processed by obtaining the start visible line number, end visible line number, file line number, and identifier file line number, and then storing them in a continuous visible range set.
It enables accurate and rapid determination of continuous visible range from a large number of consecutive files, improving the speed and efficiency of visual line operations.
Smart Images

Figure CN120803597B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a file continuous visible range determination method, an electronic device and a medium. BACKGROUND
[0002] In the process of software development, the code written in a file is usually composed of code blocks with certain hierarchical structure, for example, a loop statement can be contained in a function, and a function can be contained in a larger module (such as a class or a file), and the above various statement blocks can also contain comment information, and single-line or continuous multi-line comment information can also be regarded as a statement block. In order to improve the reading convenience of users for the same code block, the existing editor usually provides folding and unfolding functions to display as much content as possible that users care about on a fixed-size display screen. The source code file line after folding will be invisible, which is usually referred to as invisible line, and vice versa, which is visible line.
[0003] In actual application scenarios, the number of visible lines on the display is relatively small and constant, but due to the existence of the folding function, these visible lines are not necessarily continuous, and there can be a large number of invisible lines interspersed. For example: in a design, when folding ten thousand lines or even millions of lines of code. At this time, the span of the file lines in the visible range will be greater than one million lines, and the actual visible line number can only be tens of lines. In actual business scenarios such as lexical highlighting, signal marking, debugging, etc., in order to consider performance, it is often necessary to highlight the code in the continuous visible range of the corresponding file first. Therefore, how to accurately and quickly determine the continuous visible range from the continuous file with high order of magnitude becomes a technical problem to be solved. SUMMARY
[0004] The present application aims to provide a file continuous visible range determination method, an electronic device and a medium, which can accurately and quickly determine the continuous visible range from the continuous file with high order of magnitude.
[0005] According to the first aspect of the present application, a file continuous visible range determination method is provided, comprising:
[0006] Step S1, initially setting the continuous visible range set as empty;
[0007] Step S2, obtaining the file start visible line number SV in the to-be-processed visible range and the file end visible line number EV in the to-be-processed visible range;
[0008] Step S3, obtaining the file line number SF corresponding to SV and the file line number EF corresponding to EV;
[0009] Step S4: Initially set the identifier file line number GF=SF, whereby the identifier file line number is used to identify the starting line of the current continuous visible range to be determined;
[0010] Step S5: If EF-SF=EV-SV, then proceed to step S6; otherwise, proceed to step S7.
[0011] Step S6: Determine {SF, EF} as a continuous visible range, store it in the continuous visible range set, and end the process;
[0012] Step S7: Based on the file start visible line number SV, end visible line number EV, file line number SF, file line number EF, and identifier file line number GF, use a binary search method to obtain all folded lines within the visible range to be processed, and store all continuous visible ranges in the set of continuous visible ranges.
[0013] According to a second aspect of the present invention, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in the first aspect of the present invention.
[0014] According to a third aspect of the present invention, a computer-readable storage medium is provided, storing computer-executable instructions for performing the method described in the first aspect of the present invention.
[0015] Compared with existing technologies, this invention has significant advantages and beneficial effects. Through the above technical solution, the document continuous visibility range determination method, electronic device, and medium provided by this invention achieve considerable technological advancement and practicality, and have broad industrial application value. It has at least the following beneficial effects:
[0016] This invention first obtains the start visible line number SV, end visible line number EV, file line number SF, file line number EF, and identifier file line number GF. Then, it uses a binary search method to obtain all folded lines within the visible range to be processed. All continuous visible ranges are stored in the set of continuous visible ranges, thereby achieving accurate and fast determination of continuous visible ranges from a large number of continuous files and improving the speed of operation on visible lines. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a schematic diagram of a method for determining the continuous visible range of a document provided in an embodiment of the present invention;
[0019] Figure 2 This is a schematic diagram of the line numbers of the visible range of the file to be processed, provided in an embodiment of the present invention. Detailed Implementation
[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] This invention provides a method for determining the continuous visible range of a file, such as... Figure 1 As shown, it includes:
[0022] Step S1: Initially set the continuous visible range set to empty.
[0023] The continuous visible range set is used to store the continuous visible ranges determined sequentially from top to bottom within the visible range to be processed. The file line number increases sequentially from top to bottom within the visible range, and the visible line number increases sequentially from top to bottom.
[0024] Step S2: Obtain the start visible line number SV and the end visible line number EV of the file within the visible range to be processed.
[0025] It should be noted that while the visible line numbers are consecutive, the actual line numbers may not be consecutive due to the presence of collapsed lines within the visible area.
[0026] Step S3: Obtain the file line number SF corresponding to SV and the file line number EF corresponding to EV.
[0027] like Figure 2 The visible range to be processed is shown. The file line number SF corresponding to the start visible line number SV within the visible range is 105, and the file line number EF corresponding to the end visible line number EV within the visible range is 200023. There are four folds within the visible range. The file line number corresponding to the first fold is 109, the second fold is 910, the third fold is 3405, and the fourth fold is 98009.
[0028] Step S4, initially setting an identification file line number GF = SF, the identification file line number being used to identify the starting file line of the current continuous viewable range to be determined.
[0029] It should be noted that, according to the embodiment of the present application, the continuous viewable ranges are sequentially divided from top to bottom in the viewable range to be processed, therefore, the identification file line number GF is dynamically changed, and initially, GF = SF. As shown in the example, after the first continuous viewable range {105, 109} is divided, GF is updated to 905. Figure 2
[0030] Step S5, if EF-SF = EV-SV, then step S6 is performed, otherwise step S7 is performed.
[0031] It should be noted that, if EF-SF = EV-SV, it means that there is no folding line in the viewable range to be processed, then step S6 is directly entered to determine {SF, EF} as the continuous viewable range. If there is a folding line, then step S7 is entered to determine the folding line one by one to determine all the continuous viewable ranges.
[0032] Step S6, {SF, EF} is determined as the continuous viewable range, and is stored in the continuous viewable range set, and the process is ended.
[0033] Step S7, all folding lines in the viewable range to be processed are obtained by using binary search method based on the file start viewable line number SV, the file end viewable line number EV, the file line number SF, the file line number EF, and the identification file line number GF, and all the continuous viewable ranges are stored in the continuous viewable range set.
[0034] It should be noted that, by using binary search combined with the dynamically changed GF, all the folding lines in the viewable range to be processed can be accurately and quickly determined, and the determination efficiency and accuracy of the continuous viewable range in the viewable range to be processed are improved.
[0035] As an embodiment, in step S3, the file line number SF corresponding to SV and the file line number EF corresponding to EV are obtained based on a preset file line number and viewable line number mapping table. The preset mapping relationship between the file line number and the viewable line number can be obtained in advance and stored in the file line number and viewable line number mapping table.
[0036] As an embodiment, step S7 includes:
[0037] Step S71, set the first input parameter A1=SV, the second input parameter A2=EV, the third input parameter A3=SF, the fourth input parameter A4=EF, call the preset folding line search function based on {A1, A2, A3, A4} to find all folding lines from top to bottom in the to-be-processed visual range, determine all continuous regions except the last continuous region, and after the preset folding line search function call is completely ended, GF has been updated to the starting file line of the last continuous visual range. The preset folding line search function is a recursive function generated based on the binary search method.
[0038] Wherein, A1, A2, A3, A4 are inputs of the preset folding line search function. It can be understood that the preset folding line search function is a recursive function generated based on the binary search method, so the preset folding line search function will continue to be called inside the preset folding line search function call.
[0039] Step S72, determine {GF, EF} as the last A3.
[0040] As an embodiment, the preset folding line search function includes:
[0041] Step S10, input {A1, A2, A3, A4} to the preset folding line search function, if A2-A1>1, execute step S20, otherwise, execute step S80.
[0042] Step S20, set the intermediate visual line number MV=(A1+A2+1) / 2.
[0043] It should be noted that setting MV=(A1+A2+1) / 2 can ensure that the intermediate visual line number MV always goes down each time, and further improve the efficiency of folding line search on the basis of ensuring correctness.
[0044] Step S30, get the file line number MF corresponding to MV.
[0045] Wherein, the file line number MF corresponding to MV is specifically obtained based on the preset file line number and visual line number mapping table. The preset mapping relationship between the file line number and the visual line number can be obtained in advance and stored in the file line number and visual line number mapping table.
[0046] Step S40, if MF-A3=MV-A1, execute step S60, otherwise, execute step S50.
[0047] Step S50, set A1=A1, A2=MV, A3=A3, A4=MF, call the preset folding line search function based on {A1, A2, A3, A4}, and after the function call is ended, execute step S60.
[0048] It should be noted that step S50 re-invokes the preset fold line search function based on the updated {A1, A2, A3, A4} inside the preset fold line search function.
[0049] Step S60, if A4-MF=A2-MV, end the function call, otherwise, execute step S70.
[0050] Step S70, set A1=MV, A2=A2, A3=MF, A4=A4, invoke the preset fold line search function based on {A1, A2, A3, A4}, and end the function call after processing.
[0051] It should be noted that step S70 re-invokes the preset fold line search function based on the updated {A1, A2, A3, A4} inside the preset fold line search function.
[0052] Step S80, determine the behavior fold line corresponding to A3, determine {GF, A3} as the continuous visible range, and store it in the continuous visible range set.
[0053] It should be noted that when A2-A1≤1, step S80 is entered, which means that the visible behavior lines corresponding to A2 and A1 are adjacent or the same line, and at this time, it can be determined that the file line number A3 corresponding to A1 is a fold line, and GF is the starting file line of the current continuous visible range to be determined, so {GF, A3} is determined as the continuous visible range. At present, A4 corresponding to A2 is the starting file line of the next continuous visible range to be determined, so GF=A4 is updated through step S90.
[0054] Step S90, update GF=A4, and end the function call.
[0055] It should be noted that the preset fold line search function implemented through steps S10-S80 is constructed based on the bisection method and the recursive function according to the embodiment of the application, and each fold line of the visible range to be processed is accurately and quickly determined from top to bottom by directly or directly or indirectly calling the preset fold line search function inside the function, so as to determine each continuous visible range in the visible range to be processed, which facilitates subsequent lexical highlighting, signal marking, debugging and other operations based on each continuous visible range.
[0056] In addition, in the above example, the steps S10-S80 are executed in series, i.e. the continuous visual ranges are sequentially divided from the visual range to be processed from top to bottom. However, it can be understood that, for each group {A1, A2, A3, A4}, the preset folding line searching function is called, which is equivalent to determining whether the code lines between the visual line A1 and the visual line A2 are continuous, whether they need to be further divided into two parts for further judgment, and if they need to be divided, the two parts after the division can be executed in parallel, but the process involving the execution of the step S80, the determination of the folding line corresponding to A3, the determination of {GF, A3} as the continuous visual range, and the storage in the continuous visual range set need to be strictly executed in series. The parallel and serial execution mode can further improve the determination efficiency of the continuous visual range while ensuring the accuracy of the determination of the continuous visual range of the file.
[0057] It should be noted that, in order to further ensure the accuracy of the determination of the continuous visual range of the file, in the step S30, the preset folding line searching function further includes a step S00 before the step S10, i.e. if A4-A3=A2-A1, the function call is ended, otherwise, the step S10 is executed. It should be noted that the calling condition of the preset folding line searching function has already filtered out the case of A4-A3=A2-A1, and the step S00 can further detect whether the case of A4-A3=A2-A1 misfires the preset folding line searching function, thereby further improving the accuracy of the determination of the continuous visual range of the file.
[0058] The embodiment of the present application first acquires the start visual line number SV, the end visual line number EV, the file line number SF, the file line number EF, and the identification file line number GF, and then acquires all the folding lines in the visual range to be processed based on the binary search method, and stores all the continuous visual ranges in the continuous visual range set, thereby realizing the accurate and rapid determination of the continuous visual range from the continuous file with a high number of orders, and improving the operation speed of the visual line.
[0059] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in the description herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0060] It is to be understood that some of the example embodiments are described in terms of a process or method depicted as a flowchart. Although each can generally be described as a process, method, or algorithm, many of the steps of any of the processes can be performed concurrently, in parallel, or simultaneously. In addition, the steps can be rearranged or reordered. The process can terminate when its operations are completed, but can also terminate in the middle of one or more steps. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0061] An electronic device is also provided, including: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores instructions executed by the at least one processor, the instructions are configured to perform the method described in the embodiments of the present application.
[0062] A computer readable storage medium is also provided, storing computer executable instructions, the computer instructions are used to perform the method described in the embodiments of the present application.
[0063] The above description is merely illustrative of the application, and is not intended to limit the application in any way. Although the application has been described in connection with specific preferred embodiments, it will be understood that the application is capable of further modifications. Any changes and modifications that come within the scope of the application are intended to be included in the application. The application is intended to cover any adaptations or variations of the preferred embodiments discussed above. Therefore, the above description, as such, is not intended to limit the scope of the application.
Claims
1. A method for determining the continuous visible range of a file, characterized in that, include: Step S1: Initially set the continuous visible range set to empty; Step S2: Obtain the start visible line number SV and the end visible line number EV of the file within the visible range to be processed; Step S3: Obtain the file line number SF corresponding to SV and the file line number EF corresponding to EV; Step S4: Initially set the identifier file line number GF=SF, whereby the identifier file line number is used to identify the starting line of the current continuous visible range to be determined; Step S5: If EF-SF=EV-SV, then proceed to step S6; otherwise, proceed to step S7. Step S6: Determine {SF, EF} as a continuous visible range, store it in the continuous visible range set, and end the process; Step S7: Based on the file start visible line number SV, end visible line number EV, file line number SF, file line number EF, and identifier file line number GF, use a binary search method to obtain all folded lines within the visible range to be processed, and store all continuous visible ranges in the set of continuous visible ranges. Step S7 includes: Step S71: Set the first input parameter A1=SV, the second input parameter A2=EV, the third input parameter A3=SF, and the fourth input parameter A4=EF. Based on {A1, A2, A3, A4}, call the preset folded line search function to perform a binary search from top to bottom within the visible range to be processed to find all folded lines and determine all continuous regions except the last continuous region. After the preset folded line search function call is completely finished, GF has been updated to the starting line of the last continuous visible range. The preset folded line search function is a recursive function generated based on the binary search method. Step S72: Determine {GF, EF} as the last A3.
2. The method according to claim 1, characterized in that, In step S3, the file line number SF corresponding to SV and the file line number EF corresponding to EV are obtained based on a preset file line number and visual line number mapping table.
3. The method according to claim 1, characterized in that, The preset folded row lookup function includes: Step S10: Input {A1, A2, A3, A4} into the preset folded row lookup function. If A2-A1>1, then execute step S20; otherwise, execute step S80. Step S20: Set the middle visible line number MV = (A1 + A2 + 1) / 2; Step S30: Obtain the file line number MF corresponding to MV; Step S40: If MF-A3 = MV-A1, then proceed to step S60; otherwise, proceed to step S50. Step S50: Set A1=A1, A2=MV, A3=A3, A4=MF, call the preset folded row lookup function based on {A1, A2, A3, A4}, and execute step S60 after the function call is completed. Step S60: If A4-MF=A2-MV, then end the function call; otherwise, proceed to step S70. Step S70: Set A1=MV, A2=A2, A3=MF, A4=A4. Based on {A1, A2, A3, A4}, call the preset folded row lookup function. After processing, end the function call. Step S80: Determine the folded row corresponding to A3, define {GF, A3} as a continuous visible range, and store it in the continuous visible range set; Step S90: Update GF=A4 and end the function call.
4. The method according to claim 3, characterized in that, In step S30, the file line number MF corresponding to MV is obtained based on a preset file line number and visual line number mapping table.
5. The method according to claim 3, characterized in that, The preset folded row lookup function also includes: If A4-A3=A2-A1, then the function call ends in step S00 before step S10; otherwise, step S10 is executed.
6. An electronic device, characterized in that, include: At least one processor; And, a memory communicatively connected to the at least one processor; The memory stores instructions that are executed by the at least one processor, the instructions being configured to perform the method of any one of claims 1-5.
7. A computer-readable storage medium, characterized in that, The device stores computer-executable instructions for performing the method of any one of claims 1-5.
Citation Information
Patent Citations
Multiple row header areas and / or multiple column header areas for display in summary table
CN102317931A
Method and device for processing session information
CN112684961A