diff options
Diffstat (limited to 'search.lua')
-rw-r--r-- | search.lua | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/search.lua b/search.lua index eca7cd7..5d794f2 100644 --- a/search.lua +++ b/search.lua @@ -1,7 +1,7 @@ -- helpers for the search bar (C-f) function Text.draw_search_bar() - local h = Line_height+2 + local h = Editor_state.line_height+2 local y = App.screen.height-h love.graphics.setColor(0.9,0.9,0.9) love.graphics.rectangle('fill', 0, y-10, App.screen.width-1, h+8) @@ -12,92 +12,92 @@ function Text.draw_search_bar() love.graphics.setColor(0.6,0.6,0.6) love.graphics.rectangle('line', 20, y-6, App.screen.width-40, h+2, 2,2) App.color(Text_color) - App.screen.print(Search_term, 25,y-5) + App.screen.print(Editor_state.search_term, 25,y-5) App.color(Cursor_color) - if Search_text == nil then - Search_text = App.newText(love.graphics.getFont(), Search_term) + if Editor_state.search_text == nil then + Editor_state.search_text = App.newText(love.graphics.getFont(), Editor_state.search_term) end - love.graphics.circle('fill', 25+App.width(Search_text),y-5+h, 2) + love.graphics.circle('fill', 25+App.width(Editor_state.search_text),y-5+h, 2) App.color(Text_color) end function Text.search_next() -- search current line - local pos = Lines[Cursor1.line].data:find(Search_term, Cursor1.pos) + local pos = Editor_state.lines[Editor_state.cursor1.line].data:find(Editor_state.search_term, Editor_state.cursor1.pos) if pos then - Cursor1.pos = pos + Editor_state.cursor1.pos = pos end if pos == nil then - for i=Cursor1.line+1,#Lines do - pos = Lines[i].data:find(Search_term) + for i=Editor_state.cursor1.line+1,#Editor_state.lines do + pos = Editor_state.lines[i].data:find(Editor_state.search_term) if pos then - Cursor1.line = i - Cursor1.pos = pos + Editor_state.cursor1.line = i + Editor_state.cursor1.pos = pos break end end end if pos == nil then -- wrap around - for i=1,Cursor1.line-1 do - pos = Lines[i].data:find(Search_term) + for i=1,Editor_state.cursor1.line-1 do + pos = Editor_state.lines[i].data:find(Editor_state.search_term) if pos then - Cursor1.line = i - Cursor1.pos = pos + Editor_state.cursor1.line = i + Editor_state.cursor1.pos = pos break end end end if pos == nil then - Cursor1.line = Search_backup.cursor.line - Cursor1.pos = Search_backup.cursor.pos - Screen_top1.line = Search_backup.screen_top.line - Screen_top1.pos = Search_backup.screen_top.pos + Editor_state.cursor1.line = Editor_state.search_backup.cursor.line + Editor_state.cursor1.pos = Editor_state.search_backup.cursor.pos + Editor_state.screen_top1.line = Editor_state.search_backup.screen_top.line + Editor_state.screen_top1.pos = Editor_state.search_backup.screen_top.pos end - if Text.lt1(Cursor1, Screen_top1) or Text.lt1(Screen_bottom1, Cursor1) then - Screen_top1.line = Cursor1.line - local _, pos = Text.pos_at_start_of_cursor_screen_line(Margin_left, App.screen.width-Margin_right) - Screen_top1.pos = pos + if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) or Text.lt1(Editor_state.screen_bottom1, Editor_state.cursor1) then + Editor_state.screen_top1.line = Editor_state.cursor1.line + local _, pos = Text.pos_at_start_of_cursor_screen_line(Editor_state.margin_left, App.screen.width-Editor_state.margin_right) + Editor_state.screen_top1.pos = pos end end function Text.search_previous() -- search current line - local pos = rfind(Lines[Cursor1.line].data, Search_term, Cursor1.pos) + local pos = rfind(Editor_state.lines[Editor_state.cursor1.line].data, Editor_state.search_term, Editor_state.cursor1.pos) if pos then - Cursor1.pos = pos + Editor_state.cursor1.pos = pos end if pos == nil then - for i=Cursor1.line-1,1,-1 do - pos = rfind(Lines[i].data, Search_term) + for i=Editor_state.cursor1.line-1,1,-1 do + pos = rfind(Editor_state.lines[i].data, Editor_state.search_term) if pos then - Cursor1.line = i - Cursor1.pos = pos + Editor_state.cursor1.line = i + Editor_state.cursor1.pos = pos break end end end if pos == nil then -- wrap around - for i=#Lines,Cursor1.line+1,-1 do - pos = rfind(Lines[i].data, Search_term) + for i=#Editor_state.lines,Editor_state.cursor1.line+1,-1 do + pos = rfind(Editor_state.lines[i].data, Editor_state.search_term) if pos then - Cursor1.line = i - Cursor1.pos = pos + Editor_state.cursor1.line = i + Editor_state.cursor1.pos = pos break end end end if pos == nil then - Cursor1.line = Search_backup.cursor.line - Cursor1.pos = Search_backup.cursor.pos - Screen_top1.line = Search_backup.screen_top.line - Screen_top1.pos = Search_backup.screen_top.pos + Editor_state.cursor1.line = Editor_state.search_backup.cursor.line + Editor_state.cursor1.pos = Editor_state.search_backup.cursor.pos + Editor_state.screen_top1.line = Editor_state.search_backup.screen_top.line + Editor_state.screen_top1.pos = Editor_state.search_backup.screen_top.pos end - if Text.lt1(Cursor1, Screen_top1) or Text.lt1(Screen_bottom1, Cursor1) then - Screen_top1.line = Cursor1.line - local _, pos = Text.pos_at_start_of_cursor_screen_line(Margin_left, App.screen.width-Margin_right) - Screen_top1.pos = pos + if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) or Text.lt1(Editor_state.screen_bottom1, Editor_state.cursor1) then + Editor_state.screen_top1.line = Editor_state.cursor1.line + local _, pos = Text.pos_at_start_of_cursor_screen_line(Editor_state.margin_left, App.screen.width-Editor_state.margin_right) + Editor_state.screen_top1.pos = pos end end |