screenMovement.patch

David Gayou, 09/01/2008 11:09 am

Download (5.8 KB)

 
b/libyzis/mode_command.cpp Mon Sep 01 11:08:58 2008 +0200
137 137
    motions.append( new YMotion(YKeySequence("<ENTER>"), &YModeCommand::firstNonBlankNextLine, ArgNone) );
138 138
    motions.append( new YMotion(YKeySequence("+"), &YModeCommand::firstNonBlankNextLine, ArgNone) );
139 139
    motions.append( new YMotion(YKeySequence("-"), &YModeCommand::firstNonBlankPreviousLine, ArgNone) );
140
    motions.append( new YMotion(YKeySequence("H"), &YModeCommand::topScreen, ArgNone) );
141
    motions.append( new YMotion(YKeySequence("L"), &YModeCommand::bottomScreen, ArgNone) );
142
    motions.append( new YMotion(YKeySequence("M"), &YModeCommand::middleScreen, ArgNone) );
140 143
    motions.append( new YMotion(YKeySequence("gg"), &YModeCommand::gotoLine, ArgNone) );
141 144
    motions.append( new YMotion(YKeySequence("G"), &YModeCommand::gotoLine, ArgNone) );
142 145
    motions.append( new YMotion(YKeySequence("}"), &YModeCommand::nextEmptyLine, ArgNone) );
......
1180 1183
    return viewCursor.buffer();
1181 1184
}
1182 1185

  
1186
YCursor YModeCommand::topScreen(const YMotionArgs &args, CmdState *state)
1187
{
1188
    YViewCursor viewCursor = args.view->viewCursor();
1189
    args.view->moveTop(&viewCursor, args.count, args.standalone );
1190
    args.view->moveToFirstNonBlankOfLine( &viewCursor, args.standalone );
1191
    *state = CmdOk;
1192

  
1193
    YSession::self()->saveJumpPosition();
1194
    return viewCursor.buffer();
1195
}
1196

  
1197
YCursor YModeCommand::bottomScreen(const YMotionArgs &args, CmdState *state)
1198
{
1199
    YViewCursor viewCursor = args.view->viewCursor();
1200
    args.view->moveBottom(&viewCursor, args.count, args.standalone );
1201
    args.view->moveToFirstNonBlankOfLine( &viewCursor, args.standalone );
1202
    *state = CmdOk;
1203

  
1204
    YSession::self()->saveJumpPosition();
1205
    return viewCursor.buffer();
1206
}
1207

  
1208
YCursor YModeCommand::middleScreen(const YMotionArgs &args, CmdState *state)
1209
{
1210
    YViewCursor viewCursor = args.view->viewCursor();
1211
    args.view->moveMiddle(&viewCursor, args.count, args.standalone );
1212
    //use the following line instead if you don't want the argument to work with "H" command
1213
    //args.view->moveMiddle(&viewCursor, 0, args.standalone );
1214
    args.view->moveToFirstNonBlankOfLine( &viewCursor, args.standalone );
1215
    *state = CmdOk;
1216

  
1217
    YSession::self()->saveJumpPosition();
1218
    return viewCursor.buffer();
1219
}
1220

  
1183 1221
YCursor YModeCommand::gotoLine(const YMotionArgs &args, CmdState *state)
1184 1222
{
1185 1223
    YViewCursor viewCursor = args.view->viewCursor();
b/libyzis/mode_command.h Mon Sep 01 11:08:58 2008 +0200
233 233
    YCursor gotoMark(const YMotionArgs &args, CmdState *state);
234 234
    YCursor firstNonBlankNextLine(const YMotionArgs &args, CmdState *state);
235 235
    YCursor firstNonBlankPreviousLine(const YMotionArgs &args, CmdState *state);
236
    YCursor topScreen(const YMotionArgs &args, CmdState *state);
237
    YCursor bottomScreen(const YMotionArgs &args, CmdState *state);
238
    YCursor middleScreen(const YMotionArgs &args, CmdState *state);
236 239
    YCursor gotoLine(const YMotionArgs &args, CmdState *state);
237 240
    YCursor searchWord(const YMotionArgs &args, CmdState *state);
238 241
    YCursor searchNext(const YMotionArgs &args, CmdState *state);
b/libyzis/view.cpp Mon Sep 01 11:08:58 2008 +0200
821 821
    return stopped;
822 822
}
823 823

  
824
void YView::moveTop( YViewCursor* viewCursor, int line, bool applyCursor )
825
{
826
    if( line <= 0) line = 1;
827
    gotodxdy( viewCursor, 0, (getDrawCurrentTop() + line - 1 ), applyCursor );
828
}
829

  
830
void YView::moveBottom( YViewCursor* viewCursor, int line, bool applyCursor )
831
{
832
    int lineToGo;
833

  
834
    if (line <= 0) line = 1;
835

  
836
    //Checking end of file to manage the line to go if line arg is not 0
837
    if ( ( getDrawCurrentTop() + mLinesVis ) > mBuffer->lineCount() )
838
        lineToGo = mBuffer->lineCount();
839
    else lineToGo = getDrawCurrentTop() + mLinesVis; 
840
 
841
    gotodxdy( viewCursor, 0, ( lineToGo - line ), applyCursor);
842
}
843

  
844
void YView::moveMiddle(YViewCursor* viewCursor, int line, bool applyCursor)
845
{
846
    int lineToGo;
847
    
848
    if (line <= 0) line = 1;
849

  
850
    //Checking end of file to manage the line to go if line arg is not 0
851
    if ( ( getDrawCurrentTop() + mLinesVis/2 ) > mBuffer->lineCount() )
852
        lineToGo = getDrawCurrentTop() + ( mBuffer->lineCount() - getDrawCurrentTop() )/2;
853
    else lineToGo = getDrawCurrentTop() + mLinesVis/2; 
854

  
855
    gotodxdy(viewCursor, 0, ( lineToGo + line -1), applyCursor);
856
}
857

  
824 858
QString YView::moveToFirstNonBlankOfLine( )
825 859
{
826 860
    return moveToFirstNonBlankOfLine( &mainCursor );
......
856 890
{
857 891
    gotoLastLine( &mainCursor );
858 892
}
893

  
859 894
void YView::gotoLastLine( YViewCursor* viewCursor, bool applyCursor )
860 895
{
861 896
    gotoLine( viewCursor, mBuffer->lineCount() - 1, applyCursor );
b/libyzis/view.h Mon Sep 01 11:08:58 2008 +0200
293 293
    bool moveRight( YViewCursor* viewCursor, int nb_cols = 1, bool wrap = false, bool applyCursor = true);
294 294

  
295 295
    /**
296
     * move the cursor of the current view to the top line of the screen
297
     */
298
    void moveTop( YViewCursor* viewCursor, int line, bool applyCursor );
299

  
300
    /**
301
     * move the cursor of the current screen view to the bottom line of the screen
302
     */
303
    void moveBottom( YViewCursor* viewCursor, int line, bool applyCursor); 
304

  
305
   /**
306
    * Move the cursor of the current view to the middle line of the screen
307
    */
308
    void moveMiddle( YViewCursor* viewCursor,int line, bool applyCursor);  
309

  
310
   /**
296 311
     * moves the cursor of the current view to the first non-blank character
297 312
     * of the current line
298 313
     */