mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 12:56:51 +03:00
* util.h (move_backward2): Fixed endless loop. Cleaned up code. The only case that's left with the old code is text mode with line wrapping. (move_backward2_textmode_wrap): The special case of moving some lines up in text mode with line wrapping enabled.
This commit is contained in:
parent
a37fdaca96
commit
ea14b320f7
@ -1,8 +1,17 @@
|
|||||||
|
2004-08-19 Roland Illig <roland.illig@gmx.de>
|
||||||
|
|
||||||
|
* util.h (move_backward2): Fixed endless loop. Cleaned up code.
|
||||||
|
The only case that's left with the old code is text mode with
|
||||||
|
line wrapping. (move_backward2_textmode_wrap): The special case
|
||||||
|
of moving some lines up in text mode with line wrapping enabled.
|
||||||
|
|
||||||
2004-18-19 Roland Illig <roland.illig@gmx.de>
|
2004-18-19 Roland Illig <roland.illig@gmx.de>
|
||||||
|
|
||||||
* util.h: Added the function free_after for easier handling
|
* util.h: Added the function free_after for easier handling
|
||||||
of dynamically allocated strings.
|
of dynamically allocated strings.
|
||||||
|
|
||||||
2004-18-19 Roland Illig <roland.illig@gmx.de>
|
2004-18-19 Roland Illig <roland.illig@gmx.de>
|
||||||
|
|
||||||
* util.c: Added the function str_replace, which replaces
|
* util.c: Added the function str_replace, which replaces
|
||||||
all occurences of a character in a string.
|
all occurences of a character in a string.
|
||||||
|
|
||||||
|
104
src/view.c
104
src/view.c
@ -1261,6 +1261,36 @@ move_forward2 (WView *view, offset_type current, int lines, offset_type upto)
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* special case for text (non-hex) mode with line wrapping. */
|
||||||
|
static offset_type
|
||||||
|
move_backward2_textmode_wrap (WView * view, offset_type current, int lines)
|
||||||
|
{
|
||||||
|
offset_type p, q, pm;
|
||||||
|
int line;
|
||||||
|
|
||||||
|
if (current == view->last_byte && get_byte (view, current - 1) != '\n')
|
||||||
|
/* There is one virtual '\n' at the end,
|
||||||
|
so that the last line is shown */
|
||||||
|
line = 1;
|
||||||
|
else
|
||||||
|
line = 0;
|
||||||
|
|
||||||
|
for (q = p = current - 1; p > view->first; p--) {
|
||||||
|
if (get_byte (view, p) == '\n' || p == view->first) {
|
||||||
|
pm = p > view->first ? p + 1 : view->first;
|
||||||
|
line += move_forward2 (view, pm, 0, q);
|
||||||
|
if (line >= lines) {
|
||||||
|
if (line == lines)
|
||||||
|
return pm;
|
||||||
|
else
|
||||||
|
return move_forward2 (view, pm, line - lines, 0);
|
||||||
|
}
|
||||||
|
q = p + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p > view->first ? p : view->first;
|
||||||
|
}
|
||||||
|
|
||||||
/* returns the new current pointer */
|
/* returns the new current pointer */
|
||||||
/* Cause even the forward routine became very complex, we in the wrap_mode
|
/* Cause even the forward routine became very complex, we in the wrap_mode
|
||||||
just find the nearest '\n', use move_forward2(p, 0, q) to get the count
|
just find the nearest '\n', use move_forward2(p, 0, q) to get the count
|
||||||
@ -1272,51 +1302,41 @@ move_backward2 (WView *view, offset_type current, int lines)
|
|||||||
offset_type p, q, pm;
|
offset_type p, q, pm;
|
||||||
int line;
|
int line;
|
||||||
|
|
||||||
if (!view->hex_mode && current == view->first)
|
|
||||||
return current;
|
|
||||||
|
|
||||||
if (view->hex_mode) {
|
if (view->hex_mode) {
|
||||||
p = current - lines * view->bytes_per_line;
|
if (view->edit_cursor >= lines * view->bytes_per_line) {
|
||||||
p = (p < view->first) ? view->first : p;
|
view->edit_cursor -= lines * view->bytes_per_line;
|
||||||
if (lines == 1) {
|
} else {
|
||||||
q = view->edit_cursor - view->bytes_per_line;
|
view->edit_cursor %= view->bytes_per_line;
|
||||||
view->edit_cursor = (q < view->first) ? view->edit_cursor : q;
|
}
|
||||||
p = (view->edit_cursor >= current) ? current : p;
|
if (current >= lines * view->bytes_per_line) {
|
||||||
} else {
|
current -= lines * view->bytes_per_line;
|
||||||
q = p + ((LINES - 2) * view->bytes_per_line);
|
} else {
|
||||||
view->edit_cursor = (view->edit_cursor >= q) ?
|
current %= view->bytes_per_line;
|
||||||
p : view->edit_cursor;
|
}
|
||||||
}
|
return current;
|
||||||
return p;
|
|
||||||
} else {
|
} else {
|
||||||
if (current == view->last_byte
|
if (current == view->first)
|
||||||
&& get_byte (view, current - 1) != '\n')
|
return current;
|
||||||
/* There is one virtual '\n' at the end,
|
|
||||||
so that the last line is shown */
|
if (view->wrap_mode)
|
||||||
line = 1;
|
return move_backward2_textmode_wrap (view, current, lines);
|
||||||
else
|
|
||||||
line = 0;
|
/* There is one virtual '\n' at the end,
|
||||||
for (q = p = current - 1; p >= view->first; p--)
|
* so that the last line is shown */
|
||||||
if (get_byte (view, p) == '\n' || p == view->first) {
|
if (current == view->last_byte && get_byte (view, current - 1) != '\n')
|
||||||
pm = p > view->first ? p + 1 : view->first;
|
lines--;
|
||||||
if (!view->wrap_mode) {
|
while (current > view->first && get_byte(view, current - 1) != '\n')
|
||||||
if (line == lines)
|
current--;
|
||||||
return pm;
|
while (lines > 0) {
|
||||||
line++;
|
if (current > view->first)
|
||||||
} else {
|
current--;
|
||||||
line += move_forward2 (view, pm, 0, q);
|
lines--;
|
||||||
if (line >= lines) {
|
while (current > view->first && get_byte(view, current - 1) != '\n')
|
||||||
if (line == lines)
|
current--;
|
||||||
return pm;
|
}
|
||||||
else
|
return current;
|
||||||
return move_forward2 (view, pm, line - lines,
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
q = p + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return p > view->first ? p : view->first;
|
return current; /* unreached */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user