Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs')
-rw-r--r--main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs54
1 files changed, 44 insertions, 10 deletions
diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
index a9c9e75adc..599ba88014 100644
--- a/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
+++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
@@ -95,7 +95,7 @@ namespace Mono.TextEditor
/// </summary>
public event EventHandler<EditModeChangedEventArgs> EditModeChanged;
- public TextEditor Parent {
+ public MonoTextEditor Parent {
get;
set;
}
@@ -207,24 +207,28 @@ namespace Mono.TextEditor
caret.PositionChanged += CaretPositionChanged;
options = TextEditorOptions.DefaultOptions;
-
document = doc;
+ AttachDocument ();
+ SearchEngine = new BasicSearchEngine ();
+
+ HeightTree = new HeightTree (this);
+ HeightTree.Rebuild ();
+ IndentationTracker = new DefaultIndentationTracker (document);
+ }
+
+ void AttachDocument ()
+ {
+ if (document == null)
+ return;
document.BeginUndo += OnBeginUndo;
document.EndUndo += OnEndUndo;
-
document.Undone += DocumentHandleUndone;
document.Redone += DocumentHandleRedone;
document.LineChanged += HandleDocLineChanged;
document.TextReplaced += HandleTextReplaced;
-
document.TextSet += HandleDocTextSet;
document.Folded += HandleTextEditorDataDocumentFolded;
document.FoldTreeUpdated += HandleFoldTreeUpdated;
- SearchEngine = new BasicSearchEngine ();
-
- HeightTree = new HeightTree (this);
- HeightTree.Rebuild ();
- IndentationTracker = new DefaultIndentationTracker (document);
}
void HandleFoldTreeUpdated (object sender, EventArgs e)
@@ -267,6 +271,12 @@ namespace Mono.TextEditor
get {
return document;
}
+ set {
+ DetachDocument ();
+ document = value;
+ this.caret.SetDocument (document);
+ AttachDocument ();
+ }
}
void HandleTextReplaced (object sender, DocumentChangeEventArgs e)
@@ -805,6 +815,26 @@ namespace Mono.TextEditor
}
}
+ public int SelectionLead {
+ get {
+ if (MainSelection.IsEmpty)
+ return -1;
+ return MainSelection.GetLeadOffset (this);
+ }
+ set {
+ DocumentLocation location = Document.OffsetToLocation (value);
+ if (mainSelection.IsEmpty) {
+ MainSelection = new Selection (location, location);
+ } else {
+ if (MainSelection.Anchor == location) {
+ MainSelection = MainSelection.WithAnchor (MainSelection.Lead);
+ } else {
+ MainSelection = MainSelection.WithLead (location);
+ }
+ }
+ }
+ }
+
/// <summary>
/// Gets or sets the selection range. If nothing is selected (Caret.Offset, 0) is returned.
/// </summary>
@@ -888,6 +918,10 @@ namespace Mono.TextEditor
public void SetSelection (int anchorOffset, int leadOffset)
{
+ if (anchorOffset == leadOffset) {
+ MainSelection = Selection.Empty;
+ return;
+ }
var anchor = document.OffsetToLocation (anchorOffset);
var lead = document.OffsetToLocation (leadOffset);
MainSelection = new Selection (anchor, lead);
@@ -895,7 +929,7 @@ namespace Mono.TextEditor
public void SetSelection (DocumentLocation anchor, DocumentLocation lead)
{
- MainSelection = new Selection (anchor, lead);
+ MainSelection = anchor == lead ? Selection.Empty : new Selection (anchor, lead);
}
public void SetSelection (int anchorLine, int anchorColumn, int leadLine, int leadColumn)