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