public override void KeyDown(KeyEventArgs args) { char?key = this.keyTypeConverter.ConvertToChar(args.Key); // Check if the parethesis key was pressed if (key.HasValue && key.Value == '(') { // Create a regex line data RegexLineData regexLineData = RegexLineData.CreateFromCaretPosition(this.view); // Check if the line contains a new Regex statement if (IsValid(regexLineData)) { this.view.TextBuffer.Insert(regexLineData.CaretPosition, key.ToString()); // Show the regex editor RegexEditorResult editorResult = this.regexEditorService.ShowEditor(); // Insert the edited pattern in the line if (editorResult.Result.HasValue && editorResult.Result.Value) { this.view.TextBuffer.Insert(regexLineData.CaretPosition + 1, string.Format("@\"{0}\"", editorResult.Pattern)); } args.Handled = true; } } }
public override void PreprocessMouseLeftButtonUp(MouseButtonEventArgs e) { // Check if ctrl+click if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { // Create a regex line data RegexLineData regexLineData = RegexLineData.CreateFromCaretPosition(this.view); // Check if the line contains a new Regex statement if (IsValid(regexLineData)) { // Get the regular expression parameter of the Regex ctor SnapshotSpan?expression = regexLineData.Expression; if (expression.HasValue) { // Check if the click was made over the regular expression parameter. if (regexLineData.CaretPosition >= expression.Value.Start.Position && regexLineData.CaretPosition <= expression.Value.End.Position) { RegexEditorResult editorResult = this.regexEditorService.ShowEditor(regexLineData.Expression.Value.GetText()); if (editorResult.Result.HasValue && editorResult.Result.Value) { this.view.TextBuffer.Replace(regexLineData.Expression.Value.Span, editorResult.Pattern); } e.Handled = true; } } } } }