Use layout type variable to determine correct sidebar behaviour
More verbose comments, cleanup
On switch to 2-column view, populate editor if empty. On switch to 1-column view, open editor if needed.