set selected tab

This commit is contained in:
Matt Parker
2025-10-22 21:14:32 +10:00
parent aec76cc10e
commit 8e037a582d
4 changed files with 16 additions and 7 deletions

View File

@@ -34,13 +34,15 @@ public partial class CodeEditorPanel : MarginContainer
public override void _ExitTree()
{
var selectedTabIndex = _tabContainer.CurrentTab;
var thisSolution = Singletons.AppState.RecentSlns.Single(s => s.FilePath == Solution.FilePath);
thisSolution.IdeSolutionState.OpenTabs = _tabContainer.GetChildren().OfType<SharpIdeCodeEdit>()
.Select(t => new OpenTab
.Select((t, index) => new OpenTab
{
FilePath = t.SharpIdeFile.Path,
CaretLine = t.GetCaretLine(),
CaretColumn = t.GetCaretColumn()
CaretColumn = t.GetCaretColumn(),
IsSelected = index == selectedTabIndex
})
.ToList();
}
@@ -103,8 +105,7 @@ public partial class CodeEditorPanel : MarginContainer
}).AddTo(newTab); // needs to be on ui thread
});
await newTab.SetSharpIdeFile(file);
if (fileLinePosition is not null) await this.InvokeAsync(() => newTab.SetFileLinePosition(fileLinePosition.Value));
await newTab.SetSharpIdeFile(file, fileLinePosition);
}
private async Task OnDebuggerExecutionStopped(ExecutionStopInfo executionStopInfo)

View File

@@ -334,7 +334,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
}
// TODO: Ensure not running on UI thread
public async Task SetSharpIdeFile(SharpIdeFile file)
public async Task SetSharpIdeFile(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition = null)
{
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding); // get off the UI thread
_currentFile = file;
@@ -345,11 +345,13 @@ public partial class SharpIdeCodeEdit : CodeEdit
var razorSyntaxHighlighting = _roslynAnalysis.GetRazorDocumentSyntaxHighlighting(_currentFile);
var diagnostics = _roslynAnalysis.GetDocumentDiagnostics(_currentFile);
var projectDiagnosticsForFile = _roslynAnalysis.GetProjectDiagnosticsForFile(_currentFile);
await readFileTask;
var setTextTask = this.InvokeAsync(async () =>
{
_fileChangingSuppressBreakpointToggleEvent = true;
SetText(await readFileTask);
_fileChangingSuppressBreakpointToggleEvent = false;
if (fileLinePosition is not null) SetFileLinePosition(fileLinePosition.Value);
});
await Task.WhenAll(syntaxHighlighting, razorSyntaxHighlighting, setTextTask); // Text must be set before setting syntax highlighting
await this.InvokeAsync(async () => SetSyntaxHighlightingModel(await syntaxHighlighting, await razorSyntaxHighlighting));

View File

@@ -10,4 +10,5 @@ public class OpenTab
public required string FilePath { get; set; }
public required int CaretLine { get; set; }
public required int CaretColumn { get; set; }
public required bool IsSelected { get; set; }
}

View File

@@ -153,14 +153,19 @@ public partial class IdeRoot : Control
var previousTabs = Singletons.AppState.RecentSlns.Single(s => s.FilePath == solutionModel.FilePath).IdeSolutionState.OpenTabs;
var filesToOpen = previousTabs
.Select(s => (solutionModel.AllFiles.Single(f => f.Path == s.FilePath), new SharpIdeFileLinePosition(s.CaretLine, s.CaretColumn)))
.Select(s => (solutionModel.AllFiles.Single(f => f.Path == s.FilePath), new SharpIdeFileLinePosition(s.CaretLine, s.CaretColumn), s.IsSelected))
.ToList();
await this.InvokeDeferredAsync(async () =>
{
foreach (var (file, linePosition) in filesToOpen)
// Preserves order of tabs
foreach (var (file, linePosition, isSelected) in filesToOpen)
{
GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelFireAndForget(file, linePosition);
await Task.Delay(10).ConfigureAwait(false); // TODO: Do this properly - use InvokeParallelAsync, and fix FileExternallySelected waiting on syntax highlighting etc before returning
}
// Select the selected tab
var selectedFile = filesToOpen.SingleOrDefault(f => f.IsSelected);
if (selectedFile.Item1 is not null) GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelFireAndForget(selectedFile.Item1, selectedFile.Item2);
});
var tasks = solutionModel.AllProjects.Select(p => p.MsBuildEvaluationProjectTask).ToList();