/* * SetCurrentColumn - set CurrentPos.column, positioning LeftTopPos.column nicely */ vi_rc SetCurrentColumn( int newcol ) { long oldpos; int text_cols; oldpos = CurrentPos.column - LeftTopPos.column; if( newcol <= 0 ) { newcol = 1; } text_cols = WindowAuxInfo( current_window_id, WIND_INFO_TEXT_COLS ); if( oldpos < 0 || oldpos >= text_cols ) { LeftTopPos.column = newcol - SCROLL_HLINE - 1; } else { LeftTopPos.column = newcol - oldpos - 1; } if( LeftTopPos.column < 0 ) { LeftTopPos.column = 0; } CurrentPos.column = newcol; CheckCurrentColumn(); UpdateCursorDrag(); VarAddRandC(); PositionHorizontalScrollThumb( current_window_id, LeftTopPos.column ); UpdateStatusWindow(); SetWindowCursor(); DCDisplayAllLines(); return( ERR_NO_ERR ); } /* SetCurrentColumn */
/* * SetCurrentLine - reset current line after changes in current file structure */ vi_rc SetCurrentLine( linenum lineno ) { int text_lines; fcb *cfcb; line *cline; vi_rc rc; if( lineno <= 0 ) { lineno = 1; } rc = CGimmeLinePtr( lineno, &cfcb, &cline ); if( rc != ERR_NO_ERR ) { return( rc ); } CurrentLine = cline; CurrentFcb = cfcb; text_lines = WindowAuxInfo( current_window_id, WIND_INFO_TEXT_LINES ); if( lineno < LeftTopPos.line || lineno > (LeftTopPos.line + text_lines - 1) ) { LeftTopPos.line = lineno - text_lines / 2; } if( LeftTopPos.line < 1 ) { LeftTopPos.line = 1; } CheckCurrentColumn(); SetCurrentLineNumber( lineno ); UpdateStatusWindow(); SetWindowCursor(); DCDisplayAllLines(); return( ERR_NO_ERR ); } /* SetCurrentLine */
/* * 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 */
/* * Shift - shove a tab in/out over a line range */ vi_rc Shift( linenum s, linenum e, char dir, bool msgflag ) { int shv; linenum fullcnt = 0; vi_rc rc; /* * set up undo */ if( rc = ModificationTest() ) { return( rc ); } rc = UndoReplaceLines( s, e ); if( rc != ERR_NO_ERR ) { return( rc ); } /* * now, point to start line */ rc = SaveAndResetFilePos( s ); if( rc != ERR_NO_ERR ) { return( rc ); } /* * process all lines */ for( CurrentPos.line = s; CurrentPos.line <= e; CurrentPos.line++ ) { /* * Add/Subtract leading tab space */ GetCurrentLine(); shv = ShiftWidth; if( dir != '>' ) { shv *= -1; } if( AddLeadingTabSpace( &WorkLine->len, WorkLine->data, shv ) ) { ++fullcnt; } ReplaceCurrentLine(); if( CurrentPos.line != e ) { rc = CGimmeNextLinePtr( &CurrentFcb, &CurrentLine ); if( rc != ERR_NO_ERR ) { RestoreCurrentFilePos(); return( rc ); } } } /* * done, say so and go back */ RestoreCurrentFilePos(); if( msgflag ) { Message1( "%l lines %c'ed", e - s + 1, dir ); if( fullcnt > 0 ) { Message2( "%l full lines not processed", fullcnt ); } } if( CurrentPos.line >= s && CurrentPos.line <= e ) { CheckCurrentColumn(); } DCDisplayAllLines(); SetWindowCursor(); Modified( TRUE ); return( DO_NOT_CLEAR_MESSAGE_WINDOW ); } /* Shift */
/* * MovePage - move by a number of pages */ vi_rc MovePage( int dir, long repcnt, bool keepselect ) { vi_rc rc; linenum x, top, ll; linenum tmp; if( EditFlags.Modeless && !keepselect ) { UnselectRegion(); } tmp = (repcnt * dir * WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES )) - (dir * EditVars.PageLinesExposed); #if 0 x = CurrentPos.line + tmp; top = LeftTopPos.line + tmp; CFindLastLine( &ll ); if( top > ll ) { top = ll; } else if( top < 1 ) { top = 1; } if( x > ll ) { x = ll; } else if( x < 1 ) { x = 1; } #else top = LeftTopPos.line + tmp; if( top < 1 ) { top = 1; } rc = CAdvanceToLine( top ); if( rc == ERR_NO_SUCH_LINE ) { rc = CFindLastLine( &ll ); top = ll; } if( rc != ERR_NO_ERR ) { return( rc ); } x = CurrentPos.line + tmp; if( x < 1 ) { x = 1; } rc = CAdvanceToLine( x ); if( rc == ERR_NO_SUCH_LINE ) { rc = CFindLastLine( &ll ); x = ll; } if( rc != ERR_NO_ERR ) { return( rc ); } #endif LeftTopPos.line = top; SetCurrentLineNumber( x ); rc = CGimmeLinePtr( CurrentPos.line, &CurrentFcb, &CurrentLine ); if( rc == ERR_NO_ERR ) { CheckCurrentColumn(); UpdateStatusWindow(); SetWindowCursor(); DCInvalidateAllLines(); DCDisplayAllLines(); } return( rc ); } /* MovePage */