diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-08-11 22:23:04 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-08-11 22:23:16 -0700 |
commit | f3df1cda0f05cc3294dd81e2089cbc673db4cdd6 (patch) | |
tree | b888c42a9a79e1e7839f246a658591eaf465f275 /search.lua | |
parent | 8b880f4fe8d0c631975063c20217dbf44de6bc1d (diff) | |
download | lines.love-f3df1cda0f05cc3294dd81e2089cbc673db4cdd6.tar.gz |
bugfix: check after cursor on same line when searching upwards
Diffstat (limited to 'search.lua')
-rw-r--r-- | search.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/search.lua b/search.lua index 4ebd8ab..1872b9e 100644 --- a/search.lua +++ b/search.lua @@ -68,12 +68,13 @@ function Text.search_next(State) end function Text.search_previous(State) - -- search current line + -- search current line before cursor local pos = rfind(State.lines[State.cursor1.line].data, State.search_term, State.cursor1.pos-1) if pos then State.cursor1.pos = pos end if pos == nil then + -- search lines above cursor for i=State.cursor1.line-1,1,-1 do pos = rfind(State.lines[i].data, State.search_term) if pos then @@ -95,6 +96,13 @@ function Text.search_previous(State) end end if pos == nil then + -- search current line after cursor + pos = rfind(State.lines[State.cursor1.line].data, State.search_term) + if pos and pos > State.cursor1.pos then + State.cursor1.pos = pos + end + end + if pos == nil then State.cursor1.line = State.search_backup.cursor.line State.cursor1.pos = State.search_backup.cursor.pos State.screen_top1.line = State.search_backup.screen_top.line |