private void OnKeyDown(object sender, KeyEventArgs e) { if (e.Handled) { return; } if (this.completionBroker != null) { CodeAidContext codeAidContext = this.CreateCodeAidContext(); CodeAidAction action = this.codeAidEngine.ProcessKeyDown(e.Key, codeAidContext); if (!action.IsNone) { this.ExecuteCodeAidAction(action, false); } if (action.TestFlag(CodeAidActionType.EatInput)) { e.Handled = true; } else { this.OnKeyDownHelper(e); } this.ExecuteFormattingAction(action); } else { this.OnKeyDownHelper(e); } }
private void ExecuteFormattingAction(CodeAidAction action) { ITextSnapshot textSnapshot = this.textView.TextSnapshot; int index = this.textView.Caret.Position.Index; string forContainingTag = this.codeAidEngine.GetBeginningWhitespaceForContainingTag(textSnapshot, index); if (action.TestFlag(CodeAidActionType.AutoGenNewLineBelow)) { this.editorOperations.InsertNewline(this.undoHistory); this.ReplaceTextRange(this.textView.TextSnapshot.GetLineFromPosition(index).Start, index, forContainingTag); this.textView.Caret.MoveTo(index); } if (!action.TestFlag(CodeAidActionType.AutoGenIndent)) { return; } this.ReplaceTextRange(this.textView.TextSnapshot.GetLineFromPosition(index).Start, index, forContainingTag + "\t"); }
private bool CreateAndExecuteCodeAidAction(TextCompositionEventArgs e, bool matchingModeOnly) { PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.TextInsertLetter); if (this.completionBroker == null) { return(false); } CodeAidContext codeAidContext = this.CreateCodeAidContext(); CodeAidAction action = this.codeAidEngine.ProcessTextInput(e.Text, codeAidContext); if (!action.IsNone) { this.ExecuteCodeAidAction(action, matchingModeOnly); } if (!action.TestFlag(CodeAidActionType.EatInput) && !matchingModeOnly) { this.editorOperations.InsertText(e.Text, this.undoHistory); } return(true); }
public CodeAidAction(CodeAidActionType actionType) { this = new CodeAidAction(); this.actionTypeFlags = actionType; }
private void ExecuteCodeAidAction(CodeAidAction action, bool matchingModeOnly) { if (action.TestFlag(CodeAidActionType.CommitSession) && !matchingModeOnly) { this.CommitCompletionSession(action.TestFlag(CodeAidActionType.CommitOnHollowSelection)); } else if (action.TestFlag(CodeAidActionType.DismissSession)) { this.DismissCompletionSession(); } if (action.TestFlag(CodeAidActionType.StartSession)) { this.AsyncStartCompletionSession(); } if (action.TestFlag(CodeAidActionType.MatchTracking)) { this.AsyncMatchCompletionSession(); } if (action.TestFlag(CodeAidActionType.MoveSelDown)) { this.OffsetCompletionSelection(1); } if (action.TestFlag(CodeAidActionType.MoveSelUp)) { this.OffsetCompletionSelection(-1); } if (action.TestFlag(CodeAidActionType.MoveSelPageDown)) { this.OffsetCompletionSelection(7); } if (action.TestFlag(CodeAidActionType.MoveSelPageUp)) { this.OffsetCompletionSelection(-7); } if (action.TestFlag(CodeAidActionType.MoveSelHome) && this.activeSession != null) { this.activeSession.SetSelectionStatus(this.activeSession.Completions[0], CompletionSelectionOptions.Selected | CompletionSelectionOptions.Unique); } if (action.TestFlag(CodeAidActionType.MoveSelEnd) && this.activeSession != null) { this.activeSession.SetSelectionStatus(this.activeSession.Completions[this.activeSession.Completions.Count - 1], CompletionSelectionOptions.Selected | CompletionSelectionOptions.Unique); } if (action.TestFlag(CodeAidActionType.AutoGenDot) && !matchingModeOnly) { int num = this.LeftmostTextViewSelection(); this.editorOperations.InsertText(".", this.undoHistory); this.textView.Caret.MoveTo(num + 1); } if (action.TestFlag(CodeAidActionType.AutoGenAttrQuotes) && !matchingModeOnly) { int num1 = this.LeftmostTextViewSelection(); this.editorOperations.InsertText("=\"\"", this.undoHistory); int num2 = action.TestFlag(CodeAidActionType.CreateCloseTag) ? 3 : 2; this.textView.Caret.MoveTo(num1 + num2); } if (action.TestFlag(CodeAidActionType.CreateCloseTag) && !matchingModeOnly) { string autoCloseTag = this.codeAidEngine.GetAutoCloseTag(this.CreateCodeAidContext()); if (!string.IsNullOrEmpty(autoCloseTag)) { int caretIndex = this.LeftmostTextViewSelection(); this.editorOperations.InsertText("</" + autoCloseTag + ">", this.undoHistory); this.textView.Caret.MoveTo(caretIndex); } } if (action.TestFlag(CodeAidActionType.AutoGenClosingBracket) && !matchingModeOnly) { int num = this.LeftmostTextViewSelection(); this.editorOperations.InsertText(">", this.undoHistory); this.textView.Caret.MoveTo(num + 1); } if (!action.TestFlag(CodeAidActionType.AutoGenCloseComment) || matchingModeOnly) { return; } int caretIndex1 = this.LeftmostTextViewSelection(); this.editorOperations.InsertText("-->", this.undoHistory); this.textView.Caret.MoveTo(caretIndex1); }