public static int PasteFromPrimary(TextEditorData data, int insertionOffset) { var result = PasteFrom(Clipboard.Get(CopyOperation.PRIMARYCLIPBOARD_ATOM), data, true, insertionOffset, true); data.Document.CommitLineUpdate(data.GetLineByOffset(insertionOffset)); return(result); }
public static int PasteFromPrimary(TextEditorData data, int insertionOffset) { var result = PasteFrom(data, true, insertionOffset, true); data.Document.CommitLineUpdate(data.GetLineByOffset(insertionOffset)); return(result); }
public static int PasteFromPrimary (TextEditorData data, int insertionOffset) { var result = PasteFrom (Clipboard.Get (CopyOperation.PRIMARYCLIPBOARD_ATOM), data, false, insertionOffset, true); data.Document.CommitLineUpdate (data.GetLineByOffset (insertionOffset)); return result; }
void TestGuessSemicolonInsertionOffset(string fooBar, bool expected = true) { StringBuilder sb = new StringBuilder (); int semicolonOffset = 0; int guessedOffset = 0; for (int i = 0; i <fooBar.Length; i++) { char ch = fooBar [i]; if (ch == '$') { semicolonOffset = sb.Length - 1; } else if (ch == '~') { guessedOffset = sb.Length - 1; } else { sb.Append (ch); } } var data = new TextEditorData (); data.Text = sb.ToString (); int guessed; Assert.AreEqual (expected, CSharpTextEditorIndentation.GuessSemicolonInsertionOffset (data, data.GetLineByOffset (semicolonOffset), semicolonOffset, out guessed)); if (expected) Assert.AreEqual (guessedOffset, guessed); }
public override void HandleSpecialSelectionKey (TextEditorData textEditorData,uint unicodeKey) { string start, end; GetSelectionSurroundings (textEditorData, unicodeKey, out start, out end); var selection = textEditorData.MainSelection; if (textEditorData.MainSelection.SelectionMode == SelectionMode.Block) { int startCol = System.Math.Min (selection.Anchor.Column, selection.Lead.Column) - 1; int endCol = System.Math.Max (selection.Anchor.Column, selection.Lead.Column); for (int lineNumber = selection.MinLine; lineNumber <= selection.MaxLine; lineNumber++) { DocumentLine lineSegment = textEditorData.GetLine (lineNumber); if (lineSegment.Offset + startCol < lineSegment.EndOffset) textEditorData.Insert (lineSegment.Offset + startCol, start); if (lineSegment.Offset + endCol < lineSegment.EndOffset) textEditorData.Insert (lineSegment.Offset + endCol, end); } textEditorData.MainSelection = new Selection ( new DocumentLocation (selection.Anchor.Line, endCol == selection.Anchor.Column ? endCol + start.Length : startCol + 1 + start.Length), new DocumentLocation (selection.Lead.Line, endCol == selection.Anchor.Column ? startCol + 1 + start.Length : endCol + start.Length), Mono.TextEditor.SelectionMode.Block); textEditorData.Document.CommitMultipleLineUpdate (textEditorData.MainSelection.MinLine, textEditorData.MainSelection.MaxLine); } else { int anchorOffset = selection.GetAnchorOffset (textEditorData); int leadOffset = selection.GetLeadOffset (textEditorData); if (leadOffset < anchorOffset) { int tmp = anchorOffset; anchorOffset = leadOffset; leadOffset = tmp; } textEditorData.Insert (anchorOffset, start); textEditorData.Insert (leadOffset >= anchorOffset ? leadOffset + start.Length : leadOffset, end); // textEditorData.SetSelection (anchorOffset + start.Length, leadOffset + start.Length); if (CSharpTextEditorIndentation.OnTheFlyFormatting) { var l1 = textEditorData.GetLineByOffset (anchorOffset); var l2 = textEditorData.GetLineByOffset (leadOffset); OnTheFlyFormatter.Format (document, l1.Offset, l2.EndOffsetIncludingDelimiter); } } }
static bool TryFindSymbolBlock(TextEditorData data, char command, out SymbolBlock result) { char end, begin; if (!BeginToEndCharMap.TryGetValue (command, out end)) end = command; if (!EndToBeginCharMap.TryGetValue (command, out begin)) begin = command; var offset = data.Caret.Offset; var startTokenOffset = ParseForChar(data, offset, 0, end, begin, false); var endTokenOffset = ParseForChar(data, offset, data.Length, begin, end, true); // Use the editor's FindMatchingBrace built-in functionality. It's better at handling erroneous braces // inside quotes. We still need to do the above paragraph because we needed to find the braces. var matchingStartBrace = endTokenOffset.HasValue ? data.Document.GetMatchingBracketOffset( endTokenOffset.GetValueOrDefault ()) : -1; if (matchingStartBrace >= 0 && (!startTokenOffset.HasValue || matchingStartBrace != startTokenOffset.GetValueOrDefault ())) startTokenOffset = matchingStartBrace; var matchingEndBrace = startTokenOffset.HasValue && data.GetCharAt (offset) != end ? data.Document.GetMatchingBracketOffset(startTokenOffset.GetValueOrDefault ()) : -1; if (matchingEndBrace >= 0 && (!endTokenOffset.HasValue || matchingEndBrace != endTokenOffset.GetValueOrDefault ())) endTokenOffset = matchingEndBrace; if (!startTokenOffset.HasValue || !endTokenOffset.HasValue) throw new ViModeAbortException(); result = new SymbolBlock { StartOffset = startTokenOffset.GetValueOrDefault (), EndOffset = endTokenOffset.GetValueOrDefault (), StartLine = data.GetLineByOffset (startTokenOffset.GetValueOrDefault()), EndLine = data.GetLineByOffset (endTokenOffset.GetValueOrDefault()), }; return true; }