Consider undo history size don't just set to 1

Need to consider if we've undone back to the start instead of just
setting 1 here
File menu won't get cut off & minor syntax tweaks

Remove unused vars & whitespace
File manager menu won't get cut off if we trigger it near bottom of
screen. Now works out height of it and takes that into account so the
bottom sits 5px from the window.innerHeight bottom
Redo working out chPos in a more logical way
Tidy up formatting etc and add comments
Only run file.replace once, set in var