Ticket #1850: 1850-multiline-vertical-down-copy.patch

File 1850-multiline-vertical-down-copy.patch, 4.4 KB (added by vit_r, 13 years ago)

F5-enhancement: multiline_vertical_down-copy

  • edit/edit-impl.h

    From 3fb50f3f373c1c4c2bd487ba3f9e7ee1a69a47a0 Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Sat, 28 Nov 2009 16:33:53 +0000
    Subject: [PATCH] multiline vertical down-copy
    
    ---
     edit/edit-impl.h |    5 +++
     edit/edit.c      |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
     2 files changed, 87 insertions(+), 0 deletions(-)
    
    diff --git a/edit/edit-impl.h b/edit/edit-impl.h
    index 6efb373..e42fbbc 100644
    a b void edit_syntax_dialog (void); 
    277277void edit_mail_dialog (WEdit *edit); 
    278278void format_paragraph (WEdit *edit, int force); 
    279279 
     280/* mlvc - multiline vertical down-copy */ 
     281int mlvc_proceed_unmarked_line (WEdit * edit); 
     282int mlvc_copy_marked_block_down (WEdit * edit, const long start_mark, const long end_mark); 
     283int mlvc_block_down_copy (WEdit * edit); 
     284 
    280285/* either command or char_for_insertion must be passed as -1 */ 
    281286void edit_execute_cmd (WEdit *edit, int command, int char_for_insertion); 
    282287 
  • edit/edit.c

    diff --git a/edit/edit.c b/edit/edit.c
    index 0b0b1eb..040386f 100644
    a b const char VERTICAL_MAGIC[] = {'\1', '\1', '\1', '\1', '\n'}; 
    121121const global_keymap_t *editor_map; 
    122122const global_keymap_t *editor_x_map; 
    123123 
     124static long cmarked_lowline;           /* lower highlighted line */ 
     125 
    124126static void user_menu (WEdit *edit); 
    125127 
    126128int edit_get_byte (WEdit * edit, long byte_index) 
    edit_execute_key_command (WEdit *edit, unsigned long command, int char_for_inser 
    25532555    if (command != CK_Undo && command != CK_Ext_Mode) 
    25542556        edit_push_key_press (edit); 
    25552557 
     2558    if (cmarked_lowline >= 0) { 
     2559        if (command != CK_Copy) 
     2560            cmarked_lowline = -1; 
     2561    } 
    25562562    edit_execute_cmd (edit, command, char_for_insertion); 
    25572563    if (column_highlighting) 
    25582564        edit->force |= REDRAW_PAGE; 
    edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 
    29902996        break; 
    29912997 
    29922998    case CK_Copy: 
     2999        if (mlvc_block_down_copy (edit)) 
     3000            break; 
    29933001        if ( option_cursor_beyond_eol && edit->over_col > 0 ) 
    29943002            edit_insert_over (edit); 
    29953003        edit_block_copy_cmd (edit); 
    edit_stack_free (void) 
    33413349            edit_stack_iterator++) 
    33423350        g_free (edit_history_moveto[edit_stack_iterator].filename); 
    33433351} 
     3352 
     3353int mlvc_proceed_unmarked_line (WEdit * edit) /* F5 */ 
     3354{ 
     3355    long start_mark, end_mark; 
     3356 
     3357    edit_cursor_to_bol (edit); 
     3358    if (edit_get_byte (edit, edit->curs1) == '\n') 
     3359        return 0; 
     3360 
     3361    start_mark = edit->curs1; 
     3362    edit_cursor_to_eol (edit); 
     3363    end_mark = edit->curs1 + 1; 
     3364    cmarked_lowline = edit->curs_line; 
     3365    if (mlvc_copy_marked_block_down (edit, start_mark, end_mark)) 
     3366        return 1; 
     3367 
     3368    return 0; 
     3369} 
     3370 
     3371int mlvc_copy_marked_block_down (WEdit * edit, const long start_mark, const long end_mark) 
     3372{ 
     3373    long p, n; 
     3374 
     3375    if (cmarked_lowline < 0) 
     3376        return 0; 
     3377 
     3378    edit_mark_cmd (edit, 1);    /* clear */ 
     3379    edit_cursor_move (edit, start_mark - edit->curs1); 
     3380    for (n = -1, p = start_mark; p < end_mark; p++) 
     3381        edit_insert (edit, edit_get_byte (edit, ++n + p)); 
     3382 
     3383    edit_mark_cmd (edit, 0);    /* mark1 */ 
     3384    edit_cursor_move (edit, end_mark - start_mark - 1); 
     3385    cmarked_lowline = edit->curs_line; 
     3386    edit_cursor_move (edit, 1); 
     3387    edit_mark_cmd (edit, 0);    /* mark2 */ 
     3388    edit_move_to_line (edit, cmarked_lowline); 
     3389    edit_cursor_to_bol (edit); 
     3390    if (edit->curs_line > (edit->start_line 
     3391            + edit->num_widget_lines - 3)) 
     3392        edit_move_display (edit, edit->curs_line - edit->num_widget_lines + 3); 
     3393 
     3394    edit->force |= REDRAW_PAGE; 
     3395    return 1; 
     3396} 
     3397 
     3398int mlvc_block_down_copy (WEdit * edit) 
     3399{ 
     3400    long start_mark, end_mark; 
     3401 
     3402    if (column_highlighting) 
     3403        return 0; 
     3404 
     3405    if (eval_marks (edit, &start_mark, &end_mark)) { 
     3406        if (mlvc_proceed_unmarked_line (edit)) 
     3407            return 1; 
     3408    } else if (start_mark <= edit->curs1 && edit->curs1 <= end_mark) { 
     3409        if (cmarked_lowline < 0) { 
     3410            edit_cursor_move (edit, (end_mark - 1) - edit->curs1); 
     3411            edit_cursor_to_eol (edit); 
     3412            end_mark = edit->curs1 + 1; 
     3413            cmarked_lowline = edit->curs_line; 
     3414            edit_cursor_move (edit, start_mark - edit->curs1); 
     3415            edit_cursor_to_bol (edit); 
     3416            start_mark = edit->curs1; 
     3417        } 
     3418        if (mlvc_copy_marked_block_down (edit, start_mark, end_mark)) 
     3419            return 1; 
     3420    } else { 
     3421        cmarked_lowline = -1; 
     3422    } 
     3423 
     3424    return 0; 
     3425}