How to get an action button to circulate through live preview -> source -> reading view?

@tophee you can create a template with Templater and assign it to a hotkey or custom button to cycle all 3 modes:

<%*
// Cycle through the three workspace modes
const view = app.workspace.activeLeaf.getViewState()
if (view.state.mode === 'source' && view.state.source === true) {
	// In source mode, set to live preview
	view.state.source = false
} else if (view.state.mode === 'source') {
	// In live preview, set to reading mode
	view.state.mode = 'preview'
} else {
	// In reading mode, set to source mode
	view.state.mode = 'source'
	view.state.source = true
}
app.workspace.activeLeaf.setViewState(view)
app.workspace.activeLeaf.view.editor.focus()
%>
3 Likes