Esempio n. 1
0
/*
 * GetHiddenBreaks
 */
linenum GetHiddenLineBreaks( linenum s, linenum e )
{
    linenum     curr;
    line        *cline;
    fcb         *cfcb;
    int         i;
    linenum     cnt, s1, e1, tmp;

    if( s > e ) {
        tmp = s;
        s = e;
        e = tmp;
    }
    cnt = 0L;
    curr = s;
    while( curr <=e ) {
        i = CGimmeLinePtr( curr, &cfcb, &cline );
        if( i ) {
            break;
        }
        if( cline->u.ld.hidden ) {
            GetHiddenRange( curr, &s1, &e1 );
            curr = e1 + 1;
            cnt++;
        } else {
            curr++;
        }
    }
    return( cnt );

} /* GetHiddenLineBreaks */
Esempio n. 2
0
/*
 * goToLine - go to a specified line number
 */
static vi_rc goToLine( linenum lineno, bool relcurs )
{
    int         text_lines, tl;
    linenum     diff, cwl, nwl;
//    linenum   s, e, hiddcnt;
    bool        dispall, pageshift;
    fcb         *cfcb;
    line        *cline;
    int         pad;
    vi_rc       rc;

    if( lineno < 1 ) {
        return( ERR_NO_SUCH_LINE );
    }

    /*
     * get pointer to requested line
     */
    rc = CGimmeLinePtr( lineno, &cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
#if 0
    if( cline->u.ld.hidden ) {
        GetHiddenRange( lineno, &s, &e );
        if( lineno > CurrentPos.line ) {
            lineno = e + 1;
        } else {
            lineno = s - 1;
        }
        rc = CGimmeLinePtr( lineno, &cfcb, &cline );
        if( rc != ERR_NO_ERR ) {
            return( rc );
        }
    }
#endif

    /*
     * compute new location
     */
    CurrentFcb = cfcb;
    CurrentLine = cline;
    diff = lineno - CurrentPos.line;
    if( diff == 0 && !EditFlags.GlobalInProgress ) {
        return( ERR_NO_ERR );
    }
    cwl = CurrentPos.line - LeftTopPos.line + 1;
    nwl = cwl + diff;

    /*
     * if we go off the window, relocate
     */
    pageshift = false;
    dispall = false;

    text_lines = WindowAuxInfo( current_window_id, WIND_INFO_TEXT_LINES );
    if( nwl < 1 || nwl > text_lines ) {
        tl = text_lines / 2;
        if( !relcurs ) {
            LeftTopPos.line = lineno - tl;
        } else {
            LeftTopPos.line = lineno + 1 - cwl;
            pad = ( EditFlags.JumpyScroll ) ? 1 : 0;
            if( diff > 0 ) {
                LeftTopPos.line += pad;
                diff += pad;
            } else {
                LeftTopPos.line -= pad;
                diff -= pad;
            }
            if( diff > -tl && diff < tl && !dispall ) {
                pageshift = true;
            }
        }
        if( LeftTopPos.line < 1 ) {
            assert( diff <= 0 ); // < -> <= W.Briscoe 20031003 to avoid debug build failure of
            // C:\watcom\source\docs\nt) wmake -h -f ..\mif\master.mif hbook=wccerrs dotarget=nt
            diff += ( 1 - LeftTopPos.line );
            LeftTopPos.line = 1;
        }
        if( LeftTopPos.line > lineno ) {
            assert( diff > 0 );
            diff = LeftTopPos.line - lineno;
            LeftTopPos.line = lineno;
        }
        dispall = true;
    }
#if 0
    hiddcnt = GetHiddenLineCount( LeftTopPos.line, lineno );
    if( hiddcnt > 0 ) {
        pageshift = false;
        dispall = true;
    }
#endif

    if( CheckCurrentColumn() || EditFlags.Dragging ) {
        // pageshift wont help if we also have to column shift
        // and not really useful if dragging

        dispall = true;
        pageshift = false;
    }


    /* call SetCurrentLineNumber AFTER LeftTopPos.line set & CurrentColumn checked
    */
    SetCurrentLineNumber( lineno );

    if( pageshift ) {
        dispall = false;
        ShiftWindowUpDown( current_window_id, diff );
        if( EditFlags.LineNumbers ) {
            ShiftWindowUpDown( curr_num_window_id, diff );
        }
        if( diff > 0 ) {
            DCDisplaySomeLines( text_lines - diff, text_lines - 1 );
        } else {
            DCDisplaySomeLines( 0, -diff - 1 );
        }
    }
    UpdateStatusWindow();
    SetWindowCursor();
    if( dispall ) {
        DCInvalidateAllLines(); // lines definitely invalid
        DCDisplayAllLines();
    }
    return( ERR_NO_ERR );

} /* goToLine */