import * as vscode from "vscode" ; import { configuration } from "./configuration" ; const defaultMode = false ; const state = { global : defaultMode , perEditor : new WeakMap < vscode . TextEditor , boolean > ( ) , } ; export function getMode ( textEditor ) { if ( ! configuration . perEditor ) { return state . global ; } if ( ! state . perEditor . has ( textEditor ) ) { state . perEditor . set ( textEditor , defaultMode ) ; } return < boolean > state . perEditor . get ( textEditor ) ; } export function toggleMode ( textEditor ) { let overtype = ! getMode ( textEditor ) ; if ( ! configuration . perEditor ) { state . global = overtype ; } else { state . perEditor . set ( textEditor , overtype ) ; } return overtype ; } export function resetModes ( mode , perEditor ) { if ( mode === null ) { mode = defaultMode ; } if ( perEditor ) { state . global = defaultMode ; state . perEditor = state . perEditor = new WeakMap < vscode . TextEditor , boolean > ( ) ; } else { state . global = mode ; state . perEditor = state . perEditor = new WeakMap < vscode . TextEditor , boolean > ( ) ; } }