Ticket #319: 319-flow-column-insertion.patch

File 319-flow-column-insertion.patch, 7.6 KB (added by vit_r, 14 years ago)
  • edit/edit.c

    From 59e5cdcb1c98089390853bcbe29dc32aefb03d9e Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Tue, 3 Nov 2009 20:50:38 +0000
    Subject: [PATCH] flow column insertion
    
    ---
     edit/edit.c    |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
     edit/edit.h    |    5 +--
     edit/editcmd.c |   24 +++++++++++++------
     3 files changed, 84 insertions(+), 12 deletions(-)
    
    diff --git a/edit/edit.c b/edit/edit.c
    index e239c0c..1cc642e 100644
    a b const char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_"; 
    8787char *option_backup_ext = NULL; 
    8888 
    8989int edit_stack_iterator = 0; 
     90static unsigned long pasted_from_X_buf; 
    9091edit_stack_type edit_history_moveto [MAX_HISTORY_MOVETO]; 
    9192/* magic sequense for say than block is vertical */ 
    9293const char VERTICAL_MAGIC[] = {'\1', '\1', '\1', '\1', '\n'}; 
    int 
    478479edit_insert_file (WEdit *edit, const char *filename) 
    479480{ 
    480481    char *p; 
     482    pasted_from_X_buf = 0; 
    481483    if ((p = edit_get_filter (filename))) { 
    482484        FILE *f; 
    483485        long current = edit->curs1; 
    edit_insert_file (WEdit *edit, const char *filename) 
    526528                for (i = 0; i < blocklen; i++) 
    527529                    edit_insert (edit, buf[i]); 
    528530            } 
     531            pasted_from_X_buf = edit->curs1 - current; 
    529532        } 
    530533        edit_cursor_move (edit, current - edit->curs1); 
    531534        g_free (buf); 
    static void edit_goto_matching_bracket (WEdit *edit) 
    25292532 */ 
    25302533void edit_execute_key_command (WEdit *edit, int command, int char_for_insertion) 
    25312534{ 
     2535    static unsigned int go_to_SIstart_col = 0; 
     2536    static unsigned int go_to_CMstart_col = 0; 
     2537 
    25322538    if (command == CK_Begin_Record_Macro) { 
    25332539        edit->macro_i = 0; 
    25342540        edit->force |= REDRAW_CHAR_ONLY | REDRAW_LINE; 
    void edit_execute_key_command (WEdit *edit, int command, int char_for_insertion) 
    25492555        edit_push_key_press (edit); 
    25502556 
    25512557    edit_execute_cmd (edit, command, char_for_insertion); 
     2558 
     2559    switch (command) { 
     2560    case CK_Copy: 
     2561    case CK_Move: 
     2562        go_to_CMstart_col = 0; 
     2563        go_to_SIstart_col = 0; 
     2564        if ( ! column_highlighting && buf_stored_size) { 
     2565            edit_mark_cmd (edit, 1); 
     2566            edit_mark_cmd (edit, 0); 
     2567            edit_cursor_move (edit, buf_stored_size); 
     2568            edit_mark_cmd (edit, 0); 
     2569            edit->force |= REDRAW_PAGE; 
     2570            edit_update_screen (edit); 
     2571            if (edit->curs_line > (edit->start_line 
     2572                    + edit->num_widget_lines - 3)) { 
     2573                edit_move_display (edit, edit->start_line + 2); 
     2574                edit->force |= REDRAW_PAGE; 
     2575            } 
     2576            go_to_CMstart_col = 1; 
     2577        } 
     2578        break; 
     2579    case CK_XPaste: 
     2580        go_to_CMstart_col = 0; 
     2581        go_to_SIstart_col = 0; 
     2582        if ( ! column_highlighting && pasted_from_X_buf) { 
     2583            edit_mark_cmd (edit, 1); 
     2584            edit_mark_cmd (edit, 0); 
     2585            edit_cursor_move (edit, pasted_from_X_buf); 
     2586            edit_mark_cmd (edit, 0); 
     2587            edit->force |= REDRAW_PAGE; 
     2588            edit_update_screen (edit); 
     2589            if (edit->curs_line > (edit->start_line 
     2590                    + edit->num_widget_lines - 3)) { 
     2591                edit_move_display (edit, edit->start_line + 2); 
     2592                edit->force |= REDRAW_PAGE; 
     2593            } 
     2594            go_to_SIstart_col = 1; 
     2595        } 
     2596        break; 
     2597    case CK_Up: 
     2598        if ( ! column_highlighting) { 
     2599            if (go_to_CMstart_col || go_to_SIstart_col) { 
     2600                long start_mark, end_mark; 
     2601                eval_marks (edit, &start_mark, &end_mark); 
     2602                if (end_mark - start_mark) { 
     2603                    edit_cursor_move (edit, start_mark - edit->curs1); 
     2604                    if (edit->curs_line) 
     2605                        edit_move_to_line (edit, edit->curs_line - 1); 
     2606                    if (edit->curs_line < (edit->start_line + 1)) 
     2607                        edit_move_display (edit, edit->curs_line - 1); 
     2608                    edit->force |= REDRAW_PAGE; 
     2609                } 
     2610            } 
     2611        } 
     2612    default: 
     2613        go_to_CMstart_col = 0; 
     2614        go_to_SIstart_col = 0; 
     2615    } 
     2616 
    25522617    if (column_highlighting) 
    25532618        edit->force |= REDRAW_PAGE; 
    25542619} 
    edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 
    25812646        edit->highlight = 1; 
    25822647    } else {                    /* any other command */ 
    25832648        if (edit->highlight) 
    2584             edit_mark_cmd (edit, 0);    /* clear */ 
     2649            edit_mark_cmd (edit, 0);    /* marking on */ 
    25852650        edit->highlight = 0; 
    25862651    } 
    25872652 
  • edit/edit.h

    diff --git a/edit/edit.h b/edit/edit.h
    index 0891801..f26bd5b 100644
    a b extern int option_save_mode; 
    5353extern int option_save_position; 
    5454extern int option_syntax_highlighting; 
    5555extern char *option_backup_ext; 
    56  
    5756extern int edit_confirm_save; 
    58  
    5957extern int visible_tabs; 
    6058extern int visible_tws; 
    61  
    6259extern int simple_statusbar; 
    6360extern int option_check_nl_at_eof; 
    6461 
     62unsigned long buf_stored_size; 
     63 
    6564/* used in main() */ 
    6665void edit_stack_init (void); 
    6766void edit_stack_free (void); 
  • edit/editcmd.c

    diff --git a/edit/editcmd.c b/edit/editcmd.c
    index 48f1db6..c328def 100644
    a b edit_insert_column_of_text_from_file (WEdit * edit, int file) 
    11671167void 
    11681168edit_block_copy_cmd (WEdit *edit) 
    11691169{ 
    1170     long start_mark, end_mark, current = edit->curs1; 
     1170    long start_mark, end_mark; 
    11711171    int size; 
    11721172    unsigned char *copy_buf; 
    11731173 
     1174    buf_stored_size = 0; 
     1175 
    11741176    edit_update_curs_col (edit); 
    11751177    if (eval_marks (edit, &start_mark, &end_mark)) 
    11761178        return; 
    edit_block_copy_cmd (WEdit *edit) 
    11851187        edit_insert_column_of_text (edit, copy_buf, size, 
    11861188                                    abs (edit->column2 - edit->column1)); 
    11871189    } else { 
     1190        buf_stored_size = (long) size; 
    11881191        while (size--) 
    11891192            edit_insert_ahead (edit, copy_buf[size]); 
    11901193    } 
    edit_block_copy_cmd (WEdit *edit) 
    11961199        edit_set_markers (edit, 0, 0, 0, 0); 
    11971200        edit_push_action (edit, COLUMN_ON); 
    11981201        column_highlighting = 0; 
    1199     } else if (start_mark < current && end_mark > current) 
    1200         edit_set_markers (edit, start_mark, 
    1201                           end_mark + end_mark - start_mark, 0, 0); 
     1202        buf_stored_size = 0; 
     1203    } 
    12021204 
    12031205    edit->force |= REDRAW_PAGE; 
    12041206} 
    edit_block_move_cmd (WEdit *edit) 
    12141216    int deleted = 0; 
    12151217    int x = 0; 
    12161218 
     1219    buf_stored_size = 0; 
     1220 
    12171221    if (eval_marks (edit, &start_mark, &end_mark)) 
    12181222        return; 
     1223 
    12191224    if (column_highlighting) { 
    12201225        edit_update_curs_col (edit); 
    12211226        x = edit->curs_col; 
    edit_block_move_cmd (WEdit *edit) 
    12261231    } else if (start_mark <= edit->curs1 && end_mark >= edit->curs1) 
    12271232        return; 
    12281233 
    1229     if ((end_mark - start_mark) > option_max_undo / 2) 
     1234    buf_stored_size = end_mark - start_mark; 
     1235 
     1236    if (buf_stored_size > option_max_undo / 2) 
    12301237        if (edit_query_dialog2 
    12311238            (_("Warning"), 
    12321239             _ 
    edit_block_move_cmd (WEdit *edit) 
    12691276        edit_set_markers (edit, 0, 0, 0, 0); 
    12701277        edit_push_action (edit, COLUMN_ON); 
    12711278        column_highlighting = 0; 
     1279        buf_stored_size = 0; 
    12721280    } else { 
    1273         copy_buf = g_malloc (end_mark - start_mark); 
     1281        copy_buf = g_malloc (buf_stored_size); 
    12741282        edit_cursor_move (edit, start_mark - edit->curs1); 
    12751283        edit_scroll_screen_over_cursor (edit); 
    12761284        count = start_mark; 
    edit_block_move_cmd (WEdit *edit) 
    12821290        edit_cursor_move (edit, 
    12831291                          current - edit->curs1 - 
    12841292                          (((current - edit->curs1) > 
    1285                             0) ? end_mark - start_mark : 0)); 
     1293                            0) ? buf_stored_size : 0)); 
    12861294        edit_scroll_screen_over_cursor (edit); 
    12871295        while (count-- > start_mark) 
    12881296            edit_insert_ahead (edit, copy_buf[end_mark - count - 1]); 
    12891297        edit_set_markers (edit, edit->curs1, 
    1290                           edit->curs1 + end_mark - start_mark, 0, 0); 
     1298                          edit->curs1 + buf_stored_size, 0, 0); 
    12911299    } 
    12921300    edit_scroll_screen_over_cursor (edit); 
    12931301    g_free (copy_buf);