Skip to content

Commit f57db49

Browse files
committed
Fix routine location status bar item flickering
1 parent 752e434 commit f57db49

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

src/extension.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,39 +1440,33 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
14401440
}),
14411441
vscode.window.onDidChangeActiveTextEditor(async (textEditor: vscode.TextEditor) => {
14421442
if (!textEditor) return;
1443-
posPanel.text = "";
14441443
await checkConnection(false, textEditor.document.uri);
14451444
if (textEditor.document.uri.path.toLowerCase().endsWith(".xml") && config("autoPreviewXML")) {
14461445
return previewXMLAsUDL(textEditor, true);
14471446
}
14481447
}),
1449-
vscode.window.onDidChangeTextEditorSelection((event: vscode.TextEditorSelectionChangeEvent) => {
1448+
vscode.window.onDidChangeTextEditorSelection(async (event: vscode.TextEditorSelectionChangeEvent) => {
14501449
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(/(.*)\.(int|mac)$/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(/(.*)\.(int|mac)$/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;
14761470
const cursor = event.selections[0].active;
14771471
if (symbols.length == 0 || cursor.isBefore(symbols[0].range.start)) {
14781472
pos = cursor.line - 1;
@@ -1486,8 +1480,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
14861480
}
14871481
}
14881482
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+
}
14911489
}),
14921490
vscode.commands.registerCommand("vscode-objectscript.loadStudioSnippets", loadStudioSnippets),
14931491
vscode.commands.registerCommand("vscode-objectscript.loadStudioColors", () => {

0 commit comments

Comments
 (0)