import * as vscode from 'vscode' ; import { Configuration } from '../util/configuration' ; import * as util from './util' ; export async function setContext ( ) { if ( Configuration . getTableEditorDisabled ( ) ) { return ; } const editor = vscode . window . activeTextEditor ; if ( editor ) { vscode . commands . executeCommand ( 'setContext' , 'resttext.editor.opening' , true ) ; } else { vscode . commands . executeCommand ( 'setContext' , 'resttext.editor.opening' , false ) ; return ; } const tableSizeIsSelected = util . tableSizeIsSelected ( editor ) ; if ( tableSizeIsSelected ) { vscode . commands . executeCommand ( 'setContext' , 'resttext.createGrid.enabled' , true ) ; } else { vscode . commands . executeCommand ( 'setContext' , 'resttext.createGrid.enabled' , false ) ; } const tableIsSelected = util . tableIsSelected ( editor ) ; const listIsSelected = util . listIsSelected ( editor ) ; const listExistsOneLineAbove = util . listExistsOneLineAbove ( editor ) ; if ( tableIsSelected ) { vscode . commands . executeCommand ( 'setContext' , 'resttext.enter.enabled' , true ) ; vscode . commands . executeCommand ( 'setContext' , 'resttext.shift.enter.enabled' , true ) ; } else { vscode . commands . executeCommand ( 'setContext' , 'resttext.enter.enabled' , false ) ; vscode . commands . executeCommand ( 'setContext' , 'resttext.shift.enter.enabled' , false ) ; } const selectedLastChara = util . isSelectingLastChara ( ) ; if ( tableIsSelected && ! selectedLastChara ) { vscode . commands . executeCommand ( 'setContext' , 'resttext.alt.enter.enabled' , true ) ; } else { vscode . commands . executeCommand ( 'setContext' , 'resttext.alt.enter.enabled' , false ) ; } if ( tableIsSelected || listExistsOneLineAbove ) { vscode . commands . executeCommand ( 'setContext' , 'resttext.tab.enabled' , true ) ; } else { vscode . commands . executeCommand ( 'setContext' , 'resttext.tab.enabled' , false ) ; } if ( tableIsSelected ) { vscode . commands . executeCommand ( 'setContext' , 'resttext.shift.tab.enabled' , true ) ; } else { vscode . commands . executeCommand ( 'setContext' , 'resttext.shift.tab.enabled' , false ) ; } }