Skip to content

Off-by one bug in GetSnapshotPositionForTextPoint method #902

Description

@carlos-quintero

In the CodeMaidShared/Helpers/TextDocumentHelper.cs file (https://github.com/codecadwallader/codemaid/blob/dev/CodeMaidShared/Helpers/TextDocumentHelper.cs), the method GetSnapshotPositionForTextPoint has an off-by-one bug, since textPoint.LineCharOffset is 1-based (https://docs.microsoft.com/en-us/dotnet/api/envdte.textpoint.linecharoffset?view=visualstudiosdk-2022#remarks):

private static int GetSnapshotPositionForTextPoint(ITextSnapshot textSnapshot, TextPoint textPoint)
{
   ThreadHelper.ThrowIfNotOnUIThread();

   var textSnapshotLine = textSnapshot.GetLineFromLineNumber(textPoint.Line - 1);
   return textSnapshotLine.Start.Position + textPoint.LineCharOffset;  // missing to substract 1
}

The reverse GetEditPointForSnapshotPosition method is fine, though, since it adds +1 to return the textPoint.LineCharOffset value.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions