diff --git a/src/viewer/dialogs.c b/src/viewer/dialogs.c
index 1fab867..a6b3fc8 100644
a
|
b
|
mcview_dialog_goto (mcview_t * view, off_t * offset) |
280 | 280 | default: |
281 | 281 | break; |
282 | 282 | } |
283 | | *offset = mcview_bol (view, *offset); |
| 283 | *offset = mcview_bol (view, *offset, 0); |
284 | 284 | } |
285 | 285 | } |
286 | 286 | |
diff --git a/src/viewer/internal.h b/src/viewer/internal.h
index 7c4ab19..fa08628 100644
a
|
b
|
void mcview_done (mcview_t * view); |
289 | 289 | void mcview_select_encoding (mcview_t * view); |
290 | 290 | void mcview_set_codeset (mcview_t * view); |
291 | 291 | void mcview_show_error (mcview_t * view, const char *error); |
292 | | off_t mcview_bol (mcview_t * view, off_t current); |
293 | | off_t mcview_eol (mcview_t * view, off_t current); |
| 292 | off_t mcview_bol (mcview_t * view, off_t current, off_t limit); |
| 293 | off_t mcview_eol (mcview_t * view, off_t current, off_t limit); |
294 | 294 | char *mcview_get_title (const Dlg_head * h, size_t len); |
295 | 295 | gboolean mcview_lock_file (mcview_t * view); |
296 | 296 | gboolean mcview_unlock_file (mcview_t * view); |
diff --git a/src/viewer/lib.c b/src/viewer/lib.c
index f7bb51f..c29d985 100644
a
|
b
|
void |
97 | 97 | mcview_toggle_wrap_mode (mcview_t * view) |
98 | 98 | { |
99 | 99 | if (view->text_wrap_mode) |
100 | | view->dpy_start = mcview_bol (view, view->dpy_start); |
| 100 | view->dpy_start = mcview_bol (view, view->dpy_start, 0); |
101 | 101 | view->text_wrap_mode = !view->text_wrap_mode; |
102 | 102 | view->dpy_bbar_dirty = TRUE; |
103 | 103 | view->dirty++; |
… |
… |
mcview_show_error (mcview_t * view, const char *msg) |
343 | 343 | /* returns index of the first char in the line */ |
344 | 344 | /* it is constant for all line characters */ |
345 | 345 | off_t |
346 | | mcview_bol (mcview_t * view, off_t current) |
| 346 | mcview_bol (mcview_t * view, off_t current, off_t limit) |
347 | 347 | { |
348 | 348 | int c; |
349 | 349 | off_t filesize; |
… |
… |
mcview_bol (mcview_t * view, off_t current) |
361 | 361 | if (c == '\r') |
362 | 362 | current--; |
363 | 363 | } |
364 | | while (current > 0) |
| 364 | while (current > 0 && current >= limit) |
365 | 365 | { |
366 | 366 | if (!mcview_get_byte (view, current - 1, &c)) |
367 | 367 | break; |
… |
… |
mcview_bol (mcview_t * view, off_t current) |
377 | 377 | /* returns index of last char on line + width EOL */ |
378 | 378 | /* mcview_eol of the current line == mcview_bol next line */ |
379 | 379 | off_t |
380 | | mcview_eol (mcview_t * view, off_t current) |
| 380 | mcview_eol (mcview_t * view, off_t current, off_t limit) |
381 | 381 | { |
382 | 382 | int c, prev_ch = 0; |
383 | 383 | off_t filesize; |
… |
… |
mcview_eol (mcview_t * view, off_t current) |
386 | 386 | return 0; |
387 | 387 | if (current >= filesize) |
388 | 388 | return filesize; |
389 | | while (current < filesize) |
| 389 | while (current < filesize && current < limit) |
390 | 390 | { |
391 | 391 | if (!mcview_get_byte (view, current, &c)) |
392 | 392 | break; |
diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c
index 7c864f4..69c839d 100644
a
|
b
|
mcview_load (mcview_t * view, const char *command, const char *file, int start_l |
405 | 405 | canon_fname = vfs_canon (view->filename); |
406 | 406 | load_file_position (canon_fname, &line, &col, &new_offset, &view->saved_bookmarks); |
407 | 407 | new_offset = min (new_offset, mcview_get_filesize (view)); |
408 | | view->dpy_start = mcview_bol (view, new_offset); |
| 408 | view->dpy_start = mcview_bol (view, new_offset, 0); |
409 | 409 | g_free (canon_fname); |
410 | 410 | } |
411 | 411 | else if (start_line > 0) |
diff --git a/src/viewer/move.c b/src/viewer/move.c
index 873ed9a..0f0be77 100644
a
|
b
|
void |
89 | 89 | mcview_move_up (mcview_t * view, off_t lines) |
90 | 90 | { |
91 | 91 | off_t new_offset; |
| 92 | |
92 | 93 | if (view->hex_mode) |
93 | 94 | { |
94 | 95 | off_t bytes = lines * view->bytes_per_line; |
… |
… |
mcview_move_up (mcview_t * view, off_t lines) |
106 | 107 | else |
107 | 108 | { |
108 | 109 | off_t i; |
| 110 | |
109 | 111 | for (i = 0; i < lines; i++) |
110 | 112 | { |
111 | | off_t cur_bol; |
112 | | cur_bol = new_offset = mcview_bol (view, view->dpy_start); |
113 | | if (new_offset > 0) |
114 | | new_offset--; |
115 | | new_offset = mcview_bol (view, new_offset); |
116 | | if (new_offset < 0) |
117 | | new_offset = 0; |
| 113 | if (view->dpy_start == 0) |
| 114 | break; |
118 | 115 | if (view->text_wrap_mode) |
119 | 116 | { |
120 | | size_t last_row_length = (view->dpy_start - new_offset) % view->data_area.width; |
121 | | if (last_row_length != 0 && cur_bol == view->dpy_start) |
122 | | new_offset = max (new_offset, (off_t) (view->dpy_start - last_row_length)); |
| 117 | new_offset = mcview_bol (view, view->dpy_start, view->dpy_start - (off_t) 1); |
| 118 | /* check if dpy_start == BOL or not (then new_offset = dpy_start - 1, |
| 119 | * no need to check more) */ |
| 120 | if (new_offset == view->dpy_start) |
| 121 | { |
| 122 | size_t last_row_length; |
| 123 | |
| 124 | new_offset = mcview_bol (view, new_offset - 1, 0); |
| 125 | last_row_length = (view->dpy_start - new_offset) % view->data_area.width; |
| 126 | if (last_row_length != 0) |
| 127 | { |
| 128 | /* if dpy_start == BOL in wrapped mode, find BOL of previous line |
| 129 | * and move down all but the last rows */ |
| 130 | new_offset = view->dpy_start - (off_t) last_row_length; |
| 131 | } |
| 132 | } |
123 | 133 | else |
124 | | new_offset = max (new_offset, view->dpy_start - (off_t) view->data_area.width); |
| 134 | { |
| 135 | /* if dpy_start != BOL in wrapped mode, just move one row up; |
| 136 | * no need to check if > 0 as there is at least exactly one wrap |
| 137 | * between dpy_start and BOL */ |
| 138 | new_offset = view->dpy_start - (off_t) view->data_area.width; |
| 139 | } |
| 140 | view->dpy_start = new_offset; |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | /* if unwrapped -> current BOL equals dpy_start, just find BOL of previous line */ |
| 145 | new_offset = view->dpy_start - 1; |
| 146 | view->dpy_start = mcview_bol (view, new_offset, 0); |
125 | 147 | } |
126 | | view->dpy_start = new_offset; |
127 | 148 | } |
128 | 149 | } |
129 | 150 | mcview_movement_fixups (view, TRUE); |
… |
… |
mcview_move_down (mcview_t * view, off_t lines) |
153 | 174 | } |
154 | 175 | else |
155 | 176 | { |
156 | | off_t i; |
157 | 177 | off_t new_offset = 0; |
158 | 178 | |
159 | 179 | if (view->dpy_end - view->dpy_start > last_byte - view->dpy_end) |
160 | 180 | { |
161 | 181 | while (lines-- > 0) |
162 | 182 | { |
163 | | new_offset = mcview_eol (view, view->dpy_end); |
164 | 183 | if (view->text_wrap_mode) |
165 | | new_offset = min (new_offset, view->dpy_end + (off_t) view->data_area.width); |
166 | | view->dpy_end = new_offset; |
| 184 | view->dpy_end = |
| 185 | mcview_eol (view, view->dpy_end, |
| 186 | view->dpy_end + (off_t) view->data_area.width); |
| 187 | else |
| 188 | view->dpy_end = mcview_eol (view, view->dpy_end, last_byte); |
167 | 189 | |
168 | | new_offset = mcview_eol (view, view->dpy_start); |
169 | 190 | if (view->text_wrap_mode) |
170 | | new_offset = min (new_offset, view->dpy_start + (off_t) view->data_area.width); |
| 191 | new_offset = |
| 192 | mcview_eol (view, view->dpy_start, |
| 193 | view->dpy_start + (off_t) view->data_area.width); |
| 194 | else |
| 195 | new_offset = mcview_eol (view, view->dpy_start, last_byte); |
171 | 196 | if (new_offset < last_byte) |
172 | 197 | view->dpy_start = new_offset; |
173 | 198 | if (view->dpy_end >= last_byte) |
… |
… |
mcview_move_down (mcview_t * view, off_t lines) |
176 | 201 | } |
177 | 202 | else |
178 | 203 | { |
| 204 | off_t i; |
179 | 205 | for (i = 0; i < lines && new_offset < last_byte; i++) |
180 | 206 | { |
181 | | new_offset = mcview_eol (view, view->dpy_start); |
182 | 207 | if (view->text_wrap_mode) |
183 | | new_offset = min (new_offset, view->dpy_start + (off_t) view->data_area.width); |
| 208 | new_offset = |
| 209 | mcview_eol (view, view->dpy_start, |
| 210 | view->dpy_start + (off_t) view->data_area.width); |
| 211 | else |
| 212 | new_offset = mcview_eol (view, view->dpy_start, last_byte); |
184 | 213 | if (new_offset < last_byte) |
185 | 214 | view->dpy_start = new_offset; |
186 | 215 | } |
… |
… |
mcview_moveto_bol (mcview_t * view) |
314 | 343 | } |
315 | 344 | else if (!view->text_wrap_mode) |
316 | 345 | { |
317 | | view->dpy_start = mcview_bol (view, view->dpy_start); |
| 346 | view->dpy_start = mcview_bol (view, view->dpy_start, 0); |
318 | 347 | } |
319 | 348 | view->dpy_text_column = 0; |
320 | 349 | mcview_movement_fixups (view, TRUE); |
… |
… |
mcview_moveto_eol (mcview_t * view) |
344 | 373 | else |
345 | 374 | { |
346 | 375 | off_t eol; |
347 | | bol = mcview_bol (view, view->dpy_start); |
348 | | eol = mcview_eol (view, view->dpy_start); |
| 376 | bol = mcview_bol (view, view->dpy_start, 0); |
| 377 | eol = mcview_eol (view, view->dpy_start, mcview_get_filesize (view)); |
349 | 378 | if (!view->utf8) |
350 | 379 | { |
351 | 380 | if (eol > bol) |
… |
… |
mcview_moveto_match (mcview_t * view) |
467 | 496 | } |
468 | 497 | else |
469 | 498 | { |
470 | | view->dpy_start = mcview_bol (view, offset); |
| 499 | view->dpy_start = mcview_bol (view, offset, 0); |
471 | 500 | } |
472 | 501 | |
473 | 502 | mcview_scroll_to_cursor (view); |