TOJA6VDEWPXDE4KE6URFLNIZBQ6ASAFDZMSYSIBDBKACBGUKZI3QC JQ3PAMLPMSWEWAFFG2MTQTWVFNBSYV3UWC4A4YLCSI5YJ5IHUCLQC 7UDWUUVDIUFK3DFZ5WLZ5LZWDDFSCZN5AKVBUZCOIRKFOIG2ZGNAC AYX33NBCPCBFWEZI5KZXHP3Y2Q62GYVT4WHYJUYRIPYV67KPSYZAC R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC JOPVPUSAMMU6RFVDQR4NJC4GNNUFB7GPKVH7OS5FKCYS5QZ53VLQC M2SRPSX6TJJEEKUT6C4OEEZQNTL2FJEHDVSPLRHLNPZ7CWJQHSAAC CNCYMM6ABOXCRI2IP5A4T2OGBO5FQ7GWBXBP2OQYL4YET5BLJCGQC 2WGHUWE6DWRNUD7AJNLGT4I6PZ2EIVDQCZ7V7V7WSYPBRPYUUDUQC CE4LZV4TNXJT54CVGM3QANCBP42TMLMZWF2DBSMUYKAHILXIZEMQC LLQC2M2IMEJBJQXZTKC3OAKG5WKHSERXKAKCYHQRUZZD6CVRIHAQC 3VHUIIATPOF7FXB7NTL5MESCV5BCQACII2D7QZ4UIUCBX3CWXMMAC 3PSFWAILGRA4OYXWS2DX7VF332AIBPYBXHEA4GIQY2XEJVD65UMAC GRSHSSV5ZRYOXD3SGMCOXKVFXLNZYLAN3YVBDUE6IVZBIK5S3UXQC FXI74QCLOZ4BS7UVZ3U2PE3LOL7MX3FWGHZCTGH3DYFXGTXVVIRAC VDXOEDS757ISV5KM5AUFZDFH223CHQB4FK3TQOQ75CDDJAPLCFQQC M75WBEA4QUH5VRH6OD35FLPVSM3ILQNPJOE6QZPNONF32IMRLUJQC CXINBGIMA35SOE3KBVTJXM37RQTVENVRDKMGXOKEZPD37JMH37DAC 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')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')endcheck_eq(Editor_state.right, 300 - Test_margin_right, 'F - test_resize_window/baseline/right_margin')App.resize(200, 400)
App.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]endApp.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_rightelseApp.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)Menu_status_bar_height = 5 + --[[line height in tests]] 15 + 5-- 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
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')
App.screen.width = Log_browser_state.right + Margin_right
App.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