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


C# VisualLine.GetVisualColumn方法代码示例

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


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

示例1: RevalidateVisualColumn

		/// <summary>
		/// Validates the visual column of the caret using the specified visual line.
		/// The visual line must contain the caret offset.
		/// </summary>
		void RevalidateVisualColumn(VisualLine visualLine)
		{
			if (visualLine == null)
				throw new ArgumentNullException("visualLine");
			
			// mark column as validated
			visualColumnValid = true;
			
			int caretOffset = textView.Document.GetOffset(position);
			int firstDocumentLineOffset = visualLine.FirstDocumentLine.Offset;
			if (position.VisualColumn < 0) {
				position.VisualColumn = visualLine.GetVisualColumn(caretOffset - firstDocumentLineOffset);
			} else {
				int offsetFromVisualColumn = visualLine.GetRelativeOffset(position.VisualColumn);
				offsetFromVisualColumn += firstDocumentLineOffset;
				if (offsetFromVisualColumn != caretOffset) {
					position.VisualColumn = visualLine.GetVisualColumn(caretOffset - firstDocumentLineOffset);
				} else {
					if (position.VisualColumn > visualLine.VisualLength) {
						position.VisualColumn = visualLine.VisualLength;
					}
				}
			}
			// search possible caret positions
			int newVisualColumnForwards = visualLine.GetNextCaretPosition(position.VisualColumn - 1, LogicalDirection.Forward, CaretPositioningMode.Normal);
			// If position.VisualColumn was valid, we're done with validation.
			if (newVisualColumnForwards != position.VisualColumn) {
				// also search backwards so that we can pick the better match
				int newVisualColumnBackwards = visualLine.GetNextCaretPosition(position.VisualColumn + 1, LogicalDirection.Backward, CaretPositioningMode.Normal);
				
				if (newVisualColumnForwards < 0 && newVisualColumnBackwards < 0)
					throw ThrowUtil.NoValidCaretPosition();
				
				// determine offsets for new visual column positions
				int newOffsetForwards;
				if (newVisualColumnForwards >= 0)
					newOffsetForwards = visualLine.GetRelativeOffset(newVisualColumnForwards) + firstDocumentLineOffset;
				else
					newOffsetForwards = -1;
				int newOffsetBackwards;
				if (newVisualColumnBackwards >= 0)
					newOffsetBackwards = visualLine.GetRelativeOffset(newVisualColumnBackwards) + firstDocumentLineOffset;
				else
					newOffsetBackwards = -1;
				
				int newVisualColumn, newOffset;
				// if there's only one valid position, use it
				if (newVisualColumnForwards < 0) {
					newVisualColumn = newVisualColumnBackwards;
					newOffset = newOffsetBackwards;
				} else if (newVisualColumnBackwards < 0) {
					newVisualColumn = newVisualColumnForwards;
					newOffset = newOffsetForwards;
				} else {
					// two valid positions: find the better match
					if (Math.Abs(newOffsetBackwards - caretOffset) < Math.Abs(newOffsetForwards - caretOffset)) {
						// backwards is better
						newVisualColumn = newVisualColumnBackwards;
						newOffset = newOffsetBackwards;
					} else {
						// forwards is better
						newVisualColumn = newVisualColumnForwards;
						newOffset = newOffsetForwards;
					}
				}
				this.Position = new TextViewPosition(textView.Document.GetLocation(newOffset), newVisualColumn);
			}
		}
开发者ID:SiGhTfOrbACQ,项目名称:O2.Platform.Projects,代码行数:72,代码来源:Caret.cs

示例2: RevalidateVisualColumn

        /// <summary>
        /// Validates the visual column of the caret using the specified visual line.
        /// The visual line must contain the caret offset.
        /// </summary>
        void RevalidateVisualColumn(VisualLine visualLine)
        {
            if (visualLine == null)
                throw new ArgumentNullException("visualLine");

            // mark column as validated
            visualColumnValid = true;

            int caretOffset = textView.Document.GetOffset(position);
            int firstDocumentLineOffset = visualLine.FirstDocumentLine.Offset;
            if (position.VisualColumn < 0) {
                position.VisualColumn = visualLine.GetVisualColumn(caretOffset - firstDocumentLineOffset);
            } else {
                int offsetFromVisualColumn = visualLine.GetRelativeOffset(position.VisualColumn);
                offsetFromVisualColumn += firstDocumentLineOffset;
                if (offsetFromVisualColumn != caretOffset) {
                    position.VisualColumn = visualLine.GetVisualColumn(caretOffset - firstDocumentLineOffset);
                } else {
                    if (position.VisualColumn > visualLine.VisualLength) {
                        position.VisualColumn = visualLine.VisualLength;
                    }
                }
            }
            // search possible caret position (first try forwards)
            int newVisualColumn = visualLine.GetNextCaretPosition(position.VisualColumn - 1, LogicalDirection.Forward, CaretPositioningMode.Normal);
            if (newVisualColumn < 0) {
                // then try backwards
                newVisualColumn = visualLine.GetNextCaretPosition(position.VisualColumn + 1, LogicalDirection.Backward, CaretPositioningMode.Normal);
            }
            if (newVisualColumn < 0)
                throw ThrowUtil.NoValidCaretPosition();
            if (newVisualColumn != position.VisualColumn) {
                int newOffset = visualLine.GetRelativeOffset(newVisualColumn) + firstDocumentLineOffset;
                this.Position = new TextViewPosition(textView.Document.GetLocation(newOffset), newVisualColumn);
            }
        }
开发者ID:kjk,项目名称:kjkpub,代码行数:40,代码来源:Caret.cs


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