Ticket #3195: 2_goto_line.patch

File 2_goto_line.patch, 1.5 KB (added by aurel, 8 years ago)

Patch for the feature

  • src/editor/editcmd.c

    old new edit_goto_cmd (WEdit * edit) 
    29542954{ 
    29552955    char *f; 
    29562956    static long line = 0;       /* line as typed, saved as default */ 
     2957    static unsigned long column = 0; 
    29572958    long l; 
    2958     char *error; 
    2959     char s[32]; 
     2959    char s[65]; 
     2960 
     2961    if (column) 
     2962        g_snprintf (s, sizeof (s), "%ld:%lu", line, column); 
     2963    else 
     2964        g_snprintf (s, sizeof (s), "%ld", line); 
    29602965 
    2961     g_snprintf (s, sizeof (s), "%ld", line); 
    29622966    f = input_dialog (_("Goto line"), _("Enter line:"), MC_HISTORY_EDIT_GOTO_LINE, line ? s : "", 
    29632967                      INPUT_COMPLETE_NONE); 
    29642968    if (!f) 
    edit_goto_cmd (WEdit * edit) 
    29702974        return; 
    29712975    } 
    29722976 
    2973     l = strtol (f, &error, 0); 
    2974     if (*error) 
     2977    int scanned = sscanf(f, "%ld%*c%lu", &l, &column); 
     2978    if (!(scanned >= 1) || EOF == scanned) 
    29752979    { 
    29762980        g_free (f); 
    29772981        return; 
    edit_goto_cmd (WEdit * edit) 
    29822986        l = edit->buffer.lines + l + 2; 
    29832987    edit_move_display (edit, l - WIDGET (edit)->lines / 2 - 1); 
    29842988    edit_move_to_line (edit, l - 1); 
     2989 
     2990    if (scanned == 2) 
     2991    { 
     2992        off_t line_width = edit_buffer_get_current_eol (&edit->buffer) - 
     2993                           edit_buffer_get_current_bol (&edit->buffer); 
     2994        if (column > line_width) 
     2995            column = line_width; 
     2996        edit_cursor_move (edit, column - edit_get_col (edit)); 
     2997    } 
     2998    else 
     2999        column = 0; 
     3000 
    29853001    edit->force |= REDRAW_COMPLETELY; 
    29863002    g_free (f); 
    29873003}