diff options
| author | Francesco Abbate <francesco.bbt@gmail.com> | 2021-11-26 13:45:13 +0100 |
|---|---|---|
| committer | Francesco Abbate <francesco.bbt@gmail.com> | 2021-12-20 09:05:45 +0100 |
| commit | 405bd1c2bd5c18b32e7a81adf1857897cec42d27 (patch) | |
| tree | 59fa04496a93fbfd4ca45332071b1c1ab6abc754 | |
| parent | e512c576379fd806f83a89ef0a274f6ed95920d7 (diff) | |
| download | lite-xl-405bd1c2bd5c18b32e7a81adf1857897cec42d27.tar.gz lite-xl-405bd1c2bd5c18b32e7a81adf1857897cec42d27.zip | |
Fix logic in project's file insertion
The function "file_search" in core.init was sometimes giving a wrong index
value, off by one.
The problem happened for example when the entry to search was "less than"
the first entry, the function returned a value of two instead of one as
expected.
The bug was easily observed creating a new directory with a name that comes
as the first in alphabetical order within the project.
| -rw-r--r-- | data/core/init.lua | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/data/core/init.lua b/data/core/init.lua index 6f3754e4..f5d38ac0 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -191,7 +191,6 @@ end local function file_search(files, info) local filename, type = info.filename, info.type local inf, sup = 1, #files - if sup <= 0 then return 1, false end while sup - inf > 8 do local curr = math.floor((inf + sup) / 2) if system.path_compare(filename, type, files[curr].filename, files[curr].type) then @@ -200,12 +199,12 @@ local function file_search(files, info) inf = curr end end - repeat + while inf <= sup and not system.path_compare(filename, type, files[inf].filename, files[inf].type) do if files[inf].filename == filename then return inf, true end inf = inf + 1 - until inf > sup or system.path_compare(filename, type, files[inf].filename, files[inf].type) + end return inf, false end |
