Markdown files: Fix switching between 'code' and 'formatted' views
Created by: umpox
Feedback from user: https://sourcegraph.slack.com/archives/C0W2E592M/p1632997733328500
Fixes a bug where it was not possible to switch back to 'formatted' mode on Markdown files if a line range had been selected.
Also cleaned up the code a little and added some tests