Refactor editor logic