import * as vscode from "vscode" ; import { overtypeBeforePaste , overtypeBeforeType } from "./behavior" ; import { configuration , reloadConfiguration } from "./configuration" ; import { getMode , resetModes , toggleMode } from "./mode" ; import { createStatusBarItem , destroyStatusBarItem , updateStatusBarItem } from "./statusBarItem" ; export function activate ( context ) { const statusBarItem = createStatusBarItem ( ) ; activeTextEditorChanged ( ) ; context . subscriptions . push ( vscode . commands . registerCommand ( "overtype.toggle" , toggleCommand ) , vscode . commands . registerCommand ( "type" , typeCommand ) , vscode . commands . registerCommand ( "paste" , pasteCommand ) , vscode . window . onDidChangeActiveTextEditor ( activeTextEditorChanged ) , vscode . workspace . onDidChangeConfiguration ( onDidChangeConfiguration ) , statusBarItem ) ; } export function deactivate ( ) { destroyStatusBarItem ( ) ; } function activeTextEditorChanged ( textEditor ? ) { if ( textEditor === undefined ) { textEditor = vscode . window . activeTextEditor ; } if ( textEditor == null ) { updateStatusBarItem ( null ) ; } else { const mode = getMode ( textEditor ) ; updateStatusBarItem ( mode ) ; textEditor . options . cursorStyle = mode ? vscode . TextEditorCursorStyle . Block : configuration . defaultCursorStyle ; } } function toggleCommand ( ) { const textEditor = vscode . window . activeTextEditor ; if ( textEditor == null ) { return ; } toggleMode ( textEditor ) ; activeTextEditorChanged ( textEditor ) ; } function onDidChangeConfiguration ( ) { const previousPerEditor = configuration . perEditor ; const updated = reloadConfiguration ( ) ; if ( updated && configuration . perEditor !== previousPerEditor ) { const textEditor = vscode . window . activeTextEditor ; const mode = textEditor != null ? getMode ( textEditor ) : null ; resetModes ( mode , configuration . perEditor ) ; } if ( updated ) { activeTextEditorChanged ( ) ; } } function shouldPerformOvertype ( ) { if ( ! vscode . window . activeTextEditor ) { return false ; } const editor = vscode . window . activeTextEditor ; const mode = getMode ( editor ) ; return mode ; } function typeCommand ( args ) { if ( shouldPerformOvertype ( ) ) { const editor = vscode . window . activeTextEditor ; overtypeBeforeType ( editor , args . text ) ; } return vscode . commands . executeCommand ( "default:type" , args ) ; } function pasteCommand ( args ) { if ( configuration . paste && shouldPerformOvertype ( ) ) { const editor = vscode . window . activeTextEditor ; overtypeBeforePaste ( editor , args . text , args . pasteOnNewLine ) ; } return vscode . commands . executeCommand ( "default:paste" , args ) ; }