Author Topic: change Go to Line method.  (Read 4905 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
change Go to Line method.
« on: October 23, 2009, 05:41:23 pm »
Is it possible to change the function like this

Code
void cbEditor::GotoLine(int line, bool centerOnScreen)
{
    cbStyledTextCtrl* control = GetControl();

    // Make sure the line is not folded. This is done before moving to that
    // line because folding may change the lines layout.
    control->EnsureVisible(line);

    // If the line or the following is a fold point it will be unfolded, in this way
    // when the line is a function declaration (or only contains the opening brace of it [yes, that happens sometimes] )
    // the body is shown.
    DoFoldLine(line,0);
    DoFoldLine(line+1,0);

    if (centerOnScreen)
    {
        int onScreen = control->LinesOnScreen() >> 1;
        int firstVisibleLine = control->GetFirstVisibleLine();
        if(line<firstVisibleLine||line>(firstVisibleLine+2*onScreen))
        {
            control->GotoLine(line - onScreen);
            control->GotoLine(line + onScreen);
        }

    }
    control->GotoLine(line);
}

I think this can avoid some screen flash(for me, it is annoying), which means when we just do a small jump, we don't need to center the cursor. :D

Any comments?!? :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.