icecoder/ICEcoder

Go To Line - Incorrect Jump

Closed this issue · 7 comments

Hi, I'm using v8.0. If a code block is collapsed, it seems that the "go to line" feature incorrectly jumps to a different line. Thank you so much for your hard work on this. I've been a user and fan since 5.x

Hmmm I'm just not able to reproduce this. If a code block is folded (eg lines 10 - 25) and you begin typing a line number in the go to line input box (eg 16) it unfolds it and highlights the line (16) and on hitting Enter focuses the cursor on that line (16).

If it's something you can reliably reproduce, could you let me know the exact keys you're pressing and maybe also include a short video of the issue in action?

Thanks and glad to hear you've been a fan for a while :-)

@mattpass here's the link to the video https://filebin.net/kr4uls7aqdma77xj

In that link, I also included the screenshot of the icecoder and system version which might help in debugging

just found out that the incorrect jump also happens if I enter a text in the "find" text box. As for the keys I'm pressing, I am just pressing what can be seen in the video (keys to enter the go to line number and find text)

BTW, the link expires within a week. Let me know if I should upload it again.

I can confirm: it selects correct line but scrolls to the incorrect line if some code elements collapsed.
Browser: Chrome 87 on MacOs 11.1

The error is in icecoder.js (L1172-L1178)

        this.scrollInt = setInterval(function(ic) {
            ic.scrollingOnLine = ic.scrollingOnLine + ((lineNo - ic.scrollingOnLine) / 5);
            thisCM.scrollTo(0, (thisCM.defaultTextHeight() * ic.scrollingOnLine) - (thisCM.getScrollInfo().clientHeight / 10));
            if (lineNo === Math.round(ic.scrollingOnLine)) {
                clearInterval(ic.scrollInt);
            }
        }, 10, this);

Thanks @raymondsalas - the video helped explain what's going wrong here.

As you pointed out @VladimirAus - the error is in that chunk of code, specifically:
thisCM.scrollTo(0, (thisCM.defaultTextHeight() * ic.scrollingOnLine) - (thisCM.getScrollInfo().clientHeight / 10)); with the problem being thisCM.defaultTextHeight() * ic.scrollingOnLine logic not considering any collapsed sections.

What's happening: If you have a default text height of 13px and type 540, it'll scroll to 7020px down and so 540 is in view. That works fine if no code is collapsed. However, if sections of code are collapsed, it'll still want to scroll to 7020px down and likely scrolls past your line. It's taking into account the collapsed sections.

ie, if you have 1000 lines in your file, collapse 300, it should scroll to 540 * 0.7 to put it into view.

I'll look onto some amends to account for collapsed sections. Thanks!

OK - fixed! 12a53d4

The solution wasn't what I thought it'd be (above), had to use some undocumented info in CodeMirror plus consider performance, nested folds plus your requested line and it's relation to the folds (before or after folds).

Seems to work great though and fast! Have a look and let me know if any problems?

Thank you so much @mattpass ! Confirming that per initial testing, both Go To Line and Find works as expected even if there are folds in the code. I'll report if I find other issues.