当前位置: 首页>>代码示例>>C#>>正文


C# TextEditor._FilterText方法代码示例

本文整理汇总了C#中System.Windows.Documents.TextEditor._FilterText方法的典型用法代码示例。如果您正苦于以下问题:C# TextEditor._FilterText方法的具体用法?C# TextEditor._FilterText怎么用?C# TextEditor._FilterText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.TextEditor的用法示例。


在下文中一共展示了TextEditor._FilterText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoTextInput

        // ...................................................... 
        //
        //  Handling Text Input 
        // 
        // ......................................................
 
        /// <summary>
        /// This is a single method used to insert user input characters.
        /// It takes care of typing undo, springload formatting, overtype mode etc.
        /// </summary> 
        /// <param name="This"></param>
        /// <param name="textData"> 
        /// Text to insert. 
        /// </param>
        /// <param name="isInsertKeyToggled"> 
        /// Reflects a state of Insert key at the moment of textData input.
        /// </param>
        /// <param name="acceptControlCharacters">
        /// True indicates that control characters like '\t' or '\r' etc. can be inserted. 
        /// False means that all control characters are filtered out.
        /// </param> 
        private static void DoTextInput(TextEditor This, string textData, bool isInsertKeyToggled, bool acceptControlCharacters) 
        {
            // Hide the mouse cursor on user input. 
            HideCursor(This);

            // Remove control characters. Note that this is not included into _FilterText,
            // because we want such kind of filtering only for real input, 
            // not for copy/paste.
            if (!acceptControlCharacters) 
            { 
                for (int i = 0; i < textData.Length; i++)
                { 
                    if (Char.IsControl(textData[i]))
                    {
                        textData = textData.Remove(i--, 1);  // decrement i to compensate for character removal
                    } 
                }
            } 
 
            string filteredText = This._FilterText(textData, This.Selection);
            if (filteredText.Length == 0) 
            {
                return;
            }
 
            TextEditorTyping.OpenTypingUndoUnit(This);
 
            UndoCloseAction closeAction = UndoCloseAction.Rollback; 

            try 
            {
                using (This.Selection.DeclareChangeBlock())
                {
                    This.Selection.ApplyTypingHeuristics(This.AllowOvertype && This._OvertypeMode && filteredText != "\t"); 

                    This.SetSelectedText(filteredText, InputLanguageManager.Current.CurrentInputLanguage); 
 
                    // Create caret position normalized backward to keep formatting of a character just typed
                    ITextPointer caretPosition = This.Selection.End.CreatePointer(LogicalDirection.Backward); 

                    // Set selection at the end of input content
                    This.Selection.SetCaretToPosition(caretPosition, LogicalDirection.Backward, /*allowStopAtLineEnd:*/true, /*allowStopNearSpace:*/true);
                    // Note: Using explicit backward orientation we keep formatting with 
                    // a previous character during typing.
 
                    closeAction = UndoCloseAction.Commit; 
                }
            } 
            finally
            {
                TextEditorTyping.CloseTypingUndoUnit(This, closeAction);
            } 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:74,代码来源:TextEditorTyping.cs

示例2: PastePlainText

        // Helper for plain text filtering when pasted into rich or plain destination
        private static bool PastePlainText(TextEditor This, string pastedText)
        {
            pastedText = This._FilterText(pastedText, This.Selection);

            if (pastedText.Length > 0)
            {
                if (This.AcceptsRichContent && This.Selection.Start is TextPointer)
                {
                    // Clear selection content
                    This.Selection.Text = String.Empty;

                    // Ensure that text is insertable at current selection
                    TextPointer start = TextRangeEditTables.EnsureInsertionPosition((TextPointer)This.Selection.Start);

                    // Store boundaries of inserted text
                    start = start.GetPositionAtOffset(0, LogicalDirection.Backward);
                    TextPointer end = start.GetPositionAtOffset(0, LogicalDirection.Forward);

                    // For rich text we need to remove control characters and
                    // replace linebreaks by paragraphs
                    int currentLineStart = 0;
                    for (int i = 0; i < pastedText.Length; i++)
                    {
                        if (pastedText[i] == '\r' || pastedText[i] == '\n')
                        {
                            end.InsertTextInRun(pastedText.Substring(currentLineStart, i - currentLineStart));
                            if (!This.AcceptsReturn)
                            {
                                return true; // All lined except for the first one are ignored when TextBox does not accept Return key
                            }

                            if (end.HasNonMergeableInlineAncestor)
                            {
                                // We cannot split a Hyperlink or other non-mergeable Inline element,
                                // so insert a space character instead (similar to embedded object).
                                // Note that this means, Paste operation would loose
                                // paragraph break information in this case.
                                end.InsertTextInRun(" ");
                            }
                            else
                            {
                                end = end.InsertParagraphBreak();
                            }

                            if (pastedText[i] == '\r' && i + 1 < pastedText.Length && pastedText[i + 1] == '\n')
                            {
                                i++;
                            }
                            currentLineStart = i + 1;
                        }
                    }
                    end.InsertTextInRun(pastedText.Substring(currentLineStart, pastedText.Length - currentLineStart));

                    // Select all pasted content
                    This.Selection.Select(start, end);
                }
                else
                {
                    // For plain text we insert the content as is (including control characters)
                    This.Selection.Text = pastedText;
                }
                return true;
            }

            return false;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:67,代码来源:TextEditorCopyPaste.cs

示例3: HandleEnterBreakForPlainText

        // Helper for OnEnterBreak for plain text case
        private static bool HandleEnterBreakForPlainText(TextEditor This) 
        { 
            bool wasSelectionChanged = true;
 
            // Filter Environment.NewLine based on TextBox.MaxLength
            string filteredText = This._FilterText(Environment.NewLine, This.Selection);

            if (filteredText != String.Empty) 
            {
                This.Selection.Text = Environment.NewLine; 
            } 
            else
            { 
                // Do not update selection if Environment.NewLine can not fit in.
                wasSelectionChanged = false;
            }
 
            return wasSelectionChanged;
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:20,代码来源:TextEditorTyping.cs


注:本文中的System.Windows.Documents.TextEditor._FilterText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。