From 080f1697e97e13461ec6df4d31c8924d01257a1b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 9 Apr 2019 01:47:48 +0300 Subject: MERGE --- .../Tango.Scripting.Editors/TextViewPosition.cs | 158 +++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/TextViewPosition.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors/TextViewPosition.cs') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/TextViewPosition.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/TextViewPosition.cs new file mode 100644 index 000000000..ff7a78e31 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/TextViewPosition.cs @@ -0,0 +1,158 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Globalization; +using Tango.Scripting.Editors.Document; + +namespace Tango.Scripting.Editors +{ + /// + /// Represents a text location with a visual column. + /// + public struct TextViewPosition : IEquatable + { + int line, column, visualColumn; + + /// + /// Gets/Sets Location. + /// + public TextLocation Location { + get { + return new TextLocation(line, column); + } + set { + line = value.Line; + column = value.Column; + } + } + + /// + /// Gets/Sets the line number. + /// + public int Line { + get { return line; } + set { line = value; } + } + + /// + /// Gets/Sets the (text) column number. + /// + public int Column { + get { return column; } + set { column = value; } + } + + /// + /// Gets/Sets the visual column number. + /// Can be -1 (meaning unknown visual column). + /// + public int VisualColumn { + get { return visualColumn; } + set { visualColumn = value; } + } + + /// + /// Creates a new TextViewPosition instance. + /// + public TextViewPosition(int line, int column, int visualColumn) + { + this.line = line; + this.column = column; + this.visualColumn = visualColumn; + } + + /// + /// Creates a new TextViewPosition instance. + /// + public TextViewPosition(int line, int column) + : this(line, column, -1) + { + } + + /// + /// Creates a new TextViewPosition instance. + /// + public TextViewPosition(TextLocation location, int visualColumn) + { + this.line = location.Line; + this.column = location.Column; + this.visualColumn = visualColumn; + } + + /// + /// Creates a new TextViewPosition instance. + /// + public TextViewPosition(TextLocation location) + : this(location, -1) + { + } + + /// + public override string ToString() + { + return string.Format(CultureInfo.InvariantCulture, + "[TextViewPosition Line={0} Column={1} VisualColumn={2}]", + this.line, this.column, this.visualColumn); + } + + /// + /// Implicit conversion to . + /// + [Obsolete("Use the Location property instead of the implicit conversion to TextLocation")] + public static implicit operator TextLocation(TextViewPosition position) + { + return new TextLocation(position.Line, position.Column); + } + + #region Equals and GetHashCode implementation + // The code in this region is useful if you want to use this structure in collections. + // If you don't need it, you can just remove the region and the ": IEquatable" declaration. + + /// + public override bool Equals(object obj) + { + if (obj is TextViewPosition) + return Equals((TextViewPosition)obj); // use Equals method below + else + return false; + } + + /// + public override int GetHashCode() + { + int hashCode = 0; + unchecked { + hashCode += 1000000007 * Line.GetHashCode(); + hashCode += 1000000009 * Column.GetHashCode(); + hashCode += 1000000021 * VisualColumn.GetHashCode(); + } + return hashCode; + } + + /// + /// Equality test. + /// + public bool Equals(TextViewPosition other) + { + return this.Line == other.Line && this.Column == other.Column && this.VisualColumn == other.VisualColumn; + } + + /// + /// Equality test. + /// + public static bool operator ==(TextViewPosition left, TextViewPosition right) + { + return left.Equals(right); + } + + /// + /// Inequality test. + /// + public static bool operator !=(TextViewPosition left, TextViewPosition right) + { + return !(left.Equals(right)); // use operator == and negate result + } + #endregion + } +} -- cgit v1.3.1