FromByteOffset() public static method

Find the text location for a byte offset.

If the offset happens to land in the middle of a multi-byte character, this function will return a text location pointing to the character that begins just prior to the offset.

If the offset is before the start of the document (a negative number), then a location pointing to the start of the document will be returned.

If the offset is after the end of the document, then a location pointing to the end of the document will be returned.

public static FromByteOffset ( int offset ) : TextLocation
offset int The zero-based byte offset to find.
return TextLocation
Example #1
0
        /// <summary>
        /// Finds the position closest to a point on the screen.
        /// </summary>
        /// <param name="pt">The client coordinates of the point to test.</param>
        /// <param name="location">An out parameter to receive the found location.</param>
        /// <returns>
        /// If no character is close, or the point is outside the window, this function returns
        /// false, and the location parameter is set to the start of the document.
        /// If a location was found, this function returns true, and the location parameter is set
        /// to the close position.
        /// </returns>
        public bool PointToPosClose(Point pt, out TextLocation location)
        {
            int offset = Plugin.NppIntf.PointToPosClose(pt);

            if (offset < 0)
            {
                location = TextLocation.Start;
                return(false);
            }
            location = TextLocation.FromByteOffset(offset);
            return(true);
        }
Example #2
0
 /// <summary>
 /// Finds the position closest to a point on the screen.
 /// </summary>
 /// <param name="pt">The client coordinates of the point to test.</param>
 /// <returns>The zero-based position of the closest character.</returns>
 public TextLocation PointToPos(Point pt)
 {
     return(TextLocation.FromByteOffset(Plugin.NppIntf.PointToPos(pt)));
 }
Example #3
0
 /// <summary>
 /// Gets the position that corresponds to a line and column.
 /// </summary>
 /// <param name="line">The one-based line number.</param>
 /// <param name="column">The one-based column number.</param>
 /// <returns>The zero-based position.</returns>
 public TextLocation FindColumn(int line, int column)
 {
     return(TextLocation.FromByteOffset(Plugin.NppIntf.FindColumn(line, column)));
 }
Example #4
0
 /// <summary>
 /// Gets the ending position of the specified line, before any line-end characters.
 /// </summary>
 /// <param name="line">The one-based line number.</param>
 /// <returns>The end position of the line.</returns>
 public TextLocation GetLineEndPos(int line)
 {
     return(TextLocation.FromByteOffset(Plugin.NppIntf.GetLineEndPos(line)));
 }
Example #5
0
 /// <summary>
 /// Decrements the location by 1 character position.
 /// </summary>
 /// <param name="loc">The location object.</param>
 /// <returns>A new location object containing the decremented location.</returns>
 public static TextLocation operator --(TextLocation loc)
 {
     return(TextLocation.FromByteOffset(Plugin.NppIntf.MoveOffsetByChars(loc.ByteOffset, 1)));
 }
Example #6
0
 /// <summary>
 /// Moves the text location by a specified number of characters.
 /// </summary>
 /// <param name="loc">The origin location.</param>
 /// <param name="dist">The number of characters to move.</param>
 /// <returns>A new location object representing the moved location.</returns>
 public static TextLocation operator +(TextLocation loc, int dist)
 {
     return(TextLocation.FromByteOffset(Plugin.NppIntf.MoveOffsetByChars(loc.ByteOffset, dist)));
 }