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


C# Paragraph.GetTextBefore方法代码示例

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


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

示例1: ExtractListOfWords

        private List<string> ExtractListOfWords(Paragraph paragraph)
        {
            var caretIsWithin = (this.CaretPosition != null &&
                                 this.CaretPosition.CompareTo(paragraph.ContentStart) >= 0 &&
                                 this.CaretPosition.CompareTo(paragraph.ContentEnd) <= 0);

            var list = new List<string>();

            if (caretIsWithin)
            {
                var beforeText = paragraph.GetTextBefore(this.CaretPosition);
                var afterText = paragraph.GetTextAfter(this.CaretPosition);
                // enter key was pressed
                if (beforeText == "" && afterText == "")
                {

                    if (this.DisableAddingWhiteSpacesOnEnter)
                    {
                        return null;
                    }
                    // add white space to the new line - same as the previous line
                    var prev = paragraph.PreviousBlock as Paragraph;
                    if (prev != null)
                    {
                        var previousLine = prev.GetText();
                        var spaces = new StringBuilder();
                        foreach (var ch in previousLine)
                        {
                            if (ch == ' ' || ch == '\t')
                            {
                                spaces.Append(ch);
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (spaces.Length > 0)
                        {
                            beforeText = spaces.ToString();
                        }
                        else
                        {
                            return null;
                        }
                    }
                    else
                    {
                        return null;
                    }
                }
                // else

                if (beforeText != "") list.AddRange(this._paragraphProcessor.SplitWordsRegex.Split(beforeText));
                list.Add(null);
                if (afterText != "") list.AddRange(this._paragraphProcessor.SplitWordsRegex.Split(afterText));
            }
            else
            {
                var text = paragraph.GetText();
                var array = this._paragraphProcessor.SplitWordsRegex.Split(text);
                list.AddRange(array);
            }
            return list;
        }
开发者ID:VahidN,项目名称:PdfReport,代码行数:65,代码来源:SourceCodeEditor.cs

示例2: ExtractListOfWords

        /// <summary>
        /// 
        /// </summary>
        /// <param name="textBox"></param>
        /// <param name="paragraph"></param>
        /// <returns></returns>
        private List<string> ExtractListOfWords(RichTextBox textBox, Paragraph paragraph)
        {
            // Check if caret position is within the word
            var caretIsWithin = (textBox.CaretPosition != null &&
                                 textBox.CaretPosition.CompareTo(paragraph.ContentStart) >= 0 &&
                                 textBox.CaretPosition.CompareTo(paragraph.ContentEnd) <= 0);

            var list = new List<string>();

            // If caret is within the paragraph, we need to break it up into Inline objects and format the line
            if (caretIsWithin) {

                var beforeText = paragraph.GetTextBefore(textBox.CaretPosition);
                var afterText = paragraph.GetTextAfter(textBox.CaretPosition);

                // If there's no text on either side of the caret, we're on an empty line
                if (beforeText == "" && afterText == "") {

                    if (this.DisableAddingWhiteSpacesOnEnter) {
                        return null;
                    }

                    // Add white space to the new line - same as the previous line
                    var prev = paragraph.PreviousBlock as Paragraph;
                    if (prev != null) {
                        var previousLine = prev.GetText();
                        var spaces = new StringBuilder();

                        foreach (var ch in previousLine) {
                            if (ch == ' ' || ch == '\t') {
                                spaces.Append(ch);
                            }
                            else {
                                break;
                            }
                        }

                        if (spaces.Length > 0) {
                            beforeText = spaces.ToString();
                        }
                        else {
                            return null;
                        }
                    }
                    else {
                        return null;
                    }
                }

                // If theres text before or after the caret, split the words and add them to the list
                if (beforeText != "") {
                    list.AddRange(this.syntaxProcessor.SplitWordsRegex.Split(beforeText));
                }

                // Add null representing the caret
                list.Add(null);

                if (afterText != "") {
                    list.AddRange(this.syntaxProcessor.SplitWordsRegex.Split(afterText));
                }
            }
            else {
                // If caret is not in the paragraph, just add it as-is.
                // It would already be formatted.
                var text = paragraph.GetText();
                var array = this.syntaxProcessor.SplitWordsRegex.Split(text);
                list.AddRange(array);
            }

            return list;
        }
开发者ID:Kaffedreng,项目名称:CodeEditor,代码行数:77,代码来源:TextEditorControl.cs


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