Setting TextRange in ASTNode gives wrong length?

SyntaxEditor for Windows Forms Forum

Posted 11 years ago by Martin de Jong - Statistics Netherlands
Version: 4.0.0276
Avatar
When i create a node and change the Textrange the length value is one short. Sample for a Node with offsets 1 till 5 ( 5 long):

    public partial class TestNode : ActiproSoftware.SyntaxEditor.AstNodeBase    {

        public TestNode(ActiproSoftware.SyntaxEditor.TextRange range) : base(range) { }
        public TestNode() : base() { }

        public static void DoTest1() {
            TestNode node = new TestNode();
            node.TextRange = new ActiproSoftware.SyntaxEditor.TextRange(1, 5);
            Debug.Write(node.Length);
                        
        }
        public static void DoTest2() {
            TestNode node = new TestNode(new ActiproSoftware.SyntaxEditor.TextRange(1, 5));
            Debug.Write(node.Length);
        }

        public override int ContextID {
            get {
                throw new NotImplementedException();
            }
            set {
                throw new NotImplementedException();
            }
        }
    }
Both DoTestx() report value 4.

Comments (1)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
That is correct and by design. There are two ways to do offsets:

1) Offset/length combination. So in your case, you'd want offset = 1, length = 5.
2) TextRange. Text ranges "encompass" the given offsets. So to wrap 5 characters in your case, you'd want to do a TextRange of {1,6}, which means from the start of the character at offset 1 through the START of the character at offset 6 (but not including the character at offset 6).


Actipro Software Support

The latest build of this product (v2018.1 build 0342) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.