public Document UpdateDocument(Document document, IEnumerable <TextChange> changes) { var newText = document.SourceText.WithChanges(changes); OnDocumentTextChanged(document.Id, newText); return(CurrentDocuments.GetDocument(document.Id)); }
protected override void ApplyDocumentTextChanged(DocumentId id, SourceText text) { var currentDocumentBuffer = CurrentDocuments.GetDocument(id)?.SourceText.Container.GetTextBuffer(); if (currentDocumentBuffer == null) { return; } using (var edit = currentDocumentBuffer.CreateEdit(EditOptions.DefaultMinimalChange, reiteratedVersionNumber: null, editTag: null)) { var oldSnapshot = currentDocumentBuffer.CurrentSnapshot; var oldText = oldSnapshot.AsText(); var changes = text.GetTextChanges(oldText); //if (Workspace.TryGetWorkspace(oldText.Container, out var workspace)) //{ // var undoService = workspace.Services.GetService<ISourceTextUndoService>(); // undoService.BeginUndoTransaction(oldSnapshot); //} foreach (var change in changes) { edit.Replace(change.Span.Start, change.Span.Length, change.NewText); } edit.Apply(); } }
public override void OpenDocument(DocumentId documentId, bool activate = true) { if (documentId == null) { throw new ArgumentNullException(nameof(documentId)); } if (!_foregroundObject.Value.IsForeground()) { throw new InvalidOperationException("This workspace only supports opening documents on the UI thread."); } var document = CurrentDocuments.GetDocument(documentId); if (document == null) { return; } uint itemID; IVsUIHierarchy hierarchy; IVsWindowFrame docFrame; IVsTextView textView; try { VsShellUtilities.OpenDocument( _serviceProvider, document.FilePath, VSConstants.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView); } catch { // File might not exist, etc. return; } if (activate) { docFrame.Show(); } else { docFrame.ShowNoActivate(); } }
public Document GetDocument(Uri uri) { return(CurrentDocuments.GetDocumentWithFilePath(Helpers.FromUri(uri))); }