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


C# CaretPositioningMode类代码示例

本文整理汇总了C#中CaretPositioningMode的典型用法代码示例。如果您正苦于以下问题:C# CaretPositioningMode类的具体用法?C# CaretPositioningMode怎么用?C# CaretPositioningMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GetNextCaretPosition

 /// <inheritdoc/>
 public override int GetNextCaretPosition(int visualColumn, LogicalDirection direction, CaretPositioningMode mode)
 {
     int textOffset = parentVisualLine.StartOffset + this.RelativeTextOffset;
     int pos = TextUtilities.GetNextCaretPosition(parentVisualLine.Document, textOffset + visualColumn - this.VisualColumn, direction, mode);
     if (pos < textOffset || pos > textOffset + this.DocumentLength)
         return -1;
     else
         return this.VisualColumn + pos - textOffset;
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:10,代码来源:VisualLineText.cs

示例2: GetNextCaretPosition

			public override int GetNextCaretPosition(int visualColumn, LogicalDirection direction, CaretPositioningMode mode)
			{
				// only place a caret stop before the newline, no caret stop after it
				if (visualColumn > this.VisualColumn && direction == LogicalDirection.Backward ||
				    visualColumn < this.VisualColumn && direction == LogicalDirection.Forward)
				{
					return this.VisualColumn;
				} else {
					return -1;
				}
			}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:11,代码来源:NewLineElementGenerator.cs

示例3: GetNextCaretPosition

 public override int GetNextCaretPosition(int visualColumn, LogicalDirection direction, CaretPositioningMode mode)
 {
     if (mode == CaretPositioningMode.Normal || mode == CaretPositioningMode.EveryCodepoint)
         return base.GetNextCaretPosition(visualColumn, direction, mode);
     else
         return -1;
 }
开发者ID:JackWangCUMT,项目名称:AvalonEdit,代码行数:7,代码来源:SingleCharacterElementGenerator.cs

示例4: GetNextCaretPosition

			public override int GetNextCaretPosition(int visualColumn, bool backwords, CaretPositioningMode mode)
			{
				return base.GetNextCaretPosition(visualColumn, backwords, mode);
			}
开发者ID:chinax01,项目名称:x01.MelonEditor,代码行数:4,代码来源:NewLineElementGenerator.cs

示例5: GetNextCaretPosition

		static TextViewPosition GetNextCaretPosition(TextView textView, TextViewPosition caretPosition, VisualLine visualLine, CaretPositioningMode mode, bool enableVirtualSpace)
		{
			int pos = visualLine.GetNextCaretPosition(caretPosition.VisualColumn, LogicalDirection.Forward, mode, enableVirtualSpace);
			if (pos >= 0) {
				return visualLine.GetTextViewPosition(pos);
			} else {
				// move to start of next line
				DocumentLine nextDocumentLine = visualLine.LastDocumentLine.NextLine;
				if (nextDocumentLine != null) {
					VisualLine nextLine = textView.GetOrConstructVisualLine(nextDocumentLine);
					pos = nextLine.GetNextCaretPosition(-1, LogicalDirection.Forward, mode, enableVirtualSpace);
					if (pos < 0)
						throw ThrowUtil.NoValidCaretPosition();
					return nextLine.GetTextViewPosition(pos);
				} else {
					// at end of document
					Debug.Assert(visualLine.LastDocumentLine.Offset + visualLine.LastDocumentLine.TotalLength == textView.Document.TextLength);
					return new TextViewPosition(textView.Document.GetLocation(textView.Document.TextLength));
				}
			}
		}
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:21,代码来源:CaretNavigationCommandHandler.cs

示例6: GetNextCaretPosition

        /// <summary>
        /// Gets the next caret position.
        /// </summary>
        /// <param name="textSource">The text source.</param>
        /// <param name="offset">The start offset inside the text source.</param>
        /// <param name="direction">The search direction (forwards or backwards).</param>
        /// <param name="mode">The mode for caret positioning.</param>
        /// <returns>The offset of the next caret position, or -1 if there is no further caret position
        /// in the text source.</returns>
        /// <remarks>
        /// This method is NOT equivalent to the actual caret movement when using VisualLine.GetNextCaretPosition.
        /// In real caret movement, there are additional caret stops at line starts and ends. This method
        /// treats linefeeds as simple whitespace.
        /// </remarks>
        public static int GetNextCaretPosition(ITextSource textSource, int offset, LogicalDirection direction, CaretPositioningMode mode)
        {
            if (textSource == null)
                throw new ArgumentNullException(nameof(textSource));
            if (mode != CaretPositioningMode.Normal
                && mode != CaretPositioningMode.WordBorder
                && mode != CaretPositioningMode.WordStart
                && mode != CaretPositioningMode.WordBorderOrSymbol
                && mode != CaretPositioningMode.WordStartOrSymbol)
            {
                throw new ArgumentException("Unsupported CaretPositioningMode: " + mode, nameof(mode));
            }
            if (direction != LogicalDirection.Backward
                && direction != LogicalDirection.Forward)
            {
                throw new ArgumentException("Invalid LogicalDirection: " + direction, nameof(direction));
            }
            int textLength = textSource.TextLength;
            if (textLength <= 0)
            {
                // empty document? has a normal caret position at 0, though no word borders
                if (mode == CaretPositioningMode.Normal)
                {
                    if (offset > 0 && direction == LogicalDirection.Backward) return 0;
                    if (offset < 0 && direction == LogicalDirection.Forward) return 0;
                }
                return -1;
            }
            while (true)
            {
                int nextPos = (direction == LogicalDirection.Backward) ? offset - 1 : offset + 1;

                // return -1 if there is no further caret position in the text source
                // we also need this to handle offset values outside the valid range
                if (nextPos < 0 || nextPos > textLength)
                    return -1;

                // stop at every caret position? we can stop immediately.
                if (mode == CaretPositioningMode.Normal)
                    return nextPos;
                // not normal mode? we're looking for word borders...

                // check if we've run against the textSource borders.
                // a 'textSource' usually isn't the whole document, but a single VisualLineElement.
                if (nextPos == 0)
                {
                    // at the document start, there's only a word border
                    // if the first character is not whitespace
                    if (!char.IsWhiteSpace(textSource.GetCharAt(0)))
                        return nextPos;
                }
                else if (nextPos == textLength)
                {
                    // at the document end, there's never a word start
                    if (mode != CaretPositioningMode.WordStart && mode != CaretPositioningMode.WordStartOrSymbol)
                    {
                        // at the document end, there's only a word border
                        // if the last character is not whitespace
                        if (!char.IsWhiteSpace(textSource.GetCharAt(textLength - 1)))
                            return nextPos;
                    }
                }
                else
                {
                    CharacterClass charBefore = GetCharacterClass(textSource.GetCharAt(nextPos - 1));
                    CharacterClass charAfter = GetCharacterClass(textSource.GetCharAt(nextPos));
                    if (charBefore == charAfter)
                    {
                        if (charBefore == CharacterClass.Other &&
                            (mode == CaretPositioningMode.WordBorderOrSymbol || mode == CaretPositioningMode.WordStartOrSymbol))
                        {
                            // With the "OrSymbol" modes, there's a word border and start between any two unknown characters
                            return nextPos;
                        }
                    }
                    else
                    {
                        // this looks like a possible border

                        // if we're looking for word starts, check that this is a word start (and not a word end)
                        // if we're just checking for word borders, accept unconditionally
                        if (!((mode == CaretPositioningMode.WordStart || mode == CaretPositioningMode.WordStartOrSymbol)
                              && (charAfter == CharacterClass.Whitespace || charAfter == CharacterClass.LineTerminator)))
                        {
                            return nextPos;
                        }
//.........这里部分代码省略.........
开发者ID:arkanoid1,项目名称:Yanitta,代码行数:101,代码来源:TextUtilities.cs

示例7: ExpandToEnclosingUnit

 private void ExpandToEnclosingUnit(CaretPositioningMode mode)
 {
     int start = TextUtilities.GetNextCaretPosition(doc, segment.Offset + 1, LogicalDirection.Backward, mode);
     if (start < 0)
         return;
     int end = TextUtilities.GetNextCaretPosition(doc, start, LogicalDirection.Forward, mode);
     if (end < 0)
         return;
     segment = new AnchorSegment(doc, start, end - start);
 }
开发者ID:svgorbunov,项目名称:AvalonEdit,代码行数:10,代码来源:TextRangeProvider.cs

示例8: HasImplicitStopAtLineStart

 static bool HasImplicitStopAtLineStart(CaretPositioningMode mode)
 {
     return mode == CaretPositioningMode.Normal;
 }
开发者ID:eolandezhang,项目名称:Diagram,代码行数:4,代码来源:VisualLine.cs

示例9: GetNextCaretPosition

        /// <summary>
        /// Gets the next possible caret position after visualColumn, or -1 if there is no caret position.
        /// </summary>
        public int GetNextCaretPosition(int visualColumn, LogicalDirection direction, CaretPositioningMode mode, bool allowVirtualSpace)
        {
            if (!HasStopsInVirtualSpace(mode))
                allowVirtualSpace = false;

            if (elements.Count == 0) {
                // special handling for empty visual lines:
                if (allowVirtualSpace) {
                    if (direction == LogicalDirection.Forward)
                        return Math.Max(0, visualColumn + 1);
                    else if (visualColumn > 0)
                        return visualColumn - 1;
                    else
                        return -1;
                } else {
                    // even though we don't have any elements,
                    // there's a single caret stop at visualColumn 0
                    if (visualColumn < 0 && direction == LogicalDirection.Forward)
                        return 0;
                    else if (visualColumn > 0 && direction == LogicalDirection.Backward)
                        return 0;
                    else
                        return -1;
                }
            }

            int i;
            if (direction == LogicalDirection.Backward) {
                // Search Backwards:
                // If the last element doesn't handle line borders, return the line end as caret stop

                if (visualColumn > this.VisualLength && !elements[elements.Count-1].HandlesLineBorders && HasImplicitStopAtLineEnd(mode)) {
                    if (allowVirtualSpace)
                        return visualColumn - 1;
                    else
                        return this.VisualLength;
                }
                // skip elements that start after or at visualColumn
                for (i = elements.Count - 1; i >= 0; i--) {
                    if (elements[i].VisualColumn < visualColumn)
                        break;
                }
                // search last element that has a caret stop
                for (; i >= 0; i--) {
                    int pos = elements[i].GetNextCaretPosition(
                        Math.Min(visualColumn, elements[i].VisualColumn + elements[i].VisualLength + 1),
                        direction, mode);
                    if (pos >= 0)
                        return pos;
                }
                // If we've found nothing, and the first element doesn't handle line borders,
                // return the line start as normal caret stop.
                if (visualColumn > 0 && !elements[0].HandlesLineBorders && HasImplicitStopAtLineStart(mode))
                    return 0;
            } else {
                // Search Forwards:
                // If the first element doesn't handle line borders, return the line start as caret stop
                if (visualColumn < 0 && !elements[0].HandlesLineBorders && HasImplicitStopAtLineStart(mode))
                    return 0;
                // skip elements that end before or at visualColumn
                for (i = 0; i < elements.Count; i++) {
                    if (elements[i].VisualColumn + elements[i].VisualLength > visualColumn)
                        break;
                }
                // search first element that has a caret stop
                for (; i < elements.Count; i++) {
                    int pos = elements[i].GetNextCaretPosition(
                        Math.Max(visualColumn, elements[i].VisualColumn - 1),
                        direction, mode);
                    if (pos >= 0)
                        return pos;
                }
                // if we've found nothing, and the last element doesn't handle line borders,
                // return the line end as caret stop
                if ((allowVirtualSpace || !elements[elements.Count-1].HandlesLineBorders) && HasImplicitStopAtLineEnd(mode)) {
                    if (visualColumn < this.VisualLength)
                        return this.VisualLength;
                    else if (allowVirtualSpace)
                        return visualColumn + 1;
                }
            }
            // we've found nothing, return -1 and let the caret search continue in the next line
            return -1;
        }
开发者ID:eolandezhang,项目名称:Diagram,代码行数:87,代码来源:VisualLine.cs

示例10: MoveCaretRight

 static void MoveCaretRight(TextArea textArea, TextViewPosition caretPosition, VisualLine visualLine, CaretPositioningMode mode)
 {
     int pos = visualLine.GetNextCaretPosition(caretPosition.VisualColumn, LogicalDirection.Forward, mode);
     if (pos >= 0) {
         SetCaretPosition(textArea, pos, visualLine.GetRelativeOffset(pos) + visualLine.FirstDocumentLine.Offset);
     } else {
         // move to start of next line
         DocumentLine nextDocumentLine = visualLine.LastDocumentLine.NextLine;
         if (nextDocumentLine != null) {
             VisualLine nextLine = textArea.TextView.GetOrConstructVisualLine(nextDocumentLine);
             pos = nextLine.GetNextCaretPosition(-1, LogicalDirection.Forward, mode);
             if (pos < 0)
                 throw ThrowUtil.NoValidCaretPosition();
             SetCaretPosition(textArea, pos, nextLine.GetRelativeOffset(pos) + nextLine.FirstDocumentLine.Offset);
         } else {
             // at end of document
             Debug.Assert(visualLine.LastDocumentLine.Offset + visualLine.LastDocumentLine.TotalLength == textArea.Document.TextLength);
             SetCaretPosition(textArea, -1, textArea.Document.TextLength);
         }
     }
 }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:21,代码来源:CaretNavigationCommandHandler.cs

示例11: MoveCaretLeft

 static void MoveCaretLeft(TextArea textArea, TextViewPosition caretPosition, VisualLine visualLine, CaretPositioningMode mode)
 {
     int pos = visualLine.GetNextCaretPosition(caretPosition.VisualColumn, LogicalDirection.Backward, mode);
     if (pos >= 0) {
         SetCaretPosition(textArea, pos, visualLine.GetRelativeOffset(pos) + visualLine.FirstDocumentLine.Offset);
     } else {
         // move to end of previous line
         DocumentLine previousDocumentLine = visualLine.FirstDocumentLine.PreviousLine;
         if (previousDocumentLine != null) {
             VisualLine previousLine = textArea.TextView.GetOrConstructVisualLine(previousDocumentLine);
             pos = previousLine.GetNextCaretPosition(previousLine.VisualLength + 1, LogicalDirection.Backward, mode);
             if (pos < 0)
                 throw ThrowUtil.NoValidCaretPosition();
             SetCaretPosition(textArea, pos, previousLine.GetRelativeOffset(pos) + previousLine.FirstDocumentLine.Offset);
         } else {
             // at start of document
             Debug.Assert(visualLine.FirstDocumentLine.Offset == 0);
             SetCaretPosition(textArea, 0, 0);
         }
     }
 }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:21,代码来源:CaretNavigationCommandHandler.cs

示例12: GetNextCaretPosition

		public int GetNextCaretPosition(int visualColumn, bool backwords, CaretPositioningMode mode) 
		{ 
			//TODO: VisualLine.GetNextCaretPosition()
			throw new NotImplementedException();
		}
开发者ID:chinax01,项目名称:x01.MelonEditor,代码行数:5,代码来源:VisualLine.cs

示例13: HasImplicitStopAtLineStart

		static bool HasImplicitStopAtLineStart(CaretPositioningMode mode)
		{
			return mode == CaretPositioningMode.Normal || mode == CaretPositioningMode.EveryCodepoint;
		}
开发者ID:bbqchickenrobot,项目名称:AvalonEdit,代码行数:4,代码来源:VisualLine.cs

示例14: HasStopsInVirtualSpace

		static bool HasStopsInVirtualSpace(CaretPositioningMode mode)
		{
			return mode == CaretPositioningMode.Normal || mode == CaretPositioningMode.EveryCodepoint;
		}
开发者ID:bbqchickenrobot,项目名称:AvalonEdit,代码行数:4,代码来源:VisualLine.cs

示例15: GetPrevCaretPosition

		static TextViewPosition GetPrevCaretPosition(TextView textView, TextViewPosition caretPosition, VisualLine visualLine, CaretPositioningMode mode, bool enableVirtualSpace)
		{
			int pos = visualLine.GetNextCaretPosition(caretPosition.VisualColumn, LogicalDirection.Backward, mode, enableVirtualSpace);
			if (pos >= 0) {
				return visualLine.GetTextViewPosition(pos);
			} else {
				// move to end of previous line
				DocumentLine previousDocumentLine = visualLine.FirstDocumentLine.PreviousLine;
				if (previousDocumentLine != null) {
					VisualLine previousLine = textView.GetOrConstructVisualLine(previousDocumentLine);
					pos = previousLine.GetNextCaretPosition(previousLine.VisualLength + 1, LogicalDirection.Backward, mode, enableVirtualSpace);
					if (pos < 0)
						throw ThrowUtil.NoValidCaretPosition();
					return previousLine.GetTextViewPosition(pos);
				} else {
					// at start of document
					Debug.Assert(visualLine.FirstDocumentLine.Offset == 0);
					return new TextViewPosition(0, 0);
				}
			}
		}
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:21,代码来源:CaretNavigationCommandHandler.cs


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