diff --git a/edit.lua b/edit.lua index f36d6a2..39f7d0b 100644 --- a/edit.lua +++ b/edit.lua @@ -51,7 +51,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c -- when selecting text, avoid recomputing some state on every single frame recent_mouse = {}, - -- cursor coordinates in pixels + -- cursor coordinates in pixels (nil => no cursor drawn in viewport) cursor_x = 0, cursor_y = 0, @@ -79,8 +79,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c return result end -- App.initialize_state -function edit.draw(State) - App.color(Text_color) +function edit.draw(State, fg, hide_cursor) assert(#State.lines == #State.line_cache) if not Text.le1(State.screen_top1, State.cursor1) then print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos) @@ -100,13 +99,13 @@ function edit.draw(State) if line_index == State.screen_top1.line then startpos = State.screen_top1.pos end - y, State.screen_bottom1.pos = Text.draw(State, line_index, y, startpos) + y, State.screen_bottom1.pos = Text.draw(State, line_index, y, startpos, fg, hide_cursor) y = y + State.line_height --? print('=> y', y) end --? print('screen bottom: '..tostring(State.screen_bottom1.pos)..' in '..tostring(State.lines[State.screen_bottom1.line].data)) if State.search_term then - Text.draw_search_bar(State) + Text.draw_search_bar(State, hide_cursor) end end @@ -322,7 +321,7 @@ end function edit.update_font_settings(State, font_height) State.font_height = font_height - love.graphics.setFont(love.graphics.newFont(Editor_state.font_height)) + love.graphics.setFont(love.graphics.newFont(State.font_height)) State.line_height = math.floor(font_height*1.3) State.em = App.newText(love.graphics.getFont(), 'm') Text_cache = {} @@ -352,7 +351,7 @@ function edit.run_after_textinput(State, t) edit.textinput(State, t) edit.key_released(State, t) App.screen.contents = {} - edit.draw(State) + edit.draw(State, Text_color) end -- not all keys are textinput @@ -360,7 +359,7 @@ function edit.run_after_keychord(State, chord) edit.keychord_pressed(State, chord) edit.key_released(State, chord) App.screen.contents = {} - edit.draw(State) + edit.draw(State, Text_color) end function edit.run_after_mouse_click(State, x,y, mouse_button) @@ -369,19 +368,19 @@ function edit.run_after_mouse_click(State, x,y, mouse_button) App.fake_mouse_release(x,y, mouse_button) edit.mouse_released(State, x,y, mouse_button) App.screen.contents = {} - edit.draw(State) + edit.draw(State, Text_color) end function edit.run_after_mouse_press(State, x,y, mouse_button) App.fake_mouse_press(x,y, mouse_button) edit.mouse_pressed(State, x,y, mouse_button) App.screen.contents = {} - edit.draw(State) + edit.draw(State, Text_color) end function edit.run_after_mouse_release(State, x,y, mouse_button) App.fake_mouse_release(x,y, mouse_button) edit.mouse_released(State, x,y, mouse_button) App.screen.contents = {} - edit.draw(State) + edit.draw(State, Text_color) end diff --git a/search.lua b/search.lua index 37306f8..3bd61d3 100644 --- a/search.lua +++ b/search.lua @@ -16,7 +16,7 @@ function Text.draw_search_bar(State) if State.search_text == nil then State.search_text = App.newText(love.graphics.getFont(), State.search_term) end - Text.draw_cursor(State, 25+App.width(State.search_text),y-5) + Text.draw_cursor(State, 25+App.width(State.search_text),y-5, Cursor_color, Text_color) end function Text.search_next(State) diff --git a/text.lua b/text.lua index d6bdca7..bcf89aa 100644 --- a/text.lua +++ b/text.lua @@ -8,7 +8,7 @@ require 'text_tests' -- draw a line starting from startpos to screen at y between State.left and State.right -- return the final y, and position of start of final screen line drawn -function Text.draw(State, line_index, y, startpos) +function Text.draw(State, line_index, y, startpos, fg, hide_cursor) local line = State.lines[line_index] local line_cache = State.line_cache[line_index] line_cache.starty = y @@ -19,7 +19,7 @@ function Text.draw(State, line_index, y, startpos) local screen_line_starting_pos = startpos Text.compute_fragments(State, line_index) for _, f in ipairs(line_cache.fragments) do - App.color(Text_color) + App.color(fg) local frag, frag_text = f.data, f.text local frag_len = utf8.len(frag) --? print('text.draw:', frag, 'at', line_index,pos, 'after', x,y) @@ -49,11 +49,11 @@ function Text.draw(State, line_index, y, startpos) if State.search_term then if State.lines[State.cursor1.line].data:sub(State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)-1) == State.search_term then local lo_px = Text.draw_highlight(State, line, x,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term)) - App.color(Text_color) + App.color(fg) love.graphics.print(State.search_term, x+lo_px,y) end - else - Text.draw_cursor(State, x+Text.x(frag, State.cursor1.pos-pos+1), y) + elseif not hide_cursor then + Text.draw_cursor(State, x+Text.x(frag, State.cursor1.pos-pos+1), y, Cursor_color, fg) end end end @@ -61,20 +61,20 @@ function Text.draw(State, line_index, y, startpos) end pos = pos + frag_len end - if State.search_term == nil then + if not hide_cursor and State.search_term == nil then if line_index == State.cursor1.line and State.cursor1.pos == pos then - Text.draw_cursor(State, x, y) + Text.draw_cursor(State, x, y, Cursor_color, fg) end end return y, screen_line_starting_pos end -function Text.draw_cursor(State, x, y) +function Text.draw_cursor(State, x, y, cursor_color, reset_color) -- blink every 0.5s if math.floor(Cursor_time*2)%2 == 0 then - App.color(Cursor_color) + App.color(cursor_color) love.graphics.rectangle('fill', x,y, 3,State.line_height) - App.color(Text_color) + App.color(reset_color) end State.cursor_x = x State.cursor_y = y+State.line_height @@ -898,7 +898,7 @@ end -- slightly expensive since it redraws the screen function Text.cursor_out_of_screen(State) - App.draw() + edit.draw(State, --[[should be drawn over]] Cursor_color) return State.cursor_y == nil -- this approach is cheaper and almost works, except on the final screen -- where file ends above bottom of screen diff --git a/text_tests.lua b/text_tests.lua index 7f9b2e4..51d9314 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -6,7 +6,7 @@ function test_initial_state() Editor_state = edit.initialize_test_state() Editor_state.lines = load_array{} Text.redraw_all(Editor_state) - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) check_eq(#Editor_state.lines, 1, 'F - test_initial_state/#lines') check_eq(Editor_state.cursor1.line, 1, 'F - test_initial_state/cursor:line') check_eq(Editor_state.cursor1.pos, 1, 'F - test_initial_state/cursor:pos') @@ -36,7 +36,7 @@ function test_insert_first_character() Editor_state = edit.initialize_test_state() Editor_state.lines = load_array{} Text.redraw_all(Editor_state) - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_textinput(Editor_state, 'a') local y = Editor_state.top App.screen.check(y, 'a', 'F - test_insert_first_character/screen:1') @@ -62,7 +62,7 @@ function test_move_left() Editor_state.lines = load_array{'a'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=2} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'left') check_eq(Editor_state.cursor1.pos, 1, 'F - test_move_left') end @@ -74,7 +74,7 @@ function test_move_right() Editor_state.lines = load_array{'a'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=1} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'right') check_eq(Editor_state.cursor1.pos, 2, 'F - test_move_right') end @@ -86,7 +86,7 @@ function test_move_left_to_previous_line() Editor_state.lines = load_array{'abc', 'def'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=2, pos=1} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'left') check_eq(Editor_state.cursor1.line, 1, 'F - test_move_left_to_previous_line/line') check_eq(Editor_state.cursor1.pos, 4, 'F - test_move_left_to_previous_line/pos') -- past end of line @@ -99,7 +99,7 @@ function test_move_right_to_next_line() Editor_state.lines = load_array{'abc', 'def'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=4} -- past end of line - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'right') check_eq(Editor_state.cursor1.line, 2, 'F - test_move_right_to_next_line/line') check_eq(Editor_state.cursor1.pos, 1, 'F - test_move_right_to_next_line/pos') @@ -112,7 +112,7 @@ function test_move_to_start_of_word() Editor_state.lines = load_array{'abc'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=3} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-left') check_eq(Editor_state.cursor1.pos, 1, 'F - test_move_to_start_of_word') end @@ -124,7 +124,7 @@ function test_move_to_start_of_previous_word() Editor_state.lines = load_array{'abc def'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=4} -- at the space between words - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-left') check_eq(Editor_state.cursor1.pos, 1, 'F - test_move_to_start_of_previous_word') end @@ -136,7 +136,7 @@ function test_skip_to_previous_word() Editor_state.lines = load_array{'abc def'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=5} -- at the start of second word - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-left') check_eq(Editor_state.cursor1.pos, 1, 'F - test_skip_to_previous_word') end @@ -148,7 +148,7 @@ function test_skip_past_tab_to_previous_word() Editor_state.lines = load_array{'abc def\tghi'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=10} -- within third word - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-left') check_eq(Editor_state.cursor1.pos, 9, 'F - test_skip_past_tab_to_previous_word') end @@ -160,7 +160,7 @@ function test_skip_multiple_spaces_to_previous_word() Editor_state.lines = load_array{'abc def'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=6} -- at the start of second word - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-left') check_eq(Editor_state.cursor1.pos, 1, 'F - test_skip_multiple_spaces_to_previous_word') end @@ -172,7 +172,7 @@ function test_move_to_start_of_word_on_previous_line() Editor_state.lines = load_array{'abc def', 'ghi'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=2, pos=1} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-left') check_eq(Editor_state.cursor1.line, 1, 'F - test_move_to_start_of_word_on_previous_line/line') check_eq(Editor_state.cursor1.pos, 5, 'F - test_move_to_start_of_word_on_previous_line/pos') @@ -185,7 +185,7 @@ function test_move_past_end_of_word() Editor_state.lines = load_array{'abc def'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=1} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-right') check_eq(Editor_state.cursor1.pos, 4, 'F - test_move_past_end_of_word') end @@ -197,7 +197,7 @@ function test_skip_to_next_word() Editor_state.lines = load_array{'abc def'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=4} -- at the space between words - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-right') check_eq(Editor_state.cursor1.pos, 8, 'F - test_skip_to_next_word') end @@ -209,7 +209,7 @@ function test_skip_past_tab_to_next_word() Editor_state.lines = load_array{'abc\tdef'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=1} -- at the space between words - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-right') check_eq(Editor_state.cursor1.pos, 4, 'F - test_skip_past_tab_to_next_word') end @@ -221,7 +221,7 @@ function test_skip_multiple_spaces_to_next_word() Editor_state.lines = load_array{'abc def'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=4} -- at the start of second word - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-right') check_eq(Editor_state.cursor1.pos, 9, 'F - test_skip_multiple_spaces_to_next_word') end @@ -233,7 +233,7 @@ function test_move_past_end_of_word_on_next_line() Editor_state.lines = load_array{'abc def', 'ghi'} Text.redraw_all(Editor_state) Editor_state.cursor1 = {line=1, pos=8} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_keychord(Editor_state, 'M-right') check_eq(Editor_state.cursor1.line, 2, 'F - test_move_past_end_of_word_on_next_line/line') check_eq(Editor_state.cursor1.pos, 4, 'F - test_move_past_end_of_word_on_next_line/pos') @@ -250,7 +250,7 @@ function test_click_with_mouse() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- click on the other line - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) -- cursor moves check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse/cursor:line') @@ -268,7 +268,7 @@ function test_click_with_mouse_to_left_of_line() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- click to the left of the line - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_mouse_click(Editor_state, Editor_state.left-4,Editor_state.top+5, 1) -- cursor moves to start of line check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_to_left_of_line/cursor:line') @@ -288,7 +288,7 @@ function test_click_with_mouse_takes_margins_into_account() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- click on the other line - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) -- cursor moves check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_takes_margins_into_account/cursor:line') @@ -307,7 +307,7 @@ function test_click_with_mouse_on_empty_line() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- click on the empty line - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) -- cursor moves check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_on_empty_line/cursor') @@ -322,7 +322,7 @@ function test_draw_text() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_draw_text/screen:1') y = y + Editor_state.line_height @@ -340,7 +340,7 @@ function test_draw_wrapping_text() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_draw_wrapping_text/screen:1') y = y + Editor_state.line_height @@ -358,7 +358,7 @@ function test_draw_word_wrapping_text() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc ', 'F - test_draw_word_wrapping_text/screen:1') y = y + Editor_state.line_height @@ -378,7 +378,7 @@ function test_click_with_mouse_on_wrapping_line() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- click on the other line - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) -- cursor moves check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_on_wrapping_line/cursor:line') @@ -398,7 +398,7 @@ function test_click_with_mouse_on_wrapping_line_takes_margins_into_account() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- click on the other line - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) -- cursor moves check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/cursor:line') @@ -416,7 +416,7 @@ function test_draw_text_wrapping_within_word() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abcd ', 'F - test_draw_text_wrapping_within_word/screen:1') y = y + Editor_state.line_height @@ -435,7 +435,7 @@ function test_draw_wrapping_text_containing_non_ascii() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'mad', 'F - test_draw_wrapping_text_containing_non_ascii/screen:1') y = y + Editor_state.line_height @@ -455,7 +455,7 @@ function test_click_on_wrapping_line() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'madam ', 'F - test_click_on_wrapping_line/baseline/screen:1') y = y + Editor_state.line_height @@ -479,7 +479,7 @@ function test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen() Editor_state.cursor1 = {line=1, pos=8} Editor_state.screen_top1 = {line=1, pos=7} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, "I'm ad", 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/baseline/screen:2') y = y + Editor_state.line_height @@ -501,7 +501,7 @@ function test_click_past_end_of_wrapping_line() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'madam ', 'F - test_click_past_end_of_wrapping_line/baseline/screen:1') y = y + Editor_state.line_height @@ -526,7 +526,7 @@ function test_click_past_end_of_wrapping_line_containing_non_ascii() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'madam ', 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/baseline/screen:1') y = y + Editor_state.line_height @@ -552,7 +552,7 @@ function test_click_past_end_of_word_wrapping_line() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'the quick brown fox ', 'F - test_click_past_end_of_word_wrapping_line/baseline/screen:1') y = y + Editor_state.line_height @@ -572,7 +572,7 @@ function test_select_text() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- select a letter App.fake_key_press('lshift') edit.run_after_keychord(Editor_state, 'S-right') @@ -596,7 +596,7 @@ function test_cursor_movement_without_shift_resets_selection() Editor_state.selection1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- press an arrow key without shift edit.run_after_keychord(Editor_state, 'right') -- no change to data, selection is reset @@ -615,7 +615,7 @@ function test_edit_deletes_selection() Editor_state.selection1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- press a key edit.run_after_textinput(Editor_state, 'x') -- selected text is deleted and replaced with the key @@ -633,7 +633,7 @@ function test_edit_with_shift_key_deletes_selection() Editor_state.selection1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- mimic precise keypresses for a capital letter App.fake_key_press('lshift') edit.keychord_pressed(Editor_state, 'd', 'd') @@ -656,7 +656,7 @@ function test_copy_does_not_reset_selection() Editor_state.selection1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- copy selection edit.run_after_keychord(Editor_state, 'C-c') check_eq(App.clipboard, 'a', 'F - test_copy_does_not_reset_selection/clipboard') @@ -675,7 +675,7 @@ function test_cut() Editor_state.selection1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- press a key edit.run_after_keychord(Editor_state, 'C-x') check_eq(App.clipboard, 'a', 'F - test_cut/clipboard') @@ -694,7 +694,7 @@ function test_paste_replaces_selection() Editor_state.selection1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- set clipboard App.clipboard = 'xyz' -- paste selection @@ -714,7 +714,7 @@ function test_deleting_selection_may_scroll() Editor_state.cursor1 = {line=3, pos=2} Editor_state.screen_top1 = {line=2, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'def', 'F - test_deleting_selection_may_scroll/baseline/screen:1') y = y + Editor_state.line_height @@ -739,7 +739,7 @@ function test_edit_wrapping_text() Editor_state.cursor1 = {line=2, pos=4} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_textinput(Editor_state, 'g') local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_edit_wrapping_text/screen:1') @@ -759,7 +759,7 @@ function test_insert_newline() Editor_state.cursor1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_insert_newline/baseline/screen:1') y = y + Editor_state.line_height @@ -807,7 +807,7 @@ function test_insert_from_clipboard() Editor_state.cursor1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_insert_from_clipboard/baseline/screen:1') y = y + Editor_state.line_height @@ -838,7 +838,7 @@ function test_move_cursor_using_mouse() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} Editor_state.selection1 = {} - edit.draw(Editor_state) -- populate line_cache.starty for each line Editor_state.line_cache + edit.draw(Editor_state, Text_color) -- populate line_cache.starty for each line Editor_state.line_cache edit.run_after_mouse_release(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) check_eq(Editor_state.cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line') check_eq(Editor_state.cursor1.pos, 2, 'F - test_move_cursor_using_mouse/cursor:pos') @@ -856,7 +856,7 @@ function test_select_text_using_mouse() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} Editor_state.selection1 = {} - edit.draw(Editor_state) -- populate line_cache.starty for each line Editor_state.line_cache + edit.draw(Editor_state, Text_color) -- populate line_cache.starty for each line Editor_state.line_cache -- press and hold on first location edit.run_after_mouse_press(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) -- drag and release somewhere else @@ -877,7 +877,7 @@ function test_select_text_using_mouse_and_shift() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} Editor_state.selection1 = {} - edit.draw(Editor_state) -- populate line_cache.starty for each line Editor_state.line_cache + edit.draw(Editor_state, Text_color) -- populate line_cache.starty for each line Editor_state.line_cache -- click on first location edit.run_after_mouse_press(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) edit.run_after_mouse_release(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) @@ -903,7 +903,7 @@ function test_select_text_repeatedly_using_mouse_and_shift() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} Editor_state.selection1 = {} - edit.draw(Editor_state) -- populate line_cache.starty for each line Editor_state.line_cache + edit.draw(Editor_state, Text_color) -- populate line_cache.starty for each line Editor_state.line_cache -- click on first location edit.run_after_mouse_press(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) edit.run_after_mouse_release(Editor_state, Editor_state.left+8,Editor_state.top+5, 1) @@ -934,7 +934,7 @@ function test_cut_without_selection() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} Editor_state.selection1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- try to cut without selecting text edit.run_after_keychord(Editor_state, 'C-x') -- no crash @@ -951,7 +951,7 @@ function test_pagedown() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- initially the first two lines are displayed - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_pagedown/baseline/screen:1') y = y + Editor_state.line_height @@ -976,7 +976,7 @@ function test_pagedown_often_shows_start_of_wrapping_line() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_pagedown_often_shows_start_of_wrapping_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1007,7 +1007,7 @@ function test_pagedown_can_start_from_middle_of_long_wrapping_line() Editor_state.cursor1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1036,7 +1036,7 @@ function test_pagedown_never_moves_up() Editor_state.cursor1 = {line=1, pos=9} Editor_state.screen_top1 = {line=1, pos=9} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- pagedown makes no change edit.run_after_keychord(Editor_state, 'pagedown') check_eq(Editor_state.screen_top1.line, 1, 'F - test_pagedown_never_moves_up/screen_top:line') @@ -1053,7 +1053,7 @@ function test_down_arrow_moves_cursor() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- initially the first three lines are displayed - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_down_arrow_moves_cursor/baseline/screen:1') y = y + Editor_state.line_height @@ -1083,7 +1083,7 @@ function test_down_arrow_scrolls_down_by_one_line() Editor_state.cursor1 = {line=3, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_down_arrow_scrolls_down_by_one_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1112,7 +1112,7 @@ function test_down_arrow_scrolls_down_by_one_screen_line() Editor_state.cursor1 = {line=3, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_down_arrow_scrolls_down_by_one_screen_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1142,7 +1142,7 @@ function test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_ Editor_state.cursor1 = {line=3, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:1') y = y + Editor_state.line_height @@ -1171,7 +1171,7 @@ function test_page_down_followed_by_down_arrow_does_not_scroll_screen_up() Editor_state.cursor1 = {line=3, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:1') y = y + Editor_state.line_height @@ -1206,7 +1206,7 @@ function test_up_arrow_moves_cursor() Editor_state.cursor1 = {line=3, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_up_arrow_moves_cursor/baseline/screen:1') y = y + Editor_state.line_height @@ -1236,7 +1236,7 @@ function test_up_arrow_scrolls_up_by_one_line() Editor_state.cursor1 = {line=2, pos=1} Editor_state.screen_top1 = {line=2, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'def', 'F - test_up_arrow_scrolls_up_by_one_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1265,7 +1265,7 @@ function test_up_arrow_scrolls_up_by_one_screen_line() Editor_state.cursor1 = {line=3, pos=6} Editor_state.screen_top1 = {line=3, pos=5} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'jkl', 'F - test_up_arrow_scrolls_up_by_one_screen_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1294,7 +1294,7 @@ function test_up_arrow_scrolls_up_to_final_screen_line() Editor_state.cursor1 = {line=2, pos=1} Editor_state.screen_top1 = {line=2, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'ghi', 'F - test_up_arrow_scrolls_up_to_final_screen_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1325,7 +1325,7 @@ function test_up_arrow_scrolls_up_to_empty_line() Editor_state.cursor1 = {line=2, pos=1} Editor_state.screen_top1 = {line=2, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_up_arrow_scrolls_up_to_empty_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1354,7 +1354,7 @@ function test_pageup() Editor_state.screen_top1 = {line=2, pos=1} Editor_state.screen_bottom1 = {} -- initially the last two lines are displayed - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'def', 'F - test_pageup/baseline/screen:1') y = y + Editor_state.line_height @@ -1379,7 +1379,7 @@ function test_pageup_scrolls_up_by_screen_line() Editor_state.cursor1 = {line=2, pos=1} Editor_state.screen_top1 = {line=2, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'ghi', 'F - test_pageup_scrolls_up_by_screen_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1409,7 +1409,7 @@ function test_pageup_scrolls_up_from_middle_screen_line() Editor_state.cursor1 = {line=2, pos=5} Editor_state.screen_top1 = {line=2, pos=5} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'jkl', 'F - test_pageup_scrolls_up_from_middle_screen_line/baseline/screen:2') y = y + Editor_state.line_height @@ -1437,7 +1437,7 @@ function test_enter_on_bottom_line_scrolls_down() Editor_state.cursor1 = {line=3, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_enter_on_bottom_line_scrolls_down/baseline/screen:1') y = y + Editor_state.line_height @@ -1467,7 +1467,7 @@ function test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom() Editor_state.cursor1 = {line=4, pos=2} Editor_state.screen_top1 = {line=4, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'jkl', 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/baseline/screen:1') -- after hitting the enter key the screen does not scroll down @@ -1491,7 +1491,7 @@ function test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bot Editor_state.cursor1 = {line=2, pos=1} Editor_state.screen_top1 = {line=2, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- after hitting the inserting_text key the screen does not scroll down edit.run_after_textinput(Editor_state, 'a') check_eq(Editor_state.screen_top1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen_top') @@ -1511,7 +1511,7 @@ function test_typing_on_bottom_line_scrolls_down() Editor_state.cursor1 = {line=3, pos=4} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_typing_on_bottom_line_scrolls_down/baseline/screen:1') y = y + Editor_state.line_height @@ -1544,7 +1544,7 @@ function test_left_arrow_scrolls_up_in_wrapped_line() Editor_state.screen_bottom1 = {} -- cursor is at top of screen Editor_state.cursor1 = {line=3, pos=5} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'jkl', 'F - test_left_arrow_scrolls_up_in_wrapped_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1574,7 +1574,7 @@ function test_right_arrow_scrolls_down_in_wrapped_line() Editor_state.screen_bottom1 = {} -- cursor is at bottom right of screen Editor_state.cursor1 = {line=3, pos=5} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_right_arrow_scrolls_down_in_wrapped_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1605,7 +1605,7 @@ function test_home_scrolls_up_in_wrapped_line() Editor_state.screen_bottom1 = {} -- cursor is at top of screen Editor_state.cursor1 = {line=3, pos=5} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'jkl', 'F - test_home_scrolls_up_in_wrapped_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1635,7 +1635,7 @@ function test_end_scrolls_down_in_wrapped_line() Editor_state.screen_bottom1 = {} -- cursor is at bottom right of screen Editor_state.cursor1 = {line=3, pos=5} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc', 'F - test_end_scrolls_down_in_wrapped_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1665,7 +1665,7 @@ function test_position_cursor_on_recently_edited_wrapping_line() Editor_state.cursor1 = {line=1, pos=25} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'abc def ghi ', 'F - test_position_cursor_on_recently_edited_wrapping_line/baseline1/screen:1') y = y + Editor_state.line_height @@ -1700,7 +1700,7 @@ function test_backspace_can_scroll_up() Editor_state.cursor1 = {line=2, pos=1} Editor_state.screen_top1 = {line=2, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'def', 'F - test_backspace_can_scroll_up/baseline/screen:1') y = y + Editor_state.line_height @@ -1729,7 +1729,7 @@ function test_backspace_can_scroll_up_screen_line() Editor_state.cursor1 = {line=3, pos=5} Editor_state.screen_top1 = {line=3, pos=5} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) local y = Editor_state.top App.screen.check(y, 'jkl', 'F - test_backspace_can_scroll_up_screen_line/baseline/screen:1') y = y + Editor_state.line_height @@ -1872,7 +1872,7 @@ function test_undo_insert_text() Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} -- insert a character - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) edit.run_after_textinput(Editor_state, 'g') check_eq(Editor_state.cursor1.line, 2, 'F - test_undo_insert_text/baseline/cursor:line') check_eq(Editor_state.cursor1.pos, 5, 'F - test_undo_insert_text/baseline/cursor:pos') @@ -1947,7 +1947,7 @@ function test_undo_restores_selection() Editor_state.selection1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- delete selected text edit.run_after_textinput(Editor_state, 'x') check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_undo_restores_selection/baseline') @@ -1969,7 +1969,7 @@ function test_search() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') edit.run_after_textinput(Editor_state, 'd') @@ -1997,7 +1997,7 @@ function test_search_upwards() Editor_state.cursor1 = {line=1, pos=2} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') edit.run_after_textinput(Editor_state, 'a') @@ -2016,7 +2016,7 @@ function test_search_wrap() Editor_state.cursor1 = {line=1, pos=3} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- search for a string edit.run_after_keychord(Editor_state, 'C-f') edit.run_after_textinput(Editor_state, 'a') @@ -2035,7 +2035,7 @@ function test_search_wrap_upwards() Editor_state.cursor1 = {line=1, pos=1} Editor_state.screen_top1 = {line=1, pos=1} Editor_state.screen_bottom1 = {} - edit.draw(Editor_state) + edit.draw(Editor_state, Text_color) -- search upwards for a string edit.run_after_keychord(Editor_state, 'C-f') edit.run_after_textinput(Editor_state, 'a')