refactor editor-related code

This will make it easier to handle 'nb edit'