private void PerformCopy(TextEditorControl from, TextEditorControl to, int line, int length, int fromLength) { var fromDocument = from.Document; // Get the text we're going to copy. int fromStart = fromDocument.PositionToOffset(new TextLocation( 0, line )); int fromEnd = fromDocument.PositionToOffset(new TextLocation( 0, line + fromLength )); string fromText = fromDocument.GetText(fromStart, fromEnd - fromStart); UpdateEditor(from, () => { // Remove the markers. int start = from.Document.PositionToOffset(new TextLocation( 0, line )); int end = from.Document.PositionToOffset(new TextLocation( 0, line + length )); from.Document.MarkerStrategy.RemoveAll(p => p.Offset >= start && p.EndOffset <= end); // Remove empty lines from the source editor. if (fromLength != length) { start = from.Document.PositionToOffset(new TextLocation( 0, line + fromLength )); from.Document.Remove(start, end - start); } }); UpdateEditor(to, () => { // Update the target. int start = to.Document.PositionToOffset(new TextLocation( 0, line )); int end = to.Document.PositionToOffset(new TextLocation( 0, line + length )); to.Document.Replace(start, end - start, fromText); }); }
private void RemoveFromDocument(TextEditorControl editor, int line, int length) { UpdateEditor(editor, () => { var start = editor.Document.PositionToOffset(new TextLocation( 0, line )); var end = editor.Document.PositionToOffset(new TextLocation( 0, line + length )); editor.Document.Remove(start, end - start); }); }
protected override Control CreateClient() { var fontSettings = SettingsBuilder.GetSettings <IFontSettings>(this); var control = new TextEditorControl { Font = fontSettings.CodeFont ?? Constants.DefaultCodeFont, ConvertTabsToSpaces = true, Site = new SiteProxy(this) }; HookEvents(control.ActiveTextAreaControl); return(control); }
private void SyncTo(TextEditorControl source, TextEditorControl target) { source.ActiveTextAreaControl.HScrollBar.ValueChanged += (s, e) => { target.ActiveTextAreaControl.TextArea.VirtualTop = source.ActiveTextAreaControl.TextArea.VirtualTop; source.ActiveTextAreaControl.TextArea.Update(); target.ActiveTextAreaControl.TextArea.Update(); }; source.ActiveTextAreaControl.VScrollBar.ValueChanged += (s, e) => { target.ActiveTextAreaControl.TextArea.VirtualTop = source.ActiveTextAreaControl.TextArea.VirtualTop; source.ActiveTextAreaControl.TextArea.Update(); target.ActiveTextAreaControl.TextArea.Update(); }; }
private void UpdateEditor(TextEditorControl editor, Action action) { var textArea = editor.ActiveTextAreaControl.TextArea; var document = textArea.Document; document.ReadOnly = false; try { textArea.BeginUpdate(); action(); textArea.Caret.ValidateCaretPos(); textArea.EndUpdate(); textArea.Refresh(); } finally { document.ReadOnly = false; } }
public TrimmedCopy(SideBySideViewer owner, TextEditorControl editor) { _owner = owner; _editor = editor; }
private void UpdateEditor(TextEditorControl editor, Action action) { var textArea = editor.ActiveTextAreaControl.TextArea; var document = textArea.Document; document.ReadOnly = false; try { textArea.BeginUpdate(); action(); textArea.Caret.ValidateCaretPos(); textArea.EndUpdate(); textArea.Refresh(); } finally { document.ReadOnly = false; } }
private void SyncTo(TextEditorControl source, TextEditorControl target) { source.ActiveTextAreaControl.HScrollBar.ValueChanged += (s, e) => { target.ActiveTextAreaControl.TextArea.VirtualTop = source.ActiveTextAreaControl.TextArea.VirtualTop; source.ActiveTextAreaControl.TextArea.Update(); target.ActiveTextAreaControl.TextArea.Update(); }; source.ActiveTextAreaControl.VScrollBar.ValueChanged += (s, e) => { target.ActiveTextAreaControl.TextArea.VirtualTop = source.ActiveTextAreaControl.TextArea.VirtualTop; source.ActiveTextAreaControl.TextArea.Update(); target.ActiveTextAreaControl.TextArea.Update(); }; }
private void RemoveFromDocument(TextEditorControl editor, int line, int length) { UpdateEditor(editor, () => { var start = editor.Document.PositionToOffset(new TextLocation( 0, line )); var end = editor.Document.PositionToOffset(new TextLocation( 0, line + length )); editor.Document.Remove(start, end - start); }); }
private void PerformCopy(TextEditorControl from, TextEditorControl to, int line, int length, int fromLength) { var fromDocument = from.Document; // Get the text we're going to copy. int fromStart = fromDocument.PositionToOffset(new TextLocation( 0, line )); int fromEnd = fromDocument.PositionToOffset(new TextLocation( 0, line + fromLength )); string fromText = fromDocument.GetText(fromStart, fromEnd - fromStart); UpdateEditor(from, () => { // Remove the markers. int start = from.Document.PositionToOffset(new TextLocation( 0, line )); int end = from.Document.PositionToOffset(new TextLocation( 0, line + length )); from.Document.MarkerStrategy.RemoveAll(p => p.Offset >= start && p.EndOffset <= end); // Remove empty lines from the source editor. if (fromLength != length) { start = from.Document.PositionToOffset(new TextLocation( 0, line + fromLength )); from.Document.Remove(start, end - start); } }); UpdateEditor(to, () => { // Update the target. int start = to.Document.PositionToOffset(new TextLocation( 0, line )); int end = to.Document.PositionToOffset(new TextLocation( 0, line + length )); to.Document.Replace(start, end - start, fromText); }); }
private string GetTrimmedText(TextEditorControl editor, int start, int end) { var document = editor.Document; // The document contains empty lines to fill up space because the // other side has more text. This removes these empty lines from // the output. var sb = new StringBuilder(); bool isLeft = editor == _leftEditor; int offset = start; foreach (var marker in _markers) { int startLength = isLeft ? marker.LeftLength : marker.RightLength; int endLength = marker.Length; if (startLength != endLength) { int markerStart = document.PositionToOffset(new TextLocation( 0, marker.Line + startLength )); int markerEnd = document.PositionToOffset(new TextLocation( 0, marker.Line + endLength )); if (markerStart < offset) offset = markerEnd; if (markerEnd > offset) { sb.Append(document.GetText( offset, Math.Min(markerStart, end) - offset )); offset = markerEnd; } if (offset >= end) break; } } if (offset < end) { sb.Append(document.GetText( offset, end - offset )); } return sb.ToString(); }
public TrimmedCopy(SideBySideViewer owner, TextEditorControl editor) { _owner = owner; _editor = editor; }
private string GetTrimmedText(TextEditorControl editor, int start, int end) { var document = editor.Document; // The document contains empty lines to fill up space because the // other side has more text. This removes these empty lines from // the output. var sb = new StringBuilder(); bool isLeft = editor == _leftEditor; int offset = start; foreach (var marker in _markers) { int startLength = isLeft ? marker.LeftLength : marker.RightLength; int endLength = marker.Length; if (startLength != endLength) { int markerStart = document.PositionToOffset(new TextLocation( 0, marker.Line + startLength )); int markerEnd = document.PositionToOffset(new TextLocation( 0, marker.Line + endLength )); if (markerStart < offset) { offset = markerEnd; } if (markerEnd > offset) { sb.Append(document.GetText( offset, Math.Min(markerStart, end) - offset )); offset = markerEnd; } if (offset >= end) { break; } } } if (offset < end) { sb.Append(document.GetText( offset, end - offset )); } return(sb.ToString()); }
protected override Control CreateClient() { var fontSettings = SettingsBuilder.GetSettings<IFontSettings>(this); var control = new TextEditorControl { Font = fontSettings.CodeFont ?? Constants.DefaultCodeFont, ConvertTabsToSpaces = true, Site = new SiteProxy(this) }; HookEvents(control.ActiveTextAreaControl); return control; }