Page 1 of 1

Code folding and text selections

Posted: Sun Dec 22, 2013 12:07 am
by aphor
I'm not sure if this should be here or under the bugs topic. Feel free to relocate this if I chose wrong...

I found a problem with my SlideIn/Out scripts that also appears to affect Add/Remove Comments. comment_range() appears to work on display line, not file line:

For example, if I have

Code: Select all

public class Bob
{
    bool SomeFunction()
    {
        return(true);
    }

    bool AnotherFunction()
    {
        return(true);
    }
}
and fold SomeFunction() so AnotherFunction begins on display line 6 like so:

Code: Select all

public class Bob
{
    bool SomeFunction()
    { ... }

    bool AnotherFunction()
    {
        return(true);
    }

}
then select the text of the entire AnotherFunction() and execute Macros->Add/Remove Comments, the resulting text is:

Code: Select all

public class Bob
{
    bool SomeFunction()
    {
        return(true);
    // }
    // 
    // bool AnotherFunction()
    // {
        return(true);
    }

}
I initially thought this was going to be related to get_marked_top() and get_marked_bottom(), but I when I put together the simplest test I could think of:

Code: Select all

function key_macro()
    message
    (
        string.format
        (
            "Selected range [%d:%d]. Current line: %d",
            get_marked_top(),
            get_marked_bottom(),
            get_line_pos()
        )
    );
end

key_macro() -- run the macro
It correctly displays the selected line numbers regardless of fold state. If I include the folded text in the selection (i.e. same fold as above, but attempt to comment out both methods), commenting works correctly.

I've run out of time to look at this today, but thought I'd post here in case you have an immediate idea where the problem is.

Thanks!

Posted: Sun Dec 22, 2013 1:03 am
by aphor
Okay, so I can't walk away from an unresolved problem...

I believe set_line_pos() is the culprit here.

Code: Select all

function key_macro()
    local lineToSet = get_marked_top()
    set_line_pos(lineToSet)

    message
    (
        string.format
        (
            "Selected range [%d:%d]. Current line: %d",
            get_marked_top(),
            get_marked_bottom(),
            get_line_pos()
        )
    );
end

key_macro() -- run the macro
run against the example folded example code with "AnotherFunction()" as the selected text will show:

Code: Select all

Selected range [8:8] Current line: 6
A simple loop around set_line_pos() to make corrections should solve my problem (that really will wait until later), but having set_line_pos() behave as expected would be even better. :)

Posted: Sun Dec 22, 2013 1:08 am
by jussij
I believe set_line_pos() is the culprit here.

That does indeed look like the problem.

Using your test file this simple macro adds the string to the wrong line !!!

Code: Select all

function key_macro()
    screen_update_disable()
    -- should add the string to this line of the test file
    -- bool AnotherFunction()
    set_line_pos(8)
    MoveLineHome()
    print("Start of line: ")
    screen_update_enable()
    screen_update()
end

key_macro() -- run the macro
I will look to get that fixed ASAP.

Thanks for submitting the bug report :)

Cheers Jussi

Posted: Sun Dec 22, 2013 7:50 am
by aphor
Thanks!

Posted: Sun Dec 29, 2013 1:10 pm
by jussij
This folding issue should be fixed in the beta version found here: http://www.zeusedit.com/z300/ze397r-beta.zip

To use the files in this zip file just make a backup copy of the Zeus install folder and replace the files contained in that folder with the ones in the zip file.

Cheers Jussi

Posted: Thu Jan 02, 2014 9:46 pm
by aphor
Your test macro

Code: Select all

function key_macro() 
    screen_update_disable() 
    -- should add the string to this line of the test file 
    -- bool AnotherFunction() 
    set_line_pos(8) 
    MoveLineHome() 
    print("Start of line: ") 
    screen_update_enable() 
    screen_update() 
end 

key_macro() -- run the macro
works correctly with the change, but "Add/Remove Comments" and my Slide In/Out scripts still behave incorrectly. (Same behavior as decsribed above).

A bit of investigation makes me believe the problem is either in comment_range() or comment_line() [if I just call "print" in my script, it works as expected], but I don't see an obvious cause. I'll look at it more tonight.

Thanks!

Posted: Fri Jan 03, 2014 12:34 pm
by jussij
Thanks for the feedback :)

The problem was with the set_cursor_pos macro function in that just like the set_line_pos macro function it was not accounting for handling the folded lines.

The new beta version from the link below should fix this issue: http://www.zeusedit.com/z300/ze397r-beta.zip

Cheers Jussi

Posted: Fri Jan 03, 2014 8:36 pm
by aphor
Confirmed fixed. Thanks!