@@ -1455,39 +1455,33 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
1455
1455
} ) ,
1456
1456
vscode . window . onDidChangeActiveTextEditor ( async ( textEditor : vscode . TextEditor ) => {
1457
1457
if ( ! textEditor ) return ;
1458
- posPanel . text = "" ;
1459
1458
await checkConnection ( false , textEditor . document . uri ) ;
1460
1459
if ( textEditor . document . uri . path . toLowerCase ( ) . endsWith ( ".xml" ) && config ( "autoPreviewXML" ) ) {
1461
1460
return previewXMLAsUDL ( textEditor , true ) ;
1462
1461
}
1463
1462
} ) ,
1464
- vscode . window . onDidChangeTextEditorSelection ( ( event : vscode . TextEditorSelectionChangeEvent ) => {
1463
+ vscode . window . onDidChangeTextEditorSelection ( async ( event : vscode . TextEditorSelectionChangeEvent ) => {
1465
1464
const document = event . textEditor . document ;
1466
-
1467
- // Avoid losing position indicator if event came from output channel
1468
- if ( document . uri . scheme == "output" ) {
1469
- return ;
1470
- }
1471
- posPanel . text = "" ;
1472
- if ( ! [ macLangId , intLangId ] . includes ( document . languageId ) ) {
1473
- return ;
1474
- }
1475
- if ( event . selections . length > 1 || ! event . selections [ 0 ] . isEmpty ) {
1476
- return ;
1477
- }
1478
-
1479
- const file = currentFile ( document ) ;
1480
- const nameMatch = file . name . match ( / ( .* ) \. ( i n t | m a c ) $ / i) ;
1481
- if ( ! nameMatch ) {
1482
- return ;
1483
- }
1484
- const [ , routine ] = nameMatch ;
1485
- let label = "" ;
1486
- let pos = 0 ;
1487
- vscode . commands
1488
- . executeCommand < vscode . DocumentSymbol [ ] > ( "vscode.executeDocumentSymbolProvider" , document . uri )
1489
- . then ( ( symbols ) => {
1490
- if ( symbols != undefined ) {
1465
+ // Avoid losing position indicator if event came from output channel or a non-active editor
1466
+ if ( document . uri . scheme == "output" || vscode . window . activeTextEditor != event . textEditor ) return ;
1467
+ try {
1468
+ if (
1469
+ ! [ macLangId , intLangId ] . includes ( document . languageId ) ||
1470
+ event . selections . length > 1 ||
1471
+ ! event . selections [ 0 ] . isEmpty
1472
+ ) {
1473
+ throw undefined ;
1474
+ }
1475
+ const file = currentFile ( document ) ;
1476
+ const nameMatch = file . name . match ( / ( .* ) \. ( i n t | m a c ) $ / i) ;
1477
+ if ( ! nameMatch ) throw undefined ;
1478
+ const [ , routine ] = nameMatch ;
1479
+ let label = "" ;
1480
+ let pos = 0 ;
1481
+ await vscode . commands
1482
+ . executeCommand < vscode . DocumentSymbol [ ] > ( "vscode.executeDocumentSymbolProvider" , document . uri )
1483
+ . then ( ( symbols ) => {
1484
+ if ( ! symbols ) throw undefined ;
1491
1485
const cursor = event . selections [ 0 ] . active ;
1492
1486
if ( symbols . length == 0 || cursor . isBefore ( symbols [ 0 ] . range . start ) ) {
1493
1487
pos = cursor . line - 1 ;
@@ -1501,8 +1495,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
1501
1495
}
1502
1496
}
1503
1497
posPanel . text = `${ label } ${ pos > 0 ? "+" + pos : "" } ^${ routine } ` ;
1504
- }
1505
- } ) ;
1498
+ } ) ;
1499
+ } catch {
1500
+ // If we couldn't resolve the cursor location to a label+offset^routine
1501
+ // for any reason, hide the status bar item
1502
+ posPanel . text = "" ;
1503
+ }
1506
1504
} ) ,
1507
1505
vscode . commands . registerCommand ( "vscode-objectscript.loadStudioSnippets" , loadStudioSnippets ) ,
1508
1506
vscode . commands . registerCommand ( "vscode-objectscript.loadStudioColors" , ( ) => {
0 commit comments