本文整理汇总了C#中Mono.TextEditor.TextEditorData.OpenUndoGroup方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditorData.OpenUndoGroup方法的具体用法?C# TextEditorData.OpenUndoGroup怎么用?C# TextEditorData.OpenUndoGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.TextEditor.TextEditorData
的用法示例。
在下文中一共展示了TextEditorData.OpenUndoGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Left
public static void Left (TextEditorData data)
{
using (var undo = data.OpenUndoGroup ()) {
if (Platform.IsMac && data.IsSomethingSelected && !data.Caret.PreserveSelection) {
data.Caret.Offset = System.Math.Min (data.SelectionAnchor, data.Caret.Offset);
data.ClearSelection ();
return;
}
if (data.Caret.Column > DocumentLocation.MinColumn) {
DocumentLine line = data.Document.GetLine (data.Caret.Line);
if (data.Caret.Column > line.Length + 1) {
if (data.Caret.AllowCaretBehindLineEnd) {
data.Caret.Column--;
} else {
data.Caret.Column = line.Length + 1;
}
} else {
int offset = data.Caret.Offset - 1;
foreach (var folding in data.Document.GetFoldingsFromOffset (offset).Where (f => f.IsFolded && f.Offset < offset)) {
offset = System.Math.Min (offset, folding.Offset);
}
data.Caret.Offset = offset;
}
} else if (data.Caret.Line > DocumentLocation.MinLine) {
DocumentLine prevLine = data.Document.GetLine (data.Caret.Line - 1);
var nextLocation = new DocumentLocation (data.Caret.Line - 1, prevLine.Length + 1);
if (data.HasIndentationTracker && data.Options.IndentStyle == IndentStyle.Virtual && nextLocation.Column == DocumentLocation.MinColumn)
nextLocation = new DocumentLocation (data.Caret.Line - 1, data.GetVirtualIndentationColumn (nextLocation));
data.Caret.Location = nextLocation;
}
}
}
示例2: RemoveTabInLine
public static int RemoveTabInLine (TextEditorData data, DocumentLine line)
{
if (line.LengthIncludingDelimiter == 0)
return 0;
using (var undoGroup = data.OpenUndoGroup ()) {
char ch = data.Document.GetCharAt (line.Offset);
if (ch == '\t') {
data.Remove (line.Offset, 1);
data.Document.CommitLineUpdate (line);
return 1;
} else if (ch == ' ') {
int removeCount = 0;
for (int i = 0; i < data.Options.IndentationSize;) {
ch = data.Document.GetCharAt (line.Offset + i);
if (ch == ' ') {
removeCount++;
i++;
} else if (ch == '\t') {
removeCount++;
i += data.Options.TabSize;
} else {
break;
}
}
data.Remove (line.Offset, removeCount);
data.Document.CommitLineUpdate (line);
return removeCount;
}
}
return 0;
}
示例3: NextWord
static void NextWord (TextEditorData data, bool subword)
{
using (var undo = data.OpenUndoGroup ()) {
int oldLine = data.Caret.Line;
int caretOffset = data.Caret.Offset;
int offset = subword ? data.FindNextSubwordOffset (caretOffset) : data.FindNextWordOffset (caretOffset);
if (caretOffset != offset && data.CanEdit (oldLine) && data.CanEdit (data.Caret.Line)) {
data.Remove (caretOffset, offset - caretOffset);
}
}
}
示例4: GotoMatchingBracket
public static void GotoMatchingBracket (TextEditorData data)
{
using (var undoGroup = data.OpenUndoGroup ()) {
int matchingBracketOffset = data.Document.GetMatchingBracketOffset (data.Caret.Offset);
if (matchingBracketOffset == -1 && data.Caret.Offset > 0)
matchingBracketOffset = data.Document.GetMatchingBracketOffset (data.Caret.Offset - 1);
if (matchingBracketOffset != -1)
data.Caret.Offset = matchingBracketOffset;
}
}
示例5: Select
public static void Select (TextEditorData data, Action<TextEditorData> caretMoveAction)
{
using (var undoGroup = data.OpenUndoGroup ()) {
PositionChangedHandler handler = new PositionChangedHandler (data);
data.Caret.PositionChanged += handler.DataCaretPositionChanged;
StartSelection (data);
caretMoveAction (data);
data.Caret.PositionChanged -= handler.DataCaretPositionChanged;
data.Caret.AutoScrollToCaret = true;
data.Caret.PreserveSelection = false;
}
}
示例6: Insert
public void Insert (TextEditorData editor, string text)
{
int offset = editor.Document.LocationToOffset (Location);
using (var undo = editor.OpenUndoGroup ()) {
text = editor.FormatString (Location, text);
LineSegment line = editor.Document.GetLineByOffset (offset);
int insertionOffset = line.Offset + Location.Column - 1;
offset = insertionOffset;
InsertNewLine (editor, LineBefore, ref offset);
offset += editor.Insert (offset, text);
InsertNewLine (editor, LineAfter, ref offset);
}
}
示例7: Left
public static void Left(TextEditorData editor)
{
if (!Platform.IsMac)
{
if (DocumentLocation.MinColumn < editor.Caret.Column)
CaretMoveActions.Left(editor);
}
else
{
using (var undo = editor.OpenUndoGroup())
{
if (editor.Caret.Column > DocumentLocation.MinColumn)
editor.Caret.Column = editor.Caret.Column - 1;
}
}
}
示例8: Up
public static void Up(TextEditorData editor)
{
if (!Platform.IsMac)
CaretMoveActions.Up(editor);
else
{
using (var undo = editor.OpenUndoGroup())
{
if (editor.Caret.Line > DocumentLocation.MinLine)
{
int visualLine = editor.LogicalToVisualLine(editor.Caret.Line);
int line = editor.VisualToLogicalLine(visualLine - 1);
editor.Caret.Line = line;
}
}
}
}
示例9: Down
public static void Down(TextEditorData editor)
{
if (!Platform.IsMac)
CaretMoveActions.Down(editor);
else
{
using (var undo = editor.OpenUndoGroup())
{
if (editor.Caret.Line < editor.Document.LineCount)
{
int nextLine = editor.LogicalToVisualLine(editor.Caret.Line);
int line = editor.VisualToLogicalLine(nextLine + 1);
editor.Caret.Line = line;
}
}
}
}
示例10: RemoveIndentSelection
public static void RemoveIndentSelection (TextEditorData data)
{
if (!data.IsSomethingSelected)
return;
int startLineNr, endLineNr;
GetSelectedLines (data, out startLineNr, out endLineNr);
using (var undo = data.OpenUndoGroup (OperationType.Format)) {
var anchor = data.MainSelection.Anchor;
var lead = data.MainSelection.Lead;
bool first = true;
bool removedFromLast = false;
int removeLast = 0;
bool removedFromFirst = false;
int removeFirst = 0;
foreach (var line in data.SelectedLines) {
int remove = RemoveTabInLine (data, line);
removedFromLast |= remove > 0;
removeLast = remove;
if (first) {
removedFromFirst = remove > 0;
removeFirst = remove;
first = false;
}
}
var ac = System.Math.Max (DocumentLocation.MinColumn, anchor.Column - (anchor < lead ? removeFirst : removeLast));
var lc = System.Math.Max (DocumentLocation.MinColumn, lead.Column - (anchor < lead ? removeLast : removeFirst));
if (anchor < lead) {
if (!removedFromFirst)
ac = anchor.Column;
if (!removedFromLast)
lc = lead.Column;
} else {
if (!removedFromFirst)
lc = lead.Column;
if (!removedFromLast)
ac = anchor.Column;
}
data.SetSelection (anchor.Line, ac, lead.Line, lc);
}
data.Document.RequestUpdate (new MultipleLineUpdate (startLineNr, endLineNr));
data.Document.CommitDocumentUpdate ();
}
示例11: SetCompletionText
public static void SetCompletionText (TextEditorData data, CodeCompletionContext ctx, string partialWord, string completeWord, int wordOffset)
{
if (data == null || data.Document == null)
return;
int triggerOffset = ctx.TriggerOffset;
int length = String.IsNullOrEmpty (partialWord) ? 0 : partialWord.Length;
// for named arguments invoke(arg:<Expr>);
if (completeWord.EndsWith (":", StringComparison.Ordinal)) {
if (data.GetCharAt (triggerOffset + length) == ':')
length++;
}
bool blockMode = false;
if (data.IsSomethingSelected) {
blockMode = data.MainSelection.SelectionMode == Mono.TextEditor.SelectionMode.Block;
if (blockMode) {
data.Caret.PreserveSelection = true;
triggerOffset = data.Caret.Offset - length;
} else {
if (data.SelectionRange.Offset < ctx.TriggerOffset)
triggerOffset = ctx.TriggerOffset - data.SelectionRange.Length;
data.DeleteSelectedText ();
}
length = 0;
}
// | in the completion text now marks the caret position
int idx = completeWord.IndexOf ('|');
if (idx >= 0) {
completeWord = completeWord.Remove (idx, 1);
}
triggerOffset += data.EnsureCaretIsNotVirtual ();
if (blockMode) {
using (var undo = data.OpenUndoGroup ()) {
int minLine = data.MainSelection.MinLine;
int maxLine = data.MainSelection.MaxLine;
int column = triggerOffset - data.Document.GetLineByOffset (triggerOffset).Offset;
for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) {
DocumentLine lineSegment = data.Document.GetLine (lineNumber);
if (lineSegment == null)
continue;
int offset = lineSegment.Offset + column;
data.Replace (offset, length, completeWord);
}
int minColumn = Math.Min (data.MainSelection.Anchor.Column, data.MainSelection.Lead.Column);
data.MainSelection = data.MainSelection.WithRange (
new Mono.TextEditor.DocumentLocation (data.Caret.Line == minLine ? maxLine : minLine, minColumn),
data.Caret.Location
);
data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine);
data.Caret.PreserveSelection = false;
}
} else {
data.Replace (triggerOffset, length, completeWord);
}
data.Document.CommitLineUpdate (data.Caret.Line);
if (idx >= 0)
data.Caret.Offset = triggerOffset + idx;
}
示例12: MoveBlockDown
public static void MoveBlockDown (TextEditorData data)
{
int lineStart = data.Caret.Line;
int lineEnd = data.Caret.Line;
bool setSelection = lineStart != lineEnd;
DocumentLocation anchor = DocumentLocation.Empty, lead = DocumentLocation.Empty;
if (data.IsSomethingSelected) {
setSelection = true;
lineStart = data.MainSelection.MinLine;
lineEnd = data.MainSelection.MaxLine;
anchor = data.MainSelection.Anchor;
lead = data.MainSelection.Lead;
}
if (lineStart <= 0)
return;
using (var undo = data.OpenUndoGroup ()) {
//Mono.TextEditor.LineSegment startLine = data.Document.GetLine (lineStart);
//int relCaretOffset = data.Caret.Offset - startLine.Offset;
Mono.TextEditor.DocumentLine nextLine = data.Document.GetLine (lineEnd + 1);
if (nextLine == null)
return;
string text = data.Document.GetTextAt (nextLine.Offset, nextLine.Length);
List<TextLineMarker> prevLineMarkers = new List<TextLineMarker> (nextLine.Markers);
nextLine.ClearMarker ();
var loc = data.Caret.Location;
for (int i = lineEnd + 1; i >= lineStart; i--) {
DocumentLine cur = data.Document.GetLine (i);
DocumentLine prev = data.Document.GetLine (i - 1);
data.Replace (cur.Offset, cur.Length, i != lineStart ? data.Document.GetTextAt (prev.Offset, prev.Length) : text);
data.Document.GetLine (i).ClearMarker ();
foreach (TextLineMarker marker in (i != lineStart ? data.Document.GetLine (i - 1).Markers : prevLineMarkers)) {
data.Document.GetLine (i).AddMarker (marker);
}
}
data.Caret.Location = new DocumentLocation (loc.Line + 1, loc.Column);
if (setSelection)
data.SetSelection (anchor.Line + 1, anchor.Column, lead.Line + 1, lead.Column);
}
}
示例13: InsertNewLine
public static void InsertNewLine (TextEditorData data)
{
if (!data.CanEditSelection)
return;
using (var undo = data.OpenUndoGroup ()) {
if (data.IsSomethingSelected)
data.DeleteSelectedText ();
switch (data.Options.IndentStyle) {
case IndentStyle.None:
data.InsertAtCaret (data.EolMarker);
break;
case IndentStyle.Auto:
data.EnsureCaretIsNotVirtual ();
var sb = new StringBuilder (data.EolMarker);
sb.Append (data.Document.GetLineIndent (data.Caret.Line));
data.InsertAtCaret (sb.ToString ());
break;
case IndentStyle.Smart:
if (!data.HasIndentationTracker)
goto case IndentStyle.Auto;
NewLineSmartIndent (data);
break;
case IndentStyle.Virtual:
if (!data.HasIndentationTracker)
goto case IndentStyle.Auto;
var oldLine = data.Caret.Line;
var curLine = data.GetLine (oldLine);
var indentCol = data.GetVirtualIndentationColumn (data.Caret.Location);
if (curLine.Length >= data.Caret.Column) {
NewLineSmartIndent (data);
data.FixVirtualIndentation ();
data.FixVirtualIndentation (oldLine);
break;
}
data.Insert (data.Caret.Offset, data.EolMarker);
data.FixVirtualIndentation (oldLine);
data.Caret.Column = indentCol;
break;
default:
throw new ArgumentOutOfRangeException ();
}
}
}
示例14: NewLineSmartIndent
static void NewLineSmartIndent (TextEditorData data)
{
using (var undo = data.OpenUndoGroup ()) {
data.EnsureCaretIsNotVirtual ();
data.InsertAtCaret (data.EolMarker);
data.InsertAtCaret (data.GetIndentationString (data.Caret.Location));
}
}
示例15: InsertTab
public static void InsertTab (TextEditorData data)
{
if (!data.CanEditSelection)
return;
if (data.IsMultiLineSelection && data.MainSelection.SelectionMode != SelectionMode.Block) {
IndentSelection (data);
return;
}
using (var undo = data.OpenUndoGroup ()) {
string indentationString = "\t";
bool convertTabToSpaces = data.TabsToSpaces;
if (!convertTabToSpaces && !data.Options.AllowTabsAfterNonTabs) {
for (int i = 1; i < data.Caret.Column; i++) {
if (data.Document.GetCharAt (data.Caret.Offset - i) != '\t') {
convertTabToSpaces = true;
break;
}
}
}
if (convertTabToSpaces) {
DocumentLocation visualLocation = data.LogicalToVisualLocation (data.Caret.Location);
int tabWidth = TextViewMargin.GetNextTabstop (data, visualLocation.Column) - visualLocation.Column;
indentationString = new string (' ', tabWidth);
}
if (data.IsSomethingSelected)
data.DeleteSelectedText (data.MainSelection.SelectionMode != SelectionMode.Block);
data.InsertAtCaret (indentationString);
}
}