From cff1e58cf62e048380e5fcec363d1ff36fc134db Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 8 Jul 2022 08:47:23 -0700 Subject: switch arg for a function --- main.lua | 2 +- text.lua | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/main.lua b/main.lua index 8226be8..051a01e 100644 --- a/main.lua +++ b/main.lua @@ -225,8 +225,8 @@ end function App.draw() Button_handlers = {} - love.graphics.setColor(0, 0, 0) + love.graphics.setColor(0, 0, 0) --? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos) assert(Text.le1(Screen_top1, Cursor1)) Cursor_y = -1 diff --git a/text.lua b/text.lua index d2c9466..26df8a4 100644 --- a/text.lua +++ b/text.lua @@ -22,7 +22,7 @@ function Text.draw(line, line_index) if line.fragments == nil then Text.compute_fragments(line) end - Text.populate_screen_line_starting_pos(line_index) + Text.populate_screen_line_starting_pos(line) --? print('--') for _, f in ipairs(line.fragments) do local frag, frag_text = f.data, f.text @@ -143,7 +143,7 @@ function Text.textinput(t) --? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) Text.insert_at_cursor(t) if Cursor_y >= App.screen.height - Line_height then - Text.populate_screen_line_starting_pos(Cursor1.line) + Text.populate_screen_line_starting_pos(Lines[Cursor1.line]) Text.snap_cursor_to_bottom_of_screen() --? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) end @@ -176,7 +176,7 @@ function Text.keychord_pressed(chord) --? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) Text.insert_at_cursor('\t') if Cursor_y >= App.screen.height - Line_height then - Text.populate_screen_line_starting_pos(Cursor1.line) + Text.populate_screen_line_starting_pos(Lines[Cursor1.line]) Text.snap_cursor_to_bottom_of_screen() --? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) end @@ -415,7 +415,7 @@ function Text.up() if Lines[new_cursor_line].mode == 'text' then --? print('found previous text line') Cursor1.line = new_cursor_line - Text.populate_screen_line_starting_pos(Cursor1.line) + Text.populate_screen_line_starting_pos(Lines[Cursor1.line]) -- previous text line found, pick its final screen line --? print('has multiple screen lines') local screen_line_starting_pos = Lines[Cursor1.line].screen_line_starting_pos @@ -588,7 +588,7 @@ function Text.right_without_scroll() end function Text.pos_at_start_of_cursor_screen_line() - Text.populate_screen_line_starting_pos(Cursor1.line) + Text.populate_screen_line_starting_pos(Lines[Cursor1.line]) for i=#Lines[Cursor1.line].screen_line_starting_pos,1,-1 do local spos = Lines[Cursor1.line].screen_line_starting_pos[i] if spos <= Cursor1.pos then @@ -599,7 +599,7 @@ function Text.pos_at_start_of_cursor_screen_line() end function Text.cursor_at_final_screen_line() - Text.populate_screen_line_starting_pos(Cursor1.line) + Text.populate_screen_line_starting_pos(Lines[Cursor1.line]) local screen_lines = Lines[Cursor1.line].screen_line_starting_pos --? print(screen_lines[#screen_lines], Cursor1.pos) return screen_lines[#screen_lines] <= Cursor1.pos @@ -667,7 +667,7 @@ function Text.in_line(line_index,line, x,y) if line.starty == nil then return false end -- outside current page if x < Margin_left then return false end if y < line.starty then return false end - Text.populate_screen_line_starting_pos(line_index) + Text.populate_screen_line_starting_pos(line) return y < line.starty + Line_height*(#line.screen_line_starting_pos - Text.screen_line_index(line, line.startpos) + 1) end @@ -822,7 +822,7 @@ function Text.to2(pos1) return {line=pos1.line, screen_line=1, screen_pos=1} end local result = {line=pos1.line, screen_line=1} - Text.populate_screen_line_starting_pos(pos1.line) + Text.populate_screen_line_starting_pos(Lines[pos1.line]) for i=#Lines[pos1.line].screen_line_starting_pos,1,-1 do local spos = Lines[pos1.line].screen_line_starting_pos[i] if spos <= pos1.pos then @@ -887,14 +887,12 @@ function Text.previous_screen_line(pos2) return {line=pos2.line-1, screen_line=1, screen_pos=1} else local l = Lines[pos2.line-1] - Text.populate_screen_line_starting_pos(pos2.line-1) + Text.populate_screen_line_starting_pos(Lines[pos2.line-1]) return {line=pos2.line-1, screen_line=#Lines[pos2.line-1].screen_line_starting_pos, screen_pos=1} end end -function Text.populate_screen_line_starting_pos(line_index) ---? print('Text.populate_screen_line_starting_pos', line_index) - local line = Lines[line_index] +function Text.populate_screen_line_starting_pos(line) if line.screen_line_starting_pos then return end @@ -909,11 +907,9 @@ function Text.populate_screen_line_starting_pos(line_index) local frag, frag_text = f.data, f.text -- render fragment local frag_width = App.width(frag_text) ---? print(x, pos, frag, frag_width) if x + frag_width > App.screen.width-Margin_right then x = Margin_left table.insert(line.screen_line_starting_pos, pos) ---? print('new screen line:', #line.screen_line_starting_pos, pos) end x = x + frag_width local frag_len = utf8.len(frag) @@ -924,8 +920,8 @@ end function Text.tweak_screen_top_and_cursor() --? print('a', Selection1.line) if Screen_top1.pos == 1 then return end - Text.populate_screen_line_starting_pos(Screen_top1.line) local line = Lines[Screen_top1.line] + Text.populate_screen_line_starting_pos(line) for i=2,#line.screen_line_starting_pos do local pos = line.screen_line_starting_pos[i] if pos == Screen_top1.pos then -- cgit 1.4.1-2-gfad0