How to get the 'live preview' status within the TypeScript code for plugin development

I want to write a feature in the code that allows one-click switching between three modes: “source mode”, “reading view”, and “live preview”. I know I can determine ‘export type MarkdownViewModeType = ‘source’ | ‘preview’;’ through ‘this.app.workspace.getActiveViewOfType(MarkdownView).getMode()’, but I haven’t found how to determine “live preview”.

Given view is a MarkdownView, view.getState() gives you that information.

  • { mode: "preview", ... }: reading view
  • { mode: "source", source: false, ... }: live preview
  • { mode: "source", source: true, ... }: source mode

For changing the state, use view.setState.