public GetNextInsertionPosition ( LogicalDirection direction ) : |
||
direction | LogicalDirection | |
return |
public static TextPointer RemoveHyperlink(TextPointer start) { var backspacePosition = start.GetNextInsertionPosition(LogicalDirection.Backward); Hyperlink hyperlink; if (backspacePosition == null || !IsHyperlinkBoundaryCrossed(start, backspacePosition, out hyperlink)) { return null; } // Remember caretPosition with forward gravity. This is necessary since we are going to delete // the hyperlink element preceeding caretPosition and after deletion current caretPosition // (with backward gravity) will follow content preceeding the hyperlink. // We want to remember content following the hyperlink to set new caret position at. var newCaretPosition = start.GetPositionAtOffset(0, LogicalDirection.Forward); // Deleting the hyperlink is done using logic below. // 1. Copy its children Inline to a temporary array. var hyperlinkChildren = hyperlink.Inlines; var inlines = new Inline[hyperlinkChildren.Count]; hyperlinkChildren.CopyTo(inlines, 0); // 2. Remove each child from parent hyperlink element and insert it after the hyperlink. for (int i = inlines.Length - 1; i >= 0; i--) { hyperlinkChildren.Remove(inlines[i]); hyperlink.SiblingInlines.InsertAfter(hyperlink, inlines[i]); } // 3. Apply hyperlink's local formatting properties to inlines (which are now outside hyperlink scope). var localProperties = hyperlink.GetLocalValueEnumerator(); var inlineRange = new TextRange(inlines[0].ContentStart, inlines[inlines.Length - 1].ContentEnd); while (localProperties.MoveNext()) { var property = localProperties.Current; var dp = property.Property; object value = property.Value; if (!dp.ReadOnly && dp != Inline.TextDecorationsProperty && // Ignore hyperlink defaults. dp != TextElement.ForegroundProperty && dp != BaseUriHelper.BaseUriProperty && !IsHyperlinkProperty(dp)) { inlineRange.ApplyPropertyValue(dp, value); } } // 4. Delete the (empty) hyperlink element. hyperlink.SiblingInlines.Remove(hyperlink); return newCaretPosition; }
// Token: 0x06003B89 RID: 15241 RVA: 0x0010F754 File Offset: 0x0010D954 private static TextPointer GetPositionAfterList(List list) { Invariant.Assert(list != null, "list cannot be null"); TextPointer textPointer = list.ElementEnd.GetInsertionPosition(LogicalDirection.Backward); if (textPointer != null) { textPointer = textPointer.GetNextInsertionPosition(LogicalDirection.Forward); } if (textPointer == null) { textPointer = list.ElementEnd.TextContainer.End; } if (TextRangeEditTables.IsTableStructureCrossed(list.ElementEnd, textPointer)) { textPointer = list.ContentEnd; } return(textPointer); }
public void SetCell(BufferCell cell, TextPointer position, LogicalDirection direction) { TextRange range = null; TextPointer positionPlus = position.GetNextInsertionPosition(LogicalDirection.Forward); if (positionPlus != null) { range = new TextRange(position, positionPlus); } if (null == range || range.IsEmpty) { position = position.GetInsertionPosition(LogicalDirection.Forward); if (position != null) { Run r = position.GetAdjacentElement(LogicalDirection.Forward) as Run; if (null != r) { if (r.Text.Length > 0) { char[] chr = r.Text.ToCharArray(); chr[0] = cell.Character; r.Text = chr.ToString(); } else { r.Text = cell.Character.ToString(); } } else { r = position.GetAdjacentElement(LogicalDirection.Backward) as Run; if (null != r && r.Background == BrushFromConsoleColor(cell.BackgroundColor) && r.Foreground == BrushFromConsoleColor(cell.ForegroundColor) ) { if (r.Text.Length > 0) { r.Text = r.Text + cell.Character; } else { r.Text = cell.Character.ToString(); } } else { r = new Run(cell.Character.ToString(), position); } } r.Background = BrushFromConsoleColor(cell.BackgroundColor); r.Foreground = BrushFromConsoleColor(cell.ForegroundColor); //position = r.ElementStart; } } else { range.Text = cell.Character.ToString(); range.ApplyPropertyValue(TextElement.BackgroundProperty, BrushFromConsoleColor(cell.BackgroundColor)); range.ApplyPropertyValue(TextElement.ForegroundProperty, BrushFromConsoleColor(cell.ForegroundColor)); } }
internal static int GetColumnNumberFromSelection(TextPointer position) { if (position == null) { return 0; } int linesMoved; TextPointer lineStartPosition = position.GetLineStartPosition(0, out linesMoved); int columnNumber = 0; do { columnNumber++; position = position.GetNextInsertionPosition(LogicalDirection.Backward); } while (position != null && position.CompareTo(lineStartPosition) > 0); return columnNumber; }
public static string GetSentenceFromPosition(RichTextBox rtb, TextPointer position) { string sentence = string.Empty; while (true) { string c = GetCharacterAtPosition(rtb, position); sentence += c; if (c.Equals(".")) break; position = position.GetNextInsertionPosition(LogicalDirection.Forward); if (position == null) break; } return (sentence); }