bugfix: ensure Cursor_line is always on a text line

[?]
May 19, 2022, 1:19 AM
242L3OQXTU2TCAINRJXQEEDSXQXM7Y7USUPBK37ZNM3A7V5TUDSAC

Dependencies

  • [2] A2TQYJ6J .
  • [3] DLQMM265 scroll past first page
  • [4] 252M2QMD forgot to move this special case out
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] HYEAFRZ2 split mouse_pressed events between Text and Drawing
  • [*] OTIBCAUJ love2d scaffold
  • [*] XNFTJHC4 split keyboard handling between Text and Drawing
  • [*] FS2ITYYH record a known issue

Change contents

  • edit in text.lua at line 158
    [7.6]
    [7.6]
    function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
    while Cursor_line <= #Lines do
    if Lines[Cursor_line].mode == 'text' then
    break
    end
    Cursor_line = Cursor_line + 1
    end
    -- hack: insert a text line at bottom of file if necessary
    if Cursor_line > #Lines then
    assert(Cursor_line == #Lines+1)
    table.insert(Lines, {mode='text', data=''})
    end
    if Cursor_line > Screen_bottom_line then
    Screen_top_line = Cursor_line
    Text.scroll_up_while_cursor_on_screen()
    end
    end
    function Text.scroll_up_while_cursor_on_screen()
    local y = Screen_height - 15*Zoom -- for Cursor_line
    while true do
    if Screen_top_line == 1 then break end
    y = y - 15*Zoom
    if Lines[Screen_top_line].mode == 'drawing' then
    y = y - Drawing.pixels(Lines[Screen_top_line].h)
    end
    if y < 15*Zoom then
    break
    end
    Screen_top_line = Screen_top_line - 1
    end
    end
  • edit in main.lua at line 175
    [3.1721]
    [3.1721]
    Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
  • replacement in main.lua at line 181
    [3.1889][3.1889:1976]()
    if Lines[Screen_top_line].mode == 'text' then
    y = y - 15*Zoom
    else
    [3.1889]
    [3.1976]
    y = y - 15*Zoom
    if Lines[Screen_top_line].mode == 'drawing' then
  • edit in main.lua at line 191
    [3.2194]
    [9.5015]
    Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
  • edit in README.md at line 6
    [2.148]
    * The text cursor will always stay on the screen. This can have some strange
    implications:
    * A long series of drawings will get silently skipped when you hit
    page-down, until a line of text can be showed on screen.
    * If there's no line of text at the bottom of the file, one will be
    created.
    So far this app isn't really designed for all-drawing files. I'm really just
    targeting mostly-text files with a few drawings mixed in.