void CopyData(TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new Document(); monoDocument = new Document(); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = data.Document.SyntaxMode != null && data.Options.EnableSyntaxHighlighting ? data.Document.SyntaxMode : Mono.TextEditor.Highlighting.SyntaxMode.Default; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; ISegment segment = selection.GetSelectionRange(data); copiedDocument.Text = this.mode.GetTextWithoutMarkup(data.Document, data.ColorStyle, segment.Offset, segment.Length); monoDocument.Text = this.mode.GetTextWithoutMarkup(data.Document, data.ColorStyle, segment.Offset, segment.Length); LineSegment line = data.Document.GetLineByOffset(segment.Offset); var spanStack = line.StartSpan.Clone(); SyntaxModeService.ScanSpans(data.Document, this.mode, this.mode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = data.Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(data, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.EditableLength); if (col1 < col2) { ((IBuffer)copiedDocument).Insert(copiedDocument.Length, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); ((IBuffer)monoDocument).Insert(monoDocument.Length, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. ((IBuffer)copiedDocument).Insert(copiedDocument.Length, Environment.NewLine); // \r in mono document stands for block selection line end. ((IBuffer)monoDocument).Insert(monoDocument.Length, "\r"); } } line = data.Document.GetLine(selection.MinLine); spanStack = line.StartSpan.Clone(); SyntaxModeService.ScanSpans(data.Document, this.mode, this.mode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
void CopyData(TextEditorData data, Selection selection) { if (!selection.IsEmpty && data != null && data.Document != null) { this.docStyle = data.ColorStyle; this.options = data.Options; copyData = null; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; var segment = selection.GetSelectionRange(data); copiedColoredChunks = ColoredSegment.GetChunks(data, segment); var pasteHandler = data.TextPasteHandler; if (pasteHandler != null) { try { copyData = pasteHandler.GetCopyData(segment); } catch (Exception e) { Console.WriteLine("Exception while getting copy data:" + e); } } break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); copiedColoredChunks = new List <List <ColoredSegment> >(); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = data.Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(data, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.Length); if (col1 < col2) { copiedColoredChunks.Add(ColoredSegment.GetChunks(data, new TextSegment(curLine.Offset + col1, col2 - col1)).First()); } else { copiedColoredChunks.Add(new List <ColoredSegment>()); } } break; } } else { copiedColoredChunks = null; } }
internal void DeleteSelection(Selection selection) { if (selection == null) { throw new ArgumentNullException("selection"); } switch (selection.SelectionMode) { case SelectionMode.Normal: ISegment segment = selection.GetSelectionRange(this); if (Caret.Offset > segment.Offset) { Caret.Offset -= System.Math.Min(segment.Length, Caret.Offset - segment.Offset); } int len = System.Math.Min(segment.Length, Document.Length - segment.Offset); if (len > 0) { Remove(segment.Offset, len); } break; case SelectionMode.Block: DocumentLocation visStart = LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); bool preserve = Caret.PreserveSelection; Caret.PreserveSelection = true; for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(this, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(this, endCol) - 1, curLine.EditableLength); if (col1 >= col2) { continue; } Remove(curLine.Offset + col1, col2 - col1); if (Caret.Line == lineNr && Caret.Column >= col1) { Caret.Column = col1 + 1; } } int column = System.Math.Min(selection.Anchor.Column, selection.Lead.Column); selection.Anchor = new DocumentLocation(selection.Anchor.Line, column); selection.Lead = new DocumentLocation(selection.Lead.Line, column); Caret.Column = column; Caret.PreserveSelection = preserve; break; } }
void CopyData (TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new TextDocument (); monoDocument = new TextDocument (); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = SyntaxModeService.GetSyntaxMode (monoDocument, data.MimeType); switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; var segment = selection.GetSelectionRange (data); var text = data.GetTextAt (segment); copiedDocument.Text = text; monoDocument.Text = text; var line = data.Document.GetLineByOffset (segment.Offset); var spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = data.Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (data, startCol) - 1; int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.Length); if (col1 < col2) { copiedDocument.Insert (copiedDocument.TextLength, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); monoDocument.Insert (monoDocument.TextLength, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. copiedDocument.Insert (copiedDocument.TextLength, Environment.NewLine); // \r in mono document stands for block selection line end. monoDocument.Insert (monoDocument.TextLength, "\r"); } } line = data.Document.GetLine (selection.MinLine); spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
internal void DeleteSelection (Selection selection) { if (selection == null) throw new ArgumentNullException ("selection"); switch (selection.SelectionMode) { case SelectionMode.Normal: ISegment segment = selection.GetSelectionRange (this); if (Caret.Offset > segment.Offset) Caret.Offset -= System.Math.Min (segment.Length, Caret.Offset - segment.Offset); int len = System.Math.Min (segment.Length, Document.Length - segment.Offset); if (len > 0) Remove (segment.Offset, len); break; case SelectionMode.Block: DocumentLocation visStart = LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); bool preserve = Caret.PreserveSelection; Caret.PreserveSelection = true; for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (this, startCol) - 1; int col2 = System.Math.Min (curLine.GetLogicalColumn (this, endCol) - 1, curLine.EditableLength); if (col1 >= col2) continue; Remove (curLine.Offset + col1, col2 - col1); if (Caret.Line == lineNr && Caret.Column >= col1) Caret.Column = col1 + 1; } int column = System.Math.Min (selection.Anchor.Column, selection.Lead.Column); selection.Anchor = new DocumentLocation (selection.Anchor.Line, column); selection.Lead = new DocumentLocation (selection.Lead.Line, column); Caret.Column = column; Caret.PreserveSelection = preserve; break; } }
void CopyData (TextEditorData data, Selection selection) { if (!selection.IsEmpty && data != null && data.Document != null) { this.docStyle = data.ColorStyle; this.options = data.Options; copyData = null; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; var segment = selection.GetSelectionRange (data); copiedColoredChunks = ColoredSegment.GetChunks (data, segment); var pasteHandler = data.TextPasteHandler; if (pasteHandler != null) copyData = pasteHandler.GetCopyData (segment); break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); copiedColoredChunks = new List<List<ColoredSegment>> (); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = data.Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (data, startCol) - 1; int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.Length); if (col1 < col2) { copiedColoredChunks.Add (ColoredSegment.GetChunks (data, new TextSegment (curLine.Offset + col1, col2 - col1)).First ()); } else { copiedColoredChunks.Add (new List<ColoredSegment> ()); } } break; } } else { copiedColoredChunks = null; } }
internal void DeleteSelection (Selection selection) { if (selection.IsEmpty) throw new ArgumentNullException ("selection was empty."); switch (selection.SelectionMode) { case SelectionMode.Normal: var segment = selection.GetSelectionRange (this); int len = System.Math.Min (segment.Length, Document.TextLength - segment.Offset); var loc = selection.Anchor < selection.Lead ? selection.Anchor : selection.Lead; caret.Location = loc; EnsureCaretIsNotVirtual (); if (len > 0) Remove (segment.Offset, len); caret.Location = loc; break; case SelectionMode.Block: DocumentLocation visStart = LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); bool preserve = Caret.PreserveSelection; Caret.PreserveSelection = true; for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (this, startCol) - 1; int col2 = System.Math.Min (curLine.GetLogicalColumn (this, endCol) - 1, curLine.Length); if (col1 >= col2) continue; Remove (curLine.Offset + col1, col2 - col1); if (Caret.Line == lineNr && Caret.Column >= col1) Caret.Column = col1 + 1; } int column = System.Math.Min (selection.Anchor.Column, selection.Lead.Column); MainSelection = selection.WithRange ( new DocumentLocation (selection.Anchor.Line, column), new DocumentLocation (selection.Lead.Line, column) ); Caret.PreserveSelection = preserve; break; } FixVirtualIndentation (); }
void CopyData (TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new Document (); monoDocument = new Document (); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = data.Document.SyntaxMode != null && data.Options.EnableSyntaxHighlighting ? data.Document.SyntaxMode : Mono.TextEditor.Highlighting.SyntaxMode.Default; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; ISegment segment = selection.GetSelectionRange (data); copiedDocument.Text = this.mode.GetTextWithoutMarkup (data.Document, data.ColorStyle, segment.Offset, segment.Length); monoDocument.Text = this.mode.GetTextWithoutMarkup (data.Document, data.ColorStyle, segment.Offset, segment.Length); LineSegment line = data.Document.GetLineByOffset (segment.Offset); var spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode, this.mode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine (0).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = data.Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (data, startCol); int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol), curLine.EditableLength); if (col1 < col2) { ((IBuffer)copiedDocument).Insert (copiedDocument.Length, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); ((IBuffer)monoDocument).Insert (monoDocument.Length, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. ((IBuffer)copiedDocument).Insert (copiedDocument.Length, Environment.NewLine); // \r in mono document stands for block selection line end. ((IBuffer)monoDocument).Insert (monoDocument.Length, "\r"); } } line = data.Document.GetLine (selection.MinLine); spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode, this.mode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine (0).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
void CopyData(TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (!selection.IsEmpty && data != null && data.Document != null) { copiedDocument = new TextDocument(); monoDocument = new TextDocument(); this.docStyle = data.ColorStyle; this.options = data.Options; copyData = null; copiedColoredChunks = ColoredSegment.GetChunks(data, data.SelectionRange); switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; var segment = selection.GetSelectionRange(data); var pasteHandler = data.TextPasteHandler; if (pasteHandler != null) { copyData = pasteHandler.GetCopyData(segment); } var text = data.GetTextAt(segment); copiedDocument.Text = text; monoDocument.Text = text; var line = data.Document.GetLineByOffset(segment.Offset); var spanStack = line.StartSpan.Clone(); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = data.Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(data, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.Length); if (col1 < col2) { copiedDocument.Insert(copiedDocument.TextLength, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); monoDocument.Insert(monoDocument.TextLength, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. copiedDocument.Insert(copiedDocument.TextLength, Environment.NewLine); // \r in mono document stands for block selection line end. monoDocument.Insert(monoDocument.TextLength, "\r"); } } line = data.Document.GetLine(selection.MinLine); spanStack = line.StartSpan.Clone(); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }