Ticket #1847: 1847-multiline-vertical-move.patch
File 1847-multiline-vertical-move.patch, 10.7 KB (added by vit_r, 14 years ago) |
---|
-
edit/edit-impl.h
From e62ff17b07c57d07798ccd82dbe3a1dbbe9f2e7d Mon Sep 17 00:00:00 2001 From: Vit Rosin <vit_r@list.ru> Date: Fri, 27 Nov 2009 14:56:59 +0000 Subject: [PATCH] multiline vertical move --- edit/edit-impl.h | 8 ++ edit/edit.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++- misc/mc.keymap.default | 1 + misc/mc.keymap.emacs | 1 + src/cmddef.h | 1 + src/keybind.c | 2 + 6 files changed, 218 insertions(+), 2 deletions(-) diff --git a/edit/edit-impl.h b/edit/edit-impl.h index 6efb373..f0359f4 100644
a b void edit_syntax_dialog (void); 277 277 void edit_mail_dialog (WEdit *edit); 278 278 void format_paragraph (WEdit *edit, int force); 279 279 280 /* mlvm - multiline vertical move */ 281 void mlvm_get_block_marks (WEdit * edit, long *start_mark, long *end_mark); 282 int mlvm_proceed_unmarked_line (WEdit * edit, const int command); 283 int mlvm_move_marked_block_up (WEdit * edit, const long start_mark, const long end_mark); 284 int mlvm_move_marked_block_down (WEdit * edit, const long start_mark, const long end_mark); 285 int mlvm_block_up_move (WEdit * edit, const int command); 286 int mlvm_block_down_move (WEdit * edit, const int command); 287 280 288 /* either command or char_for_insertion must be passed as -1 */ 281 289 void edit_execute_cmd (WEdit *edit, int command, int char_for_insertion); 282 290 -
edit/edit.c
diff --git a/edit/edit.c b/edit/edit.c index 0b0b1eb..dea0ba0 100644
a b const char VERTICAL_MAGIC[] = {'\1', '\1', '\1', '\1', '\n'}; 121 121 const global_keymap_t *editor_map; 122 122 const global_keymap_t *editor_x_map; 123 123 124 static long marked_topline; /* upper highlighted line */ 125 static long marked_lowline; /* lower highlighted line */ 126 124 127 static void user_menu (WEdit *edit); 125 128 126 129 int edit_get_byte (WEdit * edit, long byte_index) … … edit_execute_key_command (WEdit *edit, unsigned long command, int char_for_inser 2553 2556 if (command != CK_Undo && command != CK_Ext_Mode) 2554 2557 edit_push_key_press (edit); 2555 2558 2559 if (marked_topline >= 0 || marked_lowline >= 0) { 2560 if (! (command == CK_Move_Up || command == CK_Move) ) { 2561 marked_topline = -1; 2562 marked_lowline = -1; 2563 } 2564 } 2556 2565 edit_execute_cmd (edit, command, char_for_insertion); 2557 2566 if (column_highlighting) 2558 2567 edit->force |= REDRAW_PAGE; … … edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 2586 2595 edit->highlight = 1; 2587 2596 } else { /* any other command */ 2588 2597 if (edit->highlight) 2589 edit_mark_cmd (edit, 0); /* clear*/2598 edit_mark_cmd (edit, 0); /* marking on */ 2590 2599 edit->highlight = 0; 2591 2600 } 2592 2601 … … edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 2997 3006 case CK_Remove: 2998 3007 edit_block_delete_cmd (edit); 2999 3008 break; 3009 case CK_Move_Up: 3010 if (mlvm_block_up_move (edit, command)) 3011 break; 3012 if ( option_cursor_beyond_eol && edit->over_col > 0 ) 3013 edit_insert_over (edit); 3014 edit_block_move_cmd (edit); 3015 break; 3000 3016 case CK_Move: 3017 if (mlvm_block_down_move (edit, command)) 3018 break; 3001 3019 if ( option_cursor_beyond_eol && edit->over_col > 0 ) 3002 3020 edit_insert_over (edit); 3003 3021 edit_block_move_cmd (edit); 3004 3022 break; 3005 3006 3023 case CK_Shift_Block_Left: 3007 3024 if (edit->mark1 != edit->mark2) 3008 3025 edit_move_block_to_left (edit); … … edit_stack_free (void) 3341 3358 edit_stack_iterator++) 3342 3359 g_free (edit_history_moveto[edit_stack_iterator].filename); 3343 3360 } 3361 3362 void mlvm_get_block_marks (WEdit * edit, long *start_mark, long *end_mark) 3363 { 3364 edit_cursor_move (edit, (*end_mark - 1) - edit->curs1); 3365 edit_cursor_to_eol (edit); 3366 *end_mark = edit->curs1 + 1; 3367 marked_lowline = edit->curs_line; 3368 edit_cursor_move (edit, *start_mark - edit->curs1); 3369 marked_topline = edit->curs_line; 3370 edit_cursor_to_bol (edit); 3371 *start_mark = edit->curs1; 3372 } 3373 3374 int mlvm_proceed_unmarked_line (WEdit * edit, const int command) /* F6 | C-F6 */ 3375 { 3376 long start_mark, end_mark; 3377 3378 if (edit->total_lines < 2) 3379 return 0; 3380 3381 edit_cursor_to_bol (edit); 3382 3383 if (edit->curs1 < edit->last_byte) { 3384 start_mark = edit->curs1; 3385 edit_cursor_move (edit, 1); 3386 end_mark = edit->curs1; 3387 } else { 3388 end_mark = edit->curs1; 3389 edit_cursor_move (edit, -1); 3390 start_mark = edit->curs1; 3391 } 3392 3393 mlvm_get_block_marks (edit, &start_mark, &end_mark); 3394 3395 if (command == CK_Move) { 3396 if (mlvm_move_marked_block_down (edit, start_mark, end_mark)) 3397 return 1; 3398 else 3399 marked_lowline = -1; 3400 3401 } else if (command == CK_Move_Up) { 3402 if (mlvm_move_marked_block_up (edit, start_mark, end_mark)) 3403 return 1; 3404 else 3405 marked_topline = -1; 3406 } 3407 3408 return 0; 3409 } 3410 3411 int mlvm_move_marked_block_up (WEdit * edit, const long start_mark, const long end_mark) 3412 { 3413 long p, upline_min, upline_max; 3414 3415 if (edit->total_lines < 2) 3416 return 0; 3417 3418 if (marked_topline < 1) 3419 return 0; 3420 3421 edit_cursor_move (edit, start_mark - edit->curs1); 3422 3423 if (!edit->curs_line) 3424 return 0; 3425 3426 upline_max = start_mark - 1; 3427 edit_cursor_to_bol (edit); 3428 edit_move_up (edit, 1, 0); 3429 marked_topline = edit->curs_line; 3430 upline_min = edit->curs1; 3431 edit_cursor_move (edit, (end_mark - 1) - edit->curs1); 3432 3433 for (p = (upline_min - 1); p < (start_mark - 1); p++) 3434 edit_insert (edit, edit_get_byte (edit, p)); 3435 3436 edit_cursor_move (edit, upline_min - upline_max); 3437 marked_lowline = edit->curs_line - 1; 3438 edit_mark_cmd (edit, 1); /* clear */ 3439 edit_mark_cmd (edit, 0); /* mark1 */ 3440 edit_cursor_move (edit, upline_min - edit->curs1); 3441 edit_delete_line (edit); 3442 edit_mark_cmd (edit, 0); /* mark2 */ 3443 edit_move_to_line (edit, marked_topline); 3444 edit_cursor_to_bol (edit); 3445 3446 if (edit->curs_line < (edit->start_line + 2)) 3447 edit_move_display (edit, edit->curs_line - 2); 3448 3449 return 1; 3450 } 3451 3452 int mlvm_block_up_move (WEdit * edit, const int command) 3453 { 3454 long start_mark, end_mark; 3455 3456 if (column_highlighting) 3457 return 0; 3458 3459 marked_lowline = -1; 3460 3461 if (eval_marks (edit, &start_mark, &end_mark)) { 3462 if (mlvm_proceed_unmarked_line (edit, command)) 3463 return 1; 3464 } else if (start_mark <= edit->curs1 && edit->curs1 <= end_mark) { 3465 if (marked_topline < 0) 3466 mlvm_get_block_marks (edit, &start_mark, &end_mark); 3467 3468 if (mlvm_move_marked_block_up (edit, start_mark, end_mark)) 3469 return 1; 3470 } else { 3471 marked_topline = -1; 3472 } 3473 3474 return 0; 3475 } 3476 3477 int mlvm_move_marked_block_down (WEdit * edit, const long start_mark, const long end_mark) 3478 { 3479 long p, n, lowline_min, lowline_max; 3480 3481 if (edit->total_lines < 2) 3482 return 0; 3483 3484 if (marked_lowline < 0) 3485 return 0; 3486 3487 if (end_mark >= (edit->last_byte - 1)) { 3488 marked_lowline = -1; 3489 return 0; 3490 } 3491 edit_mark_cmd (edit, 1); /* clear */ 3492 edit_cursor_move (edit, end_mark - edit->curs1); 3493 lowline_min = edit->curs1; 3494 edit_cursor_to_eol (edit); 3495 lowline_max = edit->curs1 + 1; 3496 edit_cursor_move (edit, start_mark - edit->curs1); 3497 3498 for (n = -1, p = lowline_min; p < lowline_max; p++) 3499 edit_insert (edit, edit_get_byte (edit, ++n + p)); 3500 3501 edit_mark_cmd (edit, 0); /* mark1 */ 3502 marked_topline = edit->curs_line; 3503 edit_cursor_move (edit, (end_mark - start_mark)); 3504 edit_cursor_to_eol (edit); 3505 3506 while (edit_get_byte (edit, edit->curs1 - 1) != '\n') 3507 edit_backspace (edit, 1); 3508 3509 edit_backspace (edit, 1); 3510 marked_lowline = edit->curs_line; 3511 edit_cursor_move (edit, 1); 3512 edit_mark_cmd (edit, 0); /* mark2 */ 3513 edit_move_to_line (edit, marked_lowline); 3514 edit_cursor_to_bol (edit); 3515 3516 if (edit->curs_line > (edit->start_line 3517 + edit->num_widget_lines - 3)) 3518 edit_move_display (edit, edit->curs_line - edit->num_widget_lines + 3); 3519 3520 return 1; 3521 } 3522 3523 int mlvm_block_down_move (WEdit * edit, const int command) 3524 { 3525 long start_mark, end_mark; 3526 3527 if (column_highlighting) 3528 return 0; 3529 3530 marked_topline = -1; 3531 3532 if (eval_marks (edit, &start_mark, &end_mark)) { 3533 if (mlvm_proceed_unmarked_line (edit, command)) 3534 return 1; 3535 } else if (start_mark <= edit->curs1 && edit->curs1 <= end_mark) { 3536 if (marked_lowline < 0) 3537 mlvm_get_block_marks (edit, &start_mark, &end_mark); 3538 3539 if (mlvm_move_marked_block_down (edit, start_mark, end_mark)) 3540 return 1; 3541 } else { 3542 marked_lowline = -1; 3543 } 3544 3545 return 0; 3546 } -
misc/mc.keymap.default
diff --git a/misc/mc.keymap.default b/misc/mc.keymap.default index 5883787..467cd77 100644
a b EditSaveas = f12 40 40 EditMark = f3 41 41 EditCopy = f5 42 42 EditMove = f6 43 EditMoveUp = ctrl-f6 43 44 EditRemove = f8 44 45 EditUnmark = 45 46 EditFind = f7 -
misc/mc.keymap.emacs
diff --git a/misc/mc.keymap.emacs b/misc/mc.keymap.emacs index b30d85f..8face7a 100644
a b EditSaveas = f12 39 39 EditMark = f3 40 40 EditCopy = f5 41 41 EditMove = f6 42 EditMoveUp = ctrl-f6 42 43 EditRemove = f8 43 44 EditUnmark = 44 45 EditFind = f7 -
src/cmddef.h
diff --git a/src/cmddef.h b/src/cmddef.h index 594223e..3550078 100644
a b 63 63 #define CK_Column_Mark 208 64 64 #define CK_Shift_Block_Left 211 65 65 #define CK_Shift_Block_Right 212 66 #define CK_Move_Up 213 66 67 67 68 /* search and replace */ 68 69 #define CK_Find 301 -
src/keybind.c
diff --git a/src/keybind.c b/src/keybind.c index 66657ab..c15eac8 100644
a b static name_keymap_t command_names[] = { 83 83 { "EditMark", CK_Mark }, 84 84 { "EditCopy", CK_Copy }, 85 85 { "EditMove", CK_Move }, 86 { "EditMoveUp", CK_Move_Up}, 86 87 { "EditRemove", CK_Remove }, 87 88 { "EditUnmark", CK_Unmark }, 88 89 { "EditSaveBlock", CK_Save_Block }, … … const global_keymap_t default_editor_keymap[] = { 603 604 /* Ctrl */ 604 605 { KEY_M_CTRL | (KEY_F (2)), CK_Save_As, "C-F2" }, 605 606 { KEY_M_CTRL | (KEY_F (4)), CK_Replace_Again, "C-F4" }, 607 { KEY_M_CTRL | (KEY_F (6)), CK_Move_Up, "C-F6" }, 606 608 { KEY_M_CTRL | (KEY_F (7)), CK_Find_Again, "C-F7" }, 607 609 { KEY_M_CTRL | KEY_BACKSPACE, CK_Undo, "C-BackSpace" }, 608 610 { KEY_M_CTRL | KEY_NPAGE, CK_End_Of_Text, "C-PgDn" },