Merge lines.love
[?]
Sep 17, 2022, 5:49 PM
AYX33NBCPCBFWEZI5KZXHP3Y2Q62GYVT4WHYJUYRIPYV67KPSYZACDependencies
- [2]
C3NYQP57Merge lines.love - [3]
NNTMVNVO. - [4]
ENENSZLKbugfix: source margins when toggling log browser - [5]
JMUD7T3Oget rid of ugly side-effects in tests - [6]
NFI42KGXmore correct absolute path detection - [7]
RSZD5A7Gforgot to add json.lua - [8]
2L5MEZV3experiment: new edit namespace - [9]
BLWAYPKVextract a module - [10]
AVTNUQYRbasic test-enabled framework - [11]
VXORMHMEdelete experimental REPL - [12]
32V6ZHQBMerge lines.love - [13]
KKMFQDR4editing source code from within the app - [14]
XX7G2FFJintermingle freehand line drawings with text - [15]
D2GCFTTTclean up repl functionality - [16]
T4FRZSYLdelete an ancient, unused file - [17]
BJ5X5O4Alet's prevent the text cursor from ever getting on a drawing - [18]
X3CQLBTRset window title within each app - [19]
SXTQMD44include some missing source files - [20]
3PSFWAILMerge lines.love - [21]
ZJOSQFN6bugfix: path munging on Windows - [22]
4YDBYBA4clean up memory leak experiments - [23]
2CTN2IEFMerge lines.love - [24]
2WGHUWE6self-documenting 0 Test_right_margin - [25]
OGUV4HSAremove some memory leaks from rendered fragments - [26]
4VQGE7RAnew test - [27]
MD3W5IRAnew fork: rip out drawing support - [28]
OTIBCAUJlove2d scaffold - [29]
3QNOKBFMbeginnings of a test harness - [30]
GUOQRUL7Merge lines.love - [31]
TFM6F5ODMerge lines.love - [32]
R5QXEHUIsomebody stop me - [33]
JOPVPUSAediting source code from within the app - [34]
TVCPXAAUrename - [35]
VHQCNMARseveral more modules - [36]
D4B52CQ2Merge lines.love - [37]
BULPIBEGbeginnings of a module for the text editor - [38]
KMSL74GAsupport selections in the source editor - [39]
CE4LZV4Tdrop last couple of manual tests - [40]
VHUNJHXBMerge lines.love - [41]
6SMGKYDR. - [42]
66X36NZNa little more prose describing manual_tests - [43]
FS2ITYYHrecord a known issue - [44]
K2X6G75Zstart writing some tests for drawings - [45]
6LJZN727handle chords - [46]
OI4FPFINsupport drawings in the source editor - [47]
73OCE2MCafter much struggle, a brute-force undo - [48]
P3K7UH5CMerge lines.love - [49]
LXTTOB33extract a couple of files - [50]
AKZWDWIAMerge lines.love - [51]
TLOAPLBJadd a license
Change contents
- file deletion: source_tests.lua source_tests.lua
endfunction test_show_log_browser_side()io.write('\ntest_show_log_browser_side')App.screen.init{width=300, height=300}Editor_state = edit.initialize_test_state()Editor_state.filename = 'foo'Text.redraw_all(Editor_state)Log_browser_state = edit.initialize_test_state()Text.redraw_all(Log_browser_state)log_browser.parse(Log_browser_state)check(not Show_log_browser_side, 'F - test_show_log_browser_side/baseline')App.wait_fake_time(0.1)App.run_after_keychord('C-l')check(Show_log_browser_side, 'F - test_show_log_browser_side')function test_show_log_browser_side_doubles_window_width_if_possible()io.write('\ntest_show_log_browser_side_doubles_window_width_if_possible')-- initialize screen dimensions to half widthApp.screen.init{width=300, height=300}Display_width = App.screen.width*2-- initialize source app with left side occupying entire window (half the display)Current_app = 'source'Editor_state = edit.initialize_test_state()Editor_state.filename = 'foo'Editor_state.left = Margin_leftEditor_state.right = App.screen.width - Margin_rightlocal old_editor_right = Editor_state.rightText.redraw_all(Editor_state)Log_browser_state = edit.initialize_test_state()-- log browser has some arbitrary marginsLog_browser_state.left = 200 + Margin_leftLog_browser_state.right = 400Text.redraw_all(Log_browser_state)log_browser.parse(Log_browser_state)-- display log browserApp.wait_fake_time(0.1)App.run_after_keychord('C-l')-- window width is doubledcheck_eq(App.screen.width, 600, 'F - test_show_log_browser_side_doubles_window_width_if_possible/display:width')-- left side margins are unchangedcheck_eq(Editor_state.left, Margin_left, 'F - test_show_log_browser_side_doubles_window_width_if_possible/edit:left')check_eq(Editor_state.right, old_editor_right, 'F - test_show_log_browser_side_doubles_window_width_if_possible/edit:right')-- log browser margins are adjustedcheck_eq(Log_browser_state.left, App.screen.width/2 + Margin_left, 'F - test_show_log_browser_side_doubles_window_width_if_possible/log:left')check_eq(Log_browser_state.right, App.screen.width - Margin_right, 'F - test_show_log_browser_side_doubles_window_width_if_possible/log:right')endfunction test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width()io.write('\ntest_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width')-- initialize screen dimensions and indicate that it is maximizedApp.screen.init{width=300, height=300}Display_width = 300-- initialize source app with left side occupying more than half the displayCurrent_app = 'source'Editor_state = edit.initialize_test_state()Editor_state.filename = 'foo'Editor_state.left = Margin_leftEditor_state.right = 200Text.redraw_all(Editor_state)Log_browser_state = edit.initialize_test_state()-- log browser has some arbitrary marginsLog_browser_state.left = 200 + Margin_leftLog_browser_state.right = 400Text.redraw_all(Log_browser_state)log_browser.parse(Log_browser_state)-- display log browserApp.wait_fake_time(0.1)App.run_after_keychord('C-l')-- margins are now adjustedcheck_eq(Editor_state.left, Margin_left, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/edit:left')check_eq(Editor_state.right, App.screen.width/2 - Margin_right, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/edit:right')check_eq(Log_browser_state.left, App.screen.width/2 + Margin_left, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/log:left')check_eq(Log_browser_state.right, App.screen.width - Margin_right, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/log:right')endfunction test_drop_file()io.write('\ntest_drop_file')App.screen.init{width=Editor_state.left+300, height=300}Editor_state = edit.initialize_test_state()App.filesystem['foo'] = 'abc\ndef\nghi\n'local fake_dropped_file = {opened = false,getFilename = function(self)return 'foo'end,open = function(self)self.opened = trueend,lines = function(self)assert(self.opened)return App.filesystem['foo']:gmatch('[^\n]+')end,close = function(self)self.opened = falseend,}App.filedropped(fake_dropped_file)check_eq(#Editor_state.lines, 3, 'F - test_drop_file/#lines')check_eq(Editor_state.lines[1].data, 'abc', 'F - test_drop_file/lines:1')check_eq(Editor_state.lines[2].data, 'def', 'F - test_drop_file/lines:2')check_eq(Editor_state.lines[3].data, 'ghi', 'F - test_drop_file/lines:3')edit.draw(Editor_state)endfunction test_drop_file_saves_previous()io.write('\ntest_drop_file_saves_previous')App.screen.init{width=Editor_state.left+300, height=300}-- initially editing a file called foo that hasn't been saved to filesystem yetEditor_state.lines = load_array{'abc', 'def'}Editor_state.filename = 'foo'schedule_save(Editor_state)-- now drag a new file bar from the filesystemApp.filesystem['bar'] = 'abc\ndef\nghi\n'local fake_dropped_file = {opened = false,getFilename = function(self)return 'bar'end,open = function(self)self.opened = trueend,lines = function(self)assert(self.opened)return App.filesystem['bar']:gmatch('[^\n]+')end,close = function(self)self.opened = falseend,}App.filedropped(fake_dropped_file)-- filesystem now contains a file called foocheck_eq(App.filesystem['foo'], 'abc\ndef\n', 'F - test_drop_file_saves_previous')endend-- pressing ctrl+l shows log-browser sideDisplay_width = App.screen.widthCurrent_app = 'source'check_eq(Editor_state.right, 300 - Test_margin_right, 'F - test_resize_window/baseline/right_margin')App.resize(200, 400) - file deletion: source_edit.lua source_edit.lua
if #State.lines ~= #State.line_cache thenprint(('line_cache is out of date; %d when it should be %d'):format(#State.line_cache, #State.lines))assert(false)endif not Text.le1(State.screen_top1, State.cursor1) thenprint(State.screen_top1.line, State.screen_top1.pos, State.screen_top1.posB, State.cursor1.line, State.cursor1.pos, State.cursor1.posB)assert(false)endState.cursor_x = nilState.cursor_y = nillocal y = State.top--? print('== draw')for line_index = State.screen_top1.line,#State.lines dolocal line = State.lines[line_index] - file deletion: source.lua source.lua
Menu_status_bar_height = 5 + --[[line height in tests]] 15 + 5App.screen.width = math.min(Display_width, App.screen.width*2)Editor_state.right = App.screen.width/2 - Margin_rightLog_browser_state.left = App.screen.width/2 + Margin_leftLog_browser_state.right = App.screen.width - Margin_rightApp.screen.resize(App.screen.width, App.screen.height, App.screen.flags)--? print('done setting window')-- try to restore position if possible-- if the window gets wider the window manager may not respect thissource.set_window_position_from_settings(Settings.source)returnendif chord == 'C-g' thenShow_file_navigator = trueFile_navigation.index = 1returnendif Focus == 'edit' thenreturn edit.keychord_pressed(Editor_state, chord, key)elsereturn log_browser.keychord_pressed(Log_browser_state, chord, key)endendfunction source.key_released(key, scancode)Cursor_time = 0 -- ensure cursor is visible immediately after it movesif Focus == 'edit' thenreturn edit.key_released(Editor_state, key, scancode)elsereturn log_browser.keychord_pressed(Log_browser_state, chordkey, scancode)endend-- use this sparinglyfunction to_text(s)if Text_cache[s] == nil thenText_cache[s] = App.newText(love.graphics.getFont(), s)endreturn Text_cache[s]endelseApp.screen.width = Editor_state.right + Margin_rightend--? print('setting window:', App.screen.width, App.screen.height)Settings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position()endlocal filename = Editor_state.filenameSettings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position()endfunction source.resize(w, h)--? print(("Window resized to width: %d and height: %d."):format(w, h))App.screen.width, App.screen.height = w, hText.redraw_all(Editor_state)Editor_state.selection1 = {} -- no support for shift drag while we're resizingif Show_log_browser_side thenEditor_state.right = App.screen.width/2 - Margin_rightelseEditor_state.right = App.screen.width-Margin_rightendLog_browser_state.left = App.screen.width/2 + Margin_rightLog_browser_state.right = App.screen.width-Margin_rightEditor_state.width = Editor_state.right-Editor_state.leftText.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right)--? print('end resize')endfunction source.filedropped(file)-- first make sure to save edits on any existing fileif Editor_state.next_save thensave_to_disk(Editor_state)end-- clear the slate for the new fileEditor_state.filename = file:getFilename()file:open('r')Editor_state.lines = load_from_file(file)file:close()Text.redraw_all(Editor_state)Editor_state.screen_top1 = {line=1, pos=1}Editor_state.cursor1 = {line=1, pos=1}App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)print('initializing source position')if Settings == nil then Settings = {} endif Settings.source == nil then Settings.source = {} endApp.screen.resize(0, 0) -- maximizeDisplay_width, Display_height, App.screen.flags = App.screen.size()-- shrink height slightly to account for window decorationApp.screen.height = Display_height-100App.screen.width = 40*em_widthApp.screen.flags.resizable = trueApp.screen.flags.minwidth = math.min(App.screen.width, 200)App.screen.flags.minheight = math.min(App.screen.width, 200)App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)--? print('loading source position', settings.x, settings.y, settings.displayindex)source.set_window_position_from_settings(settings)Show_log_browser_side = settings.show_log_browser_sidelocal right = App.screen.width - Margin_rightif Show_log_browser_side thenright = App.screen.width/2 - Margin_rightendEditor_state = edit.initialize_state(Margin_top, Margin_left, right, settings.font_height, math.floor(settings.font_height*1.3))Editor_state.filename = settings.filenameEditor_state.screen_top1 = settings.screen_topEditor_state.cursor1 = settings.cursorendfunction source.set_window_position_from_settings(settings)-- setPosition doesn't quite seem to do what is asked of it on Linux.love.window.setPosition(settings.x, settings.y-37, settings.displayindex)endfunction source.initialize_default_settings()local font_height = 20love.graphics.setFont(love.graphics.newFont(font_height))local em = App.newText(love.graphics.getFont(), 'm')source.initialize_window_geometry(App.width(em))Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right)Editor_state.font_height = font_heightEditor_state.line_height = math.floor(font_height*1.3)Editor_state.em = emendfunction source.initialize_window_geometry(em_width)-- maximize windowApp.screen.resize(0, 0) -- maximizeDisplay_width, Display_height, App.screen.flags = App.screen.size()-- set up desired window dimensionsApp.screen.flags.resizable = trueApp.screen.flags.minwidth = math.min(Display_width, 200)App.screen.flags.minheight = math.min(Display_height, 200)App.screen.width, App.screen.height = settings.width, settings.height--? print('setting window from settings:', App.screen.width, App.screen.height)-- a few text objects we can avoid recomputing unless the font changesText_cache = {}-- blinking cursorCursor_time = 0end-- called only for real runfunction source.initialize()love.keyboard.setTextInput(true) -- bring up keyboard on touch screenlove.keyboard.setKeyRepeat(true)love.graphics.setBackgroundColor(1,1,1)if Settings and Settings.source thensource.load_settings()elsesource.initialize_default_settings()endsource.initialize_edit_side{'run.lua'}source.initialize_log_browser_side()Menu_status_bar_height = 5 + Editor_state.line_height + 5Editor_state.top = Editor_state.top + Menu_status_bar_heightLog_browser_state.top = Log_browser_state.top + Menu_status_bar_height - replacement in source_tests.lua at line 10
check_eq(Editor_state.right, 300 - Test_margin_right, 'F - test_resize_window/baseline/left_margin')check_eq(Editor_state.right, 300 - Test_margin_right, 'F - test_resize_window/baseline/right_margin') - edit in source_tests.lua at line 19
endfunction test_show_log_browser_side()io.write('\ntest_show_log_browser_side')App.screen.init{width=300, height=300}Display_width = App.screen.widthCurrent_app = 'source'Editor_state = edit.initialize_test_state()Editor_state.filename = 'foo'Text.redraw_all(Editor_state)Log_browser_state = edit.initialize_test_state()Text.redraw_all(Log_browser_state)log_browser.parse(Log_browser_state)check(not Show_log_browser_side, 'F - test_show_log_browser_side/baseline')-- pressing ctrl+l shows log-browser sideApp.wait_fake_time(0.1)App.run_after_keychord('C-l')check(Show_log_browser_side, 'F - test_show_log_browser_side')endfunction test_show_log_browser_side_doubles_window_width_if_possible()io.write('\ntest_show_log_browser_side_doubles_window_width_if_possible')-- initialize screen dimensions to half widthApp.screen.init{width=300, height=300}Display_width = App.screen.width*2-- initialize source app with left side occupying entire window (half the display)Current_app = 'source'Editor_state = edit.initialize_test_state()Editor_state.filename = 'foo'Editor_state.left = Margin_leftEditor_state.right = App.screen.width - Margin_rightlocal old_editor_right = Editor_state.rightText.redraw_all(Editor_state)Log_browser_state = edit.initialize_test_state()-- log browser has some arbitrary marginsLog_browser_state.left = 200 + Margin_leftLog_browser_state.right = 400Text.redraw_all(Log_browser_state)log_browser.parse(Log_browser_state)-- display log browserApp.wait_fake_time(0.1)App.run_after_keychord('C-l')-- window width is doubledcheck_eq(App.screen.width, 600, 'F - test_show_log_browser_side_doubles_window_width_if_possible/display:width')-- left side margins are unchangedcheck_eq(Editor_state.left, Margin_left, 'F - test_show_log_browser_side_doubles_window_width_if_possible/edit:left')check_eq(Editor_state.right, old_editor_right, 'F - test_show_log_browser_side_doubles_window_width_if_possible/edit:right')-- log browser margins are adjustedcheck_eq(Log_browser_state.left, App.screen.width/2 + Margin_left, 'F - test_show_log_browser_side_doubles_window_width_if_possible/log:left')check_eq(Log_browser_state.right, App.screen.width - Margin_right, 'F - test_show_log_browser_side_doubles_window_width_if_possible/log:right')endfunction test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width()io.write('\ntest_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width')-- initialize screen dimensions and indicate that it is maximizedApp.screen.init{width=300, height=300}Display_width = 300-- initialize source app with left side occupying more than half the displayCurrent_app = 'source'Editor_state = edit.initialize_test_state()Editor_state.filename = 'foo'Editor_state.left = Margin_leftEditor_state.right = 200Text.redraw_all(Editor_state)Log_browser_state = edit.initialize_test_state()-- log browser has some arbitrary marginsLog_browser_state.left = 200 + Margin_leftLog_browser_state.right = 400Text.redraw_all(Log_browser_state)log_browser.parse(Log_browser_state)-- display log browserApp.wait_fake_time(0.1)App.run_after_keychord('C-l')-- margins are now adjustedcheck_eq(Editor_state.left, Margin_left, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/edit:left')check_eq(Editor_state.right, App.screen.width/2 - Margin_right, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/edit:right')check_eq(Log_browser_state.left, App.screen.width/2 + Margin_left, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/log:left')check_eq(Log_browser_state.right, App.screen.width - Margin_right, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/log:right') - replacement in source_edit.lua at line 130
assert(#State.lines == #State.line_cache)if #State.lines ~= #State.line_cache thenprint(('line_cache is out of date; %d when it should be %d'):format(#State.line_cache, #State.lines))assert(false)end - replacement in source.lua at line 48
Menu_status_bar_height = nil -- initialized belowMenu_status_bar_height = 5 + --[[line height in tests]] 15 + 5 - replacement in source.lua at line 119
love.window.setMode(0, 0) -- maximizeDisplay_width, Display_height, App.screen.flags = love.window.getMode()App.screen.resize(0, 0) -- maximizeDisplay_width, Display_height, App.screen.flags = App.screen.size() - replacement in source.lua at line 127
love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)App.screen.resize(App.screen.width, App.screen.height, App.screen.flags) - replacement in source.lua at line 159
love.window.setMode(0, 0) -- maximizeDisplay_width, Display_height, App.screen.flags = love.window.getMode()App.screen.resize(0, 0) -- maximizeDisplay_width, Display_height, App.screen.flags = App.screen.size() - replacement in source.lua at line 167
love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)App.screen.resize(App.screen.width, App.screen.height, App.screen.flags) - replacement in source.lua at line 171
Settings.source.x, Settings.source.y, Settings.source.displayindex = love.window.getPosition()Settings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position() - replacement in source.lua at line 257
Settings.source.x, Settings.source.y, Settings.source.displayindex = love.window.getPosition()Settings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position() - replacement in source.lua at line 325
App.screen.width = Log_browser_state.right + Margin_rightApp.screen.width = math.min(Display_width, App.screen.width*2)Editor_state.right = App.screen.width/2 - Margin_rightLog_browser_state.left = App.screen.width/2 + Margin_leftLog_browser_state.right = App.screen.width - Margin_right - replacement in source.lua at line 333
love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)