IContextAction Wrap(CodeAction actionToWrap, int index) { // Take care not to capture 'actionToWrap' in the lambda string actionDescription = actionToWrap.Description; return(new CSharpContextActionWrapper( manager, actionToWrap, context => { // Look up the new issue position int newStart = InspectedVersion.MoveOffsetTo(context.Version, StartOffset, AnchorMovementType.Default); int newEnd = InspectedVersion.MoveOffsetTo(context.Version, EndOffset, AnchorMovementType.Default); // If the length changed, don't bother looking up the issue again if (newEnd - newStart != EndOffset - StartOffset) { return null; } // Now rediscover this issue in the new context var issue = this.Provider.GetIssues(context).FirstOrDefault( i => context.GetOffset(i.Start) == newStart && context.GetOffset(i.End) == newEnd && i.Description == this.Description); if (issue == null) { return null; } // Now look up the action within that issue: if (index < issue.Actions.Count && issue.Actions[index].Description == actionDescription) { return issue.Actions[index]; } else { return null; } })); }
protected override void OnDocumentClosing() { // text source version becomes invalid on document close. var editor = Document.Editor; offset = version.MoveOffsetTo(editor.Version, offset); var location = editor.CaretLocation; line = location.Line; column = location.Column; version = null; }
public void ExitTextLinkMode() { if (isExited) { return; } isExited = true; Editor.Document.BeforeUndoOperation -= HandleEditorDocumentBeginUndo; Editor.Document.TextBuffer.Changed -= UpdateLinksOnTextReplace; Editor.Caret.PositionChanged -= HandlePositionChanged; DestroyHelpWindow(); textLinkMarkers.ForEach(m => Editor.Document.RemoveMarker(m)); textLinkMarkers.Clear(); if (SetCaretPosition && resetCaret) { Editor.Caret.Offset = caretOffsetVersion.MoveOffsetTo(Editor.Document.Version, caretOffset); Editor.GetTextEditorData().FixVirtualIndentation(); } if (undoDepth >= 0) { Editor.Document.StackUndoToDepth(undoDepth); } Editor.CurrentMode = OldMode; Editor.Document.CommitUpdateAll(); OnExited(EventArgs.Empty); }
protected override void OnDocumentClosing() { try { // text source version becomes invalid on document close. if (buffer != null) { if (version.BelongsToSameDocumentAs(buffer.Version)) { offset = version.MoveOffsetTo(buffer.Version, offset); } var location = buffer.CaretLocation; line = location.Line; column = location.Column; } } catch (Exception e) { LoggingService.LogInternalError(e); } version = null; buffer = null; }
protected void JumpToCurrentLocation(TextEditor editor) { if (version != null && version.BelongsToSameDocumentAs(editor.Version)) { var currentOffset = version.MoveOffsetTo(editor.Version, offset); var loc = editor.OffsetToLocation(currentOffset); editor.SetCaretLocation(loc); } else { editor.SetCaretLocation(Math.Max(line, 1), Math.Max(column, 1)); } }
internal void UpdateCaretPosition(DocumentChangeEventArgs e) { if (e.AnchorMovementType == AnchorMovementType.BeforeInsertion && caretOffset == e.Offset) { return; } var curVersion = TextEditorData.Version; if (offsetVersion == null) { offsetVersion = curVersion; return; } var newOffset = offsetVersion.MoveOffsetTo(curVersion, caretOffset); offsetVersion = curVersion; if (newOffset == caretOffset || !AutoUpdatePosition) { return; } DocumentLocation old = Location; var newLocation = TextEditorData.OffsetToLocation(newOffset); int newColumn = newLocation.Column; var curLine = TextEditorData.GetLine(newLocation.Line); if (TextEditorData.HasIndentationTracker && TextEditorData.Options.IndentStyle == IndentStyle.Virtual && curLine.Length == 0) { var indentColumn = TextEditorData.GetVirtualIndentationColumn(Location); if (column == indentColumn) { newColumn = indentColumn; } } if (AllowCaretBehindLineEnd) { if (curLine != null && column > curLine.Length) { newColumn = column; } } line = newLocation.Line; column = newColumn; SetDesiredColumn(); UpdateCaretOffset(); OnPositionChanged(new DocumentLocationEventArgs(old)); }