diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2017-03-27 19:40:09 +0300 |
---|---|---|
committer | Vsevolod Kukol <sevoku@microsoft.com> | 2017-03-27 19:40:09 +0300 |
commit | bcf0f49ff6994d1dc2d06d53a7518ae1ed35c571 (patch) | |
tree | 160c92b456601f6a46d3660eb2bdbb2c4290f93c /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor | |
parent | 0be22f7c0a199f9ffb185386eb85b620d0f37f58 (diff) | |
parent | 252dc8bac40ca46bf020351e331aa477763a020d (diff) |
Merge remote-tracking branch 'origin/master' into native-popups
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor')
13 files changed, 136 insertions, 76 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DefaultSourceEditorOptions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DefaultSourceEditorOptions.cs index 5f24903839..a1e23815a4 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DefaultSourceEditorOptions.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DefaultSourceEditorOptions.cs @@ -343,7 +343,7 @@ namespace MonoDevelop.Ide.Editor } } - ConfigurationProperty<bool> autoInsertMatchingBracket = ConfigurationProperty.Create ("AutoInsertMatchingBracket", false); + ConfigurationProperty<bool> autoInsertMatchingBracket = ConfigurationProperty.Create ("AutoInsertMatchingBracket", true); public bool AutoInsertMatchingBracket { get { return autoInsertMatchingBracket; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentContext.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentContext.cs index d3208cdac0..9816754b10 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentContext.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/DocumentContext.cs @@ -67,6 +67,17 @@ namespace MonoDevelop.Ide.Editor get; } + + /// <summary> + /// Determine if the file has already saved on disk. Untitled files are open + /// in the IDE only. After the first save the file is no longer untitled. + /// </summary> + public virtual bool IsUntitled { + get { + return false; + } + } + WorkspaceId workspaceId = WorkspaceId.Empty; public virtual T GetPolicy<T> (IEnumerable<string> types) where T : class, IEquatable<T>, new () diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/ITextDocument.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/ITextDocument.cs index b2ed856224..96f9bc284b 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/ITextDocument.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/ITextDocument.cs @@ -28,6 +28,7 @@ using System; using MonoDevelop.Core.Text; using System.Text; using MonoDevelop.Core; +using System.Collections.Generic; namespace MonoDevelop.Ide.Editor { @@ -54,8 +55,6 @@ namespace MonoDevelop.Ide.Editor new string MimeType { get; set; } - new bool UseBOM { get; set; } - new Encoding Encoding { get; set; } void InsertText (int offset, string text); @@ -68,6 +67,8 @@ namespace MonoDevelop.Ide.Editor void ReplaceText (int offset, int length, ITextSource value); + void ApplyTextChanges (IEnumerable<Microsoft.CodeAnalysis.Text.TextChange> changes); + bool IsInAtomicUndo { get; } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextEditorFactory.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextEditorFactory.cs index 4b88445dab..00af3934e6 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextEditorFactory.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextEditorFactory.cs @@ -30,14 +30,16 @@ namespace MonoDevelop.Ide.Editor { interface ITextEditorFactory { - ITextDocument CreateNewDocument (); - ITextDocument CreateNewDocument (ITextSource textSource, string fileName, string mimeType); - + ITextDocument CreateNewDocument ();
+ ITextDocument CreateNewDocument (string fileName, string mimeType);
+ ITextDocument CreateNewDocument (ITextSource textSource, string fileName, string mimeType);
+
IReadonlyTextDocument CreateNewReadonlyDocument (ITextSource textSource, string fileName, string mimeType); - ITextEditorImpl CreateNewEditor (); - ITextEditorImpl CreateNewEditor (IReadonlyTextDocument document); - + ITextEditorImpl CreateNewEditor ();
+ ITextEditorImpl CreateNewEditor (string fileName, string mimeType);
+ ITextEditorImpl CreateNewEditor (IReadonlyTextDocument document);
+
string[] GetSyntaxProperties (string mimeType, string name); } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextMarkerFactory.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextMarkerFactory.cs index 68f0ac8651..95900bc1d4 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextMarkerFactory.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/InternalExtensionAPI/ITextMarkerFactory.cs @@ -39,7 +39,7 @@ namespace MonoDevelop.Ide.Editor interface ITextMarkerFactory { #region Line marker - IUrlTextLineMarker CreateUrlTextMarker (TextEditor editor, IDocumentLine line, string value, UrlType url, string syntax, int startCol, int endCol); + IUrlTextLineMarker CreateUrlTextMarker (TextEditor editor, string value, UrlType url, string syntax, int startCol, int endCol); ICurrentDebugLineTextMarker CreateCurrentDebugLineTextMarker (TextEditor editor, int offset, int length); ITextLineMarker CreateAsmLineMarker (TextEditor editor); IUnitTestMarker CreateUnitTestMarker (TextEditor editor, UnitTestMarkerHost host, UnitTestLocation unitTestLocation); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedDocumentContext.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedDocumentContext.cs index b188468734..b2fa634440 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedDocumentContext.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/ProjectedDocumentContext.cs @@ -52,6 +52,12 @@ namespace MonoDevelop.Ide.Editor.Projection } } + public override bool IsUntitled { + get { + return originalContext.IsUntitled; + } + } + Microsoft.CodeAnalysis.Document projectedDocument; public ProjectedDocumentContext (TextEditor projectedEditor, DocumentContext originalContext) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/Projection.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/Projection.cs index b1a17b8064..a68ca66352 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/Projection.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/Projection/Projection.cs @@ -117,10 +117,12 @@ namespace MonoDevelop.Ide.Editor.Projection void HandleTextChanging (object sender, TextChangeEventArgs e) { - foreach (var segment in originalProjections) { - if (segment.Contains (e.Offset)) { - var projectedOffset = e.Offset - segment.Offset + segment.LinkedTo.Offset; - projectedEditor.ReplaceText (projectedOffset, e.RemovalLength, e.InsertedText); + foreach (var change in e.TextChanges) { + foreach (var segment in originalProjections) { + if (segment.Contains (change.Offset)) { + var projectedOffset = change.Offset - segment.Offset + segment.LinkedTo.Offset; + projectedEditor.ReplaceText (projectedOffset, change.RemovalLength, change.InsertedText); + } } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/SegmentTree.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/SegmentTree.cs index 6c23884dcd..6819994773 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/SegmentTree.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/SegmentTree.cs @@ -169,43 +169,45 @@ namespace MonoDevelop.Ide.Editor internal void UpdateOnTextReplace (object sender, TextChangeEventArgs e) { - if (e.RemovalLength == 0) { - var length = e.InsertionLength; - foreach (var segment in GetSegmentsAt (e.Offset).Where (s => s.Offset < e.Offset && e.Offset < s.EndOffset)) { - segment.Length += length; - segment.UpdateAugmentedData (); - } - var node = SearchFirstSegmentWithStartAfter (e.Offset); - if (node != null) { - node.DistanceToPrevNode += length; - node.UpdateAugmentedData (); - } - return; - } - int delta = e.ChangeDelta; - foreach (var segment in new List<T> (GetSegmentsOverlapping (e.Offset, e.RemovalLength))) { - if (segment.Offset < e.Offset) { - if (segment.EndOffset >= e.Offset + e.RemovalLength) { - segment.Length += delta; - } else { - segment.Length = e.Offset - segment.Offset; + foreach (var change in e.TextChanges) { + if (change.RemovalLength == 0) { + var length = change.InsertionLength; + foreach (var segment in GetSegmentsAt (change.Offset).Where (s => s.Offset < change.Offset && change.Offset < s.EndOffset)) { + segment.Length += length; + segment.UpdateAugmentedData (); + } + var node = SearchFirstSegmentWithStartAfter (change.Offset); + if (node != null) { + node.DistanceToPrevNode += length; + node.UpdateAugmentedData (); } - segment.UpdateAugmentedData (); continue; } - int remainingLength = segment.EndOffset - (e.Offset + e.RemovalLength); - InternalRemove (segment); - if (remainingLength > 0) { - segment.Offset = e.Offset + e.RemovalLength; - segment.Length = remainingLength; - InternalAdd (segment); + int delta = change.ChangeDelta; + foreach (var segment in new List<T> (GetSegmentsOverlapping (change.Offset, change.RemovalLength))) { + if (segment.Offset < change.Offset) { + if (segment.EndOffset >= change.Offset + change.RemovalLength) { + segment.Length += delta; + } else { + segment.Length = change.Offset - segment.Offset; + } + segment.UpdateAugmentedData (); + continue; + } + int remainingLength = segment.EndOffset - (change.Offset + change.RemovalLength); + InternalRemove (segment); + if (remainingLength > 0) { + segment.Offset = change.Offset + change.RemovalLength; + segment.Length = remainingLength; + InternalAdd (segment); + } } - } - var next = SearchFirstSegmentWithStartAfter (e.Offset + 1); + var next = SearchFirstSegmentWithStartAfter (change.Offset + 1); - if (next != null) { - next.DistanceToPrevNode += delta; - next.UpdateAugmentedData (); + if (next != null) { + next.DistanceToPrevNode += delta; + next.UpdateAugmentedData (); + } } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditor.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditor.cs index c1dc85c09b..f87f00d1b6 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditor.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditor.cs @@ -366,16 +366,6 @@ namespace MonoDevelop.Ide.Editor } } - public bool UseBOM { - get { - return ReadOnlyTextDocument.UseBOM; - } - set { - Runtime.AssertMainThread (); - ReadWriteTextDocument.UseBOM = value; - } - } - public Encoding Encoding { get { return ReadOnlyTextDocument.Encoding; @@ -673,6 +663,17 @@ namespace MonoDevelop.Ide.Editor ReadWriteTextDocument.ReplaceText (segment.Offset, segment.Length, value); } + /// <summary> + /// Applies a batch of text changes. Note that the textchange offsets are always offsets in the current (old) document. + /// </summary> + public void ApplyTextChanges (IEnumerable<Microsoft.CodeAnalysis.Text.TextChange> changes) + { + if (changes == null) + throw new ArgumentNullException (nameof (changes)); + Runtime.AssertMainThread (); + ReadWriteTextDocument.ApplyTextChanges (changes); + } + public IDocumentLine GetLine (int lineNumber) { return ReadOnlyTextDocument.GetLine (lineNumber); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorDisplayBinding.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorDisplayBinding.cs index 15d839752b..ba49053020 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorDisplayBinding.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorDisplayBinding.cs @@ -94,12 +94,23 @@ namespace MonoDevelop.Ide.Editor } public ViewContent CreateContent (FilePath fileName, string mimeType, Project ownerProject) - { - var editor = TextEditorFactory.CreateNewEditor (); - editor.FileName = fileName; - editor.MimeType = mimeType; + {
+ TextEditor editor;
+
+ // HACK: this is a very poor test for whether to load the document. Maybe add an IsPlaceholder property to FilePath.
+ // Another alternative would be to add a parameter to CreateContent.
+ if (File.Exists(fileName))
+ {
+ editor = TextEditorFactory.CreateNewEditor(fileName, mimeType);
+ }
+ else
+ {
+ editor = TextEditorFactory.CreateNewEditor();
+ editor.FileName = fileName; + editor.MimeType = mimeType;
+ }
+
editor.GetViewContent ().Project = ownerProject; - editor.GetViewContent ().ContentName = fileName; return editor.GetViewContent (); } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorFactory.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorFactory.cs index 13b7d8c3f7..6025768667 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorFactory.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorFactory.cs @@ -49,8 +49,15 @@ namespace MonoDevelop.Ide.Editor public static ITextDocument CreateNewDocument () { return currentFactory.CreateNewDocument (); - } - + }
+
+ public static ITextDocument CreateNewDocument(string fileName, string mimeType = null)
+ {
+ if (fileName == null)
+ throw new System.ArgumentNullException(nameof(fileName));
+ return currentFactory.CreateNewDocument(fileName, mimeType);
+ }
+
public static ITextDocument CreateNewDocument (ITextSource textSource, string fileName, string mimeType = null) { if (textSource == null) @@ -72,17 +79,29 @@ namespace MonoDevelop.Ide.Editor return currentFactory.CreateNewDocument (textSource, fileName, mimeType); } - static ConfigurationProperty<double> zoomLevel = ConfigurationProperty.Create ("Editor.ZoomLevel", 1.0d); + static ConfigurationProperty<double> zoomLevel = ConfigurationProperty.Create ("Editor.ZoomLevel", 1.0d);
+
+ public static TextEditor CreateNewEditor(string fileName, string mimeType, TextEditorType textEditorType = TextEditorType.Default)
+ {
+ var result = new TextEditor(currentFactory.CreateNewEditor(fileName, mimeType), textEditorType);
+ InitializeTextEditor(result);
+ return result;
+ }
+
+ public static TextEditor CreateNewEditor(TextEditorType textEditorType = TextEditorType.Default)
+ {
+ var result = new TextEditor(currentFactory.CreateNewEditor(), textEditorType);
+ InitializeTextEditor(result);
+ return result;
+ }
+
+ private static void InitializeTextEditor(TextEditor textEditor) + {
+ textEditor.ZoomLevel = zoomLevel; - public static TextEditor CreateNewEditor (TextEditorType textEditorType = TextEditorType.Default) - { - var result = new TextEditor (currentFactory.CreateNewEditor (), textEditorType) { - ZoomLevel = zoomLevel + textEditor.ZoomLevelChanged += delegate { + zoomLevel.Value = textEditor.ZoomLevel; }; - result.ZoomLevelChanged += delegate { - zoomLevel.Value = result.ZoomLevel; - }; - return result; } public static TextEditor CreateNewEditor (IReadonlyTextDocument document, TextEditorType textEditorType = TextEditorType.Default) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorViewContent.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorViewContent.cs index 2c8b188bba..b5dcfb110f 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorViewContent.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextEditorViewContent.cs @@ -223,7 +223,6 @@ namespace MonoDevelop.Ide.Editor var res = await TextFileUtility.GetTextAsync (content); text = textEditor.Text = res.Text; textEditor.Encoding = res.Encoding; - textEditor.UseBOM = res.HasBom; } await RunFirstTimeFoldUpdate (text); textEditorImpl.InformLoadComplete (); @@ -308,6 +307,12 @@ namespace MonoDevelop.Ide.Editor } } + public override string TabAccessibilityDescription { + get { + return textEditorImpl.ViewContent.TabAccessibilityDescription; + } + } + public override bool IsDirty { get { return textEditorImpl.ViewContent.IsDirty; } set { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextMarkerFactory.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextMarkerFactory.cs index 0a1530f5a1..7c3b21ac14 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextMarkerFactory.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor/TextMarkerFactory.cs @@ -37,9 +37,9 @@ namespace MonoDevelop.Ide.Editor public static class TextMarkerFactory { #region Line marker - public static IUrlTextLineMarker CreateUrlTextMarker (TextEditor editor, IDocumentLine line, string value, UrlType url, string syntax, int startCol, int endCol) + public static IUrlTextLineMarker CreateUrlTextMarker (TextEditor editor, string value, UrlType url, string syntax, int startCol, int endCol) { - return editor.TextMarkerFactory.CreateUrlTextMarker (editor, line, value, url, syntax, startCol, endCol); + return editor.TextMarkerFactory.CreateUrlTextMarker (editor, value, url, syntax, startCol, endCol); } public static ICurrentDebugLineTextMarker CreateCurrentDebugLineTextMarker (TextEditor editor, int offset, int length) @@ -115,7 +115,7 @@ namespace MonoDevelop.Ide.Editor endOffset++; } if (endOffset == offset + 1) { - if (endOffset - 1 < editor.Length) { + if (endOffset > 0 && endOffset - 1 < editor.Length) { var c = editor.GetCharAt (endOffset - 1); while ((c == '\n' || c == '\r') && endOffset < editor.Length) { c = editor.GetCharAt (endOffset); |