34QHL4KCLCWXMXY7CBWZIEMKL6BX62DACWANNPQPYUHSV2INSE2QC
D2KRR2KTJJQCVGQYIEJDLV4NKMXBSNN6WOB62BVZ67KKMBRITD7AC
NNTMVNVOGXTHJKTNOWOSF257EQFLGJNRT7TJ3JIT4JNIJQYVR7JQC
ENENSZLKCCS7XILJUHIJUQPBOI6VK74YPHBFWPBXAHHHTHT2D3UQC
JMUD7T3OJTEF5V73Y2B2GSVUBNBSJFRJPZNREBE5E4BV3IG6SJLQC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
KKMFQDR43ZWVCDRHQLWWX3FCWCFA3ZSXYOBRJNPHUQZR2XPKWULAC
S2BZ3VEFKU4SYA2FYNYHKVSOXJBCQUZYI3DAGZAPGIHDLDLX44SAC
4VQGE7RAC2B4NWCCKDCUZMMRDRMXLN6357YY4OPFIK6BZBGRWDHQC
6SMGKYDRM7QERJDO2URF57M3G7OVJBAVPZGD7XO7K2VZCL4TNYBAC
5R2LPB3UGD6S6YTJKRFA7FOCTZERZW5ACCPP46KQWY7K3FZ7ASQAC
JOPVPUSAMMU6RFVDQR4NJC4GNNUFB7GPKVH7OS5FKCYS5QZ53VLQC
end
function 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')
end
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 width
App.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_left
Editor_state.right = App.screen.width - Margin_right
local old_editor_right = Editor_state.right
Text.redraw_all(Editor_state)
Log_browser_state = edit.initialize_test_state()
-- log browser has some arbitrary margins
Log_browser_state.left = 200 + Margin_left
Log_browser_state.right = 400
Text.redraw_all(Log_browser_state)
log_browser.parse(Log_browser_state)
-- display log browser
App.wait_fake_time(0.1)
App.run_after_keychord('C-l')
-- window width is doubled
check_eq(App.screen.width, 600, 'F - test_show_log_browser_side_doubles_window_width_if_possible/display:width')
-- left side margins are unchanged
check_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 adjusted
check_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')
end
function 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 maximized
App.screen.init{width=300, height=300}
Display_width = 300
-- initialize source app with left side occupying more than half the display
Current_app = 'source'
Editor_state = edit.initialize_test_state()
Editor_state.filename = 'foo'
Editor_state.left = Margin_left
Editor_state.right = 200
Text.redraw_all(Editor_state)
Log_browser_state = edit.initialize_test_state()
-- log browser has some arbitrary margins
Log_browser_state.left = 200 + Margin_left
Log_browser_state.right = 400
Text.redraw_all(Log_browser_state)
log_browser.parse(Log_browser_state)
-- display log browser
App.wait_fake_time(0.1)
App.run_after_keychord('C-l')
-- margins are now adjusted
check_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')
end
function 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 = true
end,
lines = function(self)
assert(self.opened)
return App.filesystem['foo']:gmatch('[^\n]+')
end,
close = function(self)
self.opened = false
end,
}
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)
end
function 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 yet
Editor_state.lines = load_array{'abc', 'def'}
Editor_state.filename = 'foo'
schedule_save(Editor_state)
-- now drag a new file bar from the filesystem
App.filesystem['bar'] = 'abc\ndef\nghi\n'
local fake_dropped_file = {
opened = false,
getFilename = function(self)
return 'bar'
end,
open = function(self)
self.opened = true
end,
lines = function(self)
assert(self.opened)
return App.filesystem['bar']:gmatch('[^\n]+')
end,
close = function(self)
self.opened = false
end,
}
App.filedropped(fake_dropped_file)
-- filesystem now contains a file called foo
check_eq(App.filesystem['foo'], 'abc\ndef\n', 'F - test_drop_file_saves_previous')
end
-- pressing ctrl+l shows log-browser side
Display_width = App.screen.width
Current_app = 'source'
check_eq(Editor_state.right, 300 - Test_margin_right, 'F - test_resize_window/baseline/right_margin')
App.resize(200, 400)
if #State.lines ~= #State.line_cache then
print(('line_cache is out of date; %d when it should be %d'):format(#State.line_cache, #State.lines))
assert(false)
end
if not Text.le1(State.screen_top1, State.cursor1) then
print(State.screen_top1.line, State.screen_top1.pos, State.screen_top1.posB, State.cursor1.line, State.cursor1.pos, State.cursor1.posB)
assert(false)
end
State.cursor_x = nil
State.cursor_y = nil
local y = State.top
--? print('== draw')
for line_index = State.screen_top1.line,#State.lines do
local line = State.lines[line_index]
Menu_status_bar_height = 5 + --[[line height in tests]] 15 + 5
App.screen.width = math.min(Display_width, App.screen.width*2)
Editor_state.right = App.screen.width/2 - Margin_right
Log_browser_state.left = App.screen.width/2 + Margin_left
Log_browser_state.right = App.screen.width - Margin_right
else
App.screen.width = Editor_state.right + Margin_right
end
--? print('setting window:', App.screen.width, App.screen.height)
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 this
source.set_window_position_from_settings(Settings.source)
return
end
if chord == 'C-g' then
Show_file_navigator = true
File_navigation.index = 1
return
end
if Focus == 'edit' then
return edit.keychord_pressed(Editor_state, chord, key)
else
return log_browser.keychord_pressed(Log_browser_state, chord, key)
end
end
function source.key_released(key, scancode)
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
if Focus == 'edit' then
return edit.key_released(Editor_state, key, scancode)
else
return log_browser.keychord_pressed(Log_browser_state, chordkey, scancode)
end
end
-- use this sparingly
function to_text(s)
if Text_cache[s] == nil then
Text_cache[s] = App.newText(love.graphics.getFont(), s)
end
return Text_cache[s]
end
App.screen.resize(0, 0) -- maximize
Display_width, Display_height, App.screen.flags = App.screen.size()
App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
App.screen.resize(0, 0) -- maximize
Display_width, Display_height, App.screen.flags = App.screen.size()
App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
Settings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position()
Settings.source.x, Settings.source.y, Settings.source.displayindex = App.screen.position()
end
local filename = Editor_state.filename
end
function source.resize(w, h)
--? print(("Window resized to width: %d and height: %d."):format(w, h))
App.screen.width, App.screen.height = w, h
Text.redraw_all(Editor_state)
Editor_state.selection1 = {} -- no support for shift drag while we're resizing
if Show_log_browser_side then
Editor_state.right = App.screen.width/2 - Margin_right
else
Editor_state.right = App.screen.width-Margin_right
end
Log_browser_state.left = App.screen.width/2 + Margin_right
Log_browser_state.right = App.screen.width-Margin_right
Editor_state.width = Editor_state.right-Editor_state.left
Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right)
--? print('end resize')
end
function source.filedropped(file)
-- first make sure to save edits on any existing file
if Editor_state.next_save then
save_to_disk(Editor_state)
end
-- clear the slate for the new file
Editor_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}
print('initializing source position')
if Settings == nil then Settings = {} end
if Settings.source == nil then Settings.source = {} end
-- shrink height slightly to account for window decoration
App.screen.height = Display_height-100
App.screen.width = 40*em_width
App.screen.flags.resizable = true
App.screen.flags.minwidth = math.min(App.screen.width, 200)
App.screen.flags.minheight = math.min(App.screen.width, 200)
--? 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_side
local right = App.screen.width - Margin_right
if Show_log_browser_side then
right = App.screen.width/2 - Margin_right
end
Editor_state = edit.initialize_state(Margin_top, Margin_left, right, settings.font_height, math.floor(settings.font_height*1.3))
Editor_state.filename = settings.filename
Editor_state.screen_top1 = settings.screen_top
Editor_state.cursor1 = settings.cursor
end
function 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)
end
function source.initialize_default_settings()
local font_height = 20
love.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_height
Editor_state.line_height = math.floor(font_height*1.3)
Editor_state.em = em
end
function source.initialize_window_geometry(em_width)
-- maximize window
-- set up desired window dimensions
App.screen.flags.resizable = true
App.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 changes
Text_cache = {}
-- blinking cursor
Cursor_time = 0
end
-- called only for real run
function source.initialize()
love.keyboard.setTextInput(true) -- bring up keyboard on touch screen
love.keyboard.setKeyRepeat(true)
love.graphics.setBackgroundColor(1,1,1)
if Settings and Settings.source then
source.load_settings()
else
source.initialize_default_settings()
end
source.initialize_edit_side{'run.lua'}
source.initialize_log_browser_side()
Menu_status_bar_height = 5 + Editor_state.line_height + 5
Editor_state.top = Editor_state.top + Menu_status_bar_height
Log_browser_state.top = Log_browser_state.top + Menu_status_bar_height
end
function test_show_log_browser_side()
io.write('\ntest_show_log_browser_side')
App.screen.init{width=300, height=300}
Display_width = App.screen.width
Current_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 side
App.wait_fake_time(0.1)
App.run_after_keychord('C-l')
check(Show_log_browser_side, 'F - test_show_log_browser_side')
end
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 width
App.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_left
Editor_state.right = App.screen.width - Margin_right
local old_editor_right = Editor_state.right
Text.redraw_all(Editor_state)
Log_browser_state = edit.initialize_test_state()
-- log browser has some arbitrary margins
Log_browser_state.left = 200 + Margin_left
Log_browser_state.right = 400
Text.redraw_all(Log_browser_state)
log_browser.parse(Log_browser_state)
-- display log browser
App.wait_fake_time(0.1)
App.run_after_keychord('C-l')
-- window width is doubled
check_eq(App.screen.width, 600, 'F - test_show_log_browser_side_doubles_window_width_if_possible/display:width')
-- left side margins are unchanged
check_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 adjusted
check_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')
end
function 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 maximized
App.screen.init{width=300, height=300}
Display_width = 300
-- initialize source app with left side occupying more than half the display
Current_app = 'source'
Editor_state = edit.initialize_test_state()
Editor_state.filename = 'foo'
Editor_state.left = Margin_left
Editor_state.right = 200
Text.redraw_all(Editor_state)
Log_browser_state = edit.initialize_test_state()
-- log browser has some arbitrary margins
Log_browser_state.left = 200 + Margin_left
Log_browser_state.right = 400
Text.redraw_all(Log_browser_state)
log_browser.parse(Log_browser_state)
-- display log browser
App.wait_fake_time(0.1)
App.run_after_keychord('C-l')
-- margins are now adjusted
check_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_right
Log_browser_state.left = App.screen.width/2 + Margin_left
Log_browser_state.right = App.screen.width - Margin_right