-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_goto_line.patch
51 lines (49 loc) · 1.51 KB
/
2_goto_line.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--- mc-4.8.11.orig/src/editor/editcmd.c
+++ mc-4.8.11/src/editor/editcmd.c
@@ -2954,11 +2954,15 @@ edit_goto_cmd (WEdit * edit)
{
char *f;
static long line = 0; /* line as typed, saved as default */
+ static unsigned long column = 0;
long l;
- char *error;
- char s[32];
+ char s[65];
+
+ if (column)
+ g_snprintf (s, sizeof (s), "%ld:%lu", line, column);
+ else
+ g_snprintf (s, sizeof (s), "%ld", line);
- g_snprintf (s, sizeof (s), "%ld", line);
f = input_dialog (_("Goto line"), _("Enter line:"), MC_HISTORY_EDIT_GOTO_LINE, line ? s : "",
INPUT_COMPLETE_NONE);
if (!f)
@@ -2970,8 +2974,8 @@ edit_goto_cmd (WEdit * edit)
return;
}
- l = strtol (f, &error, 0);
- if (*error)
+ int scanned = sscanf(f, "%ld%*c%lu", &l, &column);
+ if (!(scanned >= 1) || EOF == scanned)
{
g_free (f);
return;
@@ -2982,6 +2986,18 @@ edit_goto_cmd (WEdit * edit)
l = edit->buffer.lines + l + 2;
edit_move_display (edit, l - WIDGET (edit)->lines / 2 - 1);
edit_move_to_line (edit, l - 1);
+
+ if (scanned == 2)
+ {
+ off_t line_width = edit_buffer_get_current_eol (&edit->buffer) -
+ edit_buffer_get_current_bol (&edit->buffer);
+ if (column > line_width)
+ column = line_width;
+ edit_cursor_move (edit, column - edit_get_col (edit));
+ }
+ else
+ column = 0;
+
edit->force |= REDRAW_COMPLETELY;
g_free (f);
}