private void PreviewKeyDownHandler(object sender, KeyEventArgs e) { AutocompleteManager.handleKeyDown(e); if (e.Handled || Keyboard.IsKeyDown(Key.RightAlt)) { return; } Char c = KeyDecoder.GetCharFromKey(e.Key); if (e.Key == Key.Enter) { if (!Selection.IsEmpty) { Selection.Text = ""; } TextPointer inserted = Selection.Start.InsertLineBreak(); Selection.Select(inserted, inserted); e.Handled = true; } else if ((c == '?' || c == '#') && Selection.IsEmpty) { Selection.Text = c.ToString(); LMD_Document lmdDoc = new LMD_Document(getDocument(Document)); String result = lmdDoc.getCommandResult(); Selection.Text = (result == "") ? c.ToString() : result; Selection.Select(Selection.End, Selection.End); e.Handled = true; } else if (e.Key == Key.Space) { BeginChange(); CaretPosition = CaretPosition.GetPositionAtOffset(0, LogicalDirection.Backward); CaretPosition.InsertTextInRun(c.ToString()); CaretPosition = CaretPosition.GetNextInsertionPosition(LogicalDirection.Forward); e.Handled = true; EndChange(); } }