2000-06-19 08:22:15 +04:00
|
|
|
/**************************************************************************
|
2016-08-29 18:10:49 +03:00
|
|
|
* move.c -- This file is part of GNU nano. *
|
2000-06-19 08:22:15 +04:00
|
|
|
* *
|
2017-04-09 13:09:23 +03:00
|
|
|
* Copyright (C) 1999-2011, 2013-2017 Free Software Foundation, Inc. *
|
2016-08-29 16:14:18 +03:00
|
|
|
* Copyright (C) 2014, 2015, 2016 Benno Schulenberg *
|
|
|
|
* *
|
2016-08-29 18:10:49 +03:00
|
|
|
* GNU nano is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published *
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, *
|
|
|
|
* or (at your option) any later version. *
|
2000-06-19 08:22:15 +04:00
|
|
|
* *
|
2016-08-29 18:10:49 +03:00
|
|
|
* GNU nano is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty *
|
|
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU General Public License for more details. *
|
2000-06-19 08:22:15 +04:00
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
2016-08-29 18:10:49 +03:00
|
|
|
* along with this program. If not, see http://www.gnu.org/licenses/. *
|
2000-06-19 08:22:15 +04:00
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2005-12-08 05:47:10 +03:00
|
|
|
#include "proto.h"
|
2001-04-28 22:03:52 +04:00
|
|
|
|
2000-06-19 08:22:15 +04:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Move to the first line of the file. */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_first_line(void)
|
2004-05-24 01:33:23 +04:00
|
|
|
{
|
2016-10-12 22:07:16 +03:00
|
|
|
openfile->current = openfile->fileage;
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->current_x = 0;
|
2005-07-14 22:01:08 +04:00
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
2016-04-25 22:14:18 +03:00
|
|
|
refresh_needed = TRUE;
|
2004-05-24 01:33:23 +04:00
|
|
|
}
|
|
|
|
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Move to the last line of the file. */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_last_line(void)
|
2004-05-24 01:33:23 +04:00
|
|
|
{
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->current = openfile->filebot;
|
2005-11-05 20:50:06 +03:00
|
|
|
openfile->current_x = strlen(openfile->filebot->data);
|
|
|
|
openfile->placewewant = xplustabs();
|
2016-10-12 22:07:16 +03:00
|
|
|
|
|
|
|
/* Set the last line of the screen as the target for the cursor. */
|
2005-08-16 05:27:05 +04:00
|
|
|
openfile->current_y = editwinrows - 1;
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2016-04-25 22:14:18 +03:00
|
|
|
refresh_needed = TRUE;
|
2016-04-12 11:24:57 +03:00
|
|
|
focusing = FALSE;
|
2004-05-24 01:33:23 +04:00
|
|
|
}
|
|
|
|
|
2017-03-29 11:27:49 +03:00
|
|
|
/* Determine the actual current chunk and the target column. */
|
|
|
|
void get_edge_and_target(size_t *leftedge, size_t *target_column)
|
|
|
|
{
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (ISSET(SOFTWRAP)) {
|
2017-08-22 16:59:20 +03:00
|
|
|
size_t shim = editwincols * (1 + (tabsize / editwincols));
|
|
|
|
|
2017-07-09 22:07:38 +03:00
|
|
|
*leftedge = leftedge_for(xplustabs(), openfile->current);
|
2017-08-22 16:59:20 +03:00
|
|
|
*target_column = (openfile->placewewant + shim - *leftedge) % editwincols;
|
2017-03-29 11:27:49 +03:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
*leftedge = 0;
|
|
|
|
*target_column = openfile->placewewant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 23:03:07 +03:00
|
|
|
/* Return the index in line->data that corresponds to the given column on the
|
|
|
|
* chunk that starts at the given leftedge. If the index lands on a tab, and
|
|
|
|
* this tab starts on an earlier chunk, and the tab ends on this row OR we're
|
|
|
|
* going forward, then increment the index and recalculate leftedge. */
|
|
|
|
size_t proper_x(filestruct *line, size_t *leftedge, bool forward,
|
|
|
|
size_t column, bool *shifted)
|
2017-08-20 16:20:20 +03:00
|
|
|
{
|
2017-08-24 23:03:07 +03:00
|
|
|
size_t index = actual_x(line->data, column);
|
2017-08-20 16:20:20 +03:00
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
2017-08-24 23:03:07 +03:00
|
|
|
if (ISSET(SOFTWRAP) && line->data[index] == '\t' && (forward ||
|
|
|
|
*leftedge / tabsize < (*leftedge + editwincols) / tabsize) &&
|
|
|
|
*leftedge % tabsize != 0 && column < *leftedge + tabsize) {
|
2017-08-20 16:20:20 +03:00
|
|
|
index++;
|
2017-08-24 23:03:07 +03:00
|
|
|
|
|
|
|
*leftedge = leftedge_for(strnlenpt(line->data, index), line);
|
|
|
|
|
|
|
|
if (shifted != NULL)
|
|
|
|
*shifted = TRUE;
|
|
|
|
}
|
2017-08-20 16:20:20 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2017-08-24 23:03:07 +03:00
|
|
|
/* Adjust the values for current_x and placewewant in case we have landed in
|
|
|
|
* the middle of a tab that crosses a row boundary. */
|
|
|
|
void set_proper_index_and_pww(size_t *leftedge, size_t target, bool forward)
|
|
|
|
{
|
|
|
|
bool shifted = FALSE;
|
|
|
|
|
|
|
|
openfile->current_x = proper_x(openfile->current, leftedge, forward,
|
|
|
|
actual_last_column(*leftedge, target), &shifted);
|
|
|
|
|
|
|
|
/* If the index was incremented, try going to the target column. */
|
|
|
|
if (shifted) {
|
|
|
|
size_t newer_x = actual_x(openfile->current->data, *leftedge + target);
|
|
|
|
|
|
|
|
if (newer_x > openfile->current_x)
|
|
|
|
openfile->current_x = newer_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
openfile->placewewant = *leftedge + target;
|
|
|
|
}
|
|
|
|
|
2017-03-28 12:24:32 +03:00
|
|
|
/* Move up nearly one screenful. */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_page_up(void)
|
2000-07-03 08:24:39 +04:00
|
|
|
{
|
2017-03-27 12:38:52 +03:00
|
|
|
int mustmove = (editwinrows < 3) ? 1 : editwinrows - 2;
|
2017-03-29 11:27:49 +03:00
|
|
|
size_t leftedge, target_column;
|
2005-07-17 02:50:30 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
/* If we're not in smooth scrolling mode, put the cursor at the
|
|
|
|
* beginning of the top line of the edit window, as Pico does. */
|
2016-12-09 15:31:04 +03:00
|
|
|
if (!ISSET(SMOOTH_SCROLL)) {
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current = openfile->edittop;
|
2017-08-29 20:28:44 +03:00
|
|
|
leftedge = openfile->firstcolumn;
|
2017-08-30 22:57:35 +03:00
|
|
|
openfile->current_y = 0;
|
2017-08-20 16:20:20 +03:00
|
|
|
target_column = 0;
|
|
|
|
} else
|
|
|
|
get_edge_and_target(&leftedge, &target_column);
|
2017-01-20 21:03:49 +03:00
|
|
|
|
|
|
|
/* Move up the required number of lines or chunks. If we can't, we're
|
|
|
|
* at the top of the file, so put the cursor there and get out. */
|
|
|
|
if (go_back_chunks(mustmove, &openfile->current, &leftedge) > 0) {
|
|
|
|
do_first_line();
|
|
|
|
return;
|
2009-11-24 20:15:53 +03:00
|
|
|
}
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2017-08-24 23:03:07 +03:00
|
|
|
set_proper_index_and_pww(&leftedge, target_column, FALSE);
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2017-04-07 22:40:33 +03:00
|
|
|
/* Move the viewport so that the cursor stays immobile, if possible. */
|
2016-10-20 22:11:11 +03:00
|
|
|
adjust_viewport(STATIONARY);
|
2016-04-25 22:14:18 +03:00
|
|
|
refresh_needed = TRUE;
|
2000-07-03 08:24:39 +04:00
|
|
|
}
|
|
|
|
|
2017-03-28 12:24:32 +03:00
|
|
|
/* Move down nearly one screenful. */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_page_down(void)
|
2002-09-07 00:35:28 +04:00
|
|
|
{
|
2017-03-27 12:38:52 +03:00
|
|
|
int mustmove = (editwinrows < 3) ? 1 : editwinrows - 2;
|
2017-03-29 11:27:49 +03:00
|
|
|
size_t leftedge, target_column;
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
/* If we're not in smooth scrolling mode, put the cursor at the
|
|
|
|
* beginning of the top line of the edit window, as Pico does. */
|
2016-12-09 15:31:04 +03:00
|
|
|
if (!ISSET(SMOOTH_SCROLL)) {
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current = openfile->edittop;
|
2017-08-29 20:28:44 +03:00
|
|
|
leftedge = openfile->firstcolumn;
|
2017-08-30 22:57:35 +03:00
|
|
|
openfile->current_y = 0;
|
2017-08-20 16:20:20 +03:00
|
|
|
target_column = 0;
|
|
|
|
} else
|
|
|
|
get_edge_and_target(&leftedge, &target_column);
|
2016-08-21 16:49:39 +03:00
|
|
|
|
2017-01-20 21:03:49 +03:00
|
|
|
/* Move down the required number of lines or chunks. If we can't, we're
|
|
|
|
* at the bottom of the file, so put the cursor there and get out. */
|
|
|
|
if (go_forward_chunks(mustmove, &openfile->current, &leftedge) > 0) {
|
|
|
|
do_last_line();
|
|
|
|
return;
|
|
|
|
}
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2017-08-24 23:03:07 +03:00
|
|
|
set_proper_index_and_pww(&leftedge, target_column, TRUE);
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2017-04-07 22:40:33 +03:00
|
|
|
/* Move the viewport so that the cursor stays immobile, if possible. */
|
2016-10-20 22:11:11 +03:00
|
|
|
adjust_viewport(STATIONARY);
|
2016-04-25 22:14:18 +03:00
|
|
|
refresh_needed = TRUE;
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
|
|
|
|
2005-07-20 23:24:11 +04:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
2017-04-17 13:01:03 +03:00
|
|
|
/* Move to the beginning of the last beginning-of-paragraph line before the
|
|
|
|
* current line. If update_screen is TRUE, update the screen afterwards. */
|
|
|
|
void do_para_begin(bool update_screen)
|
2005-07-20 23:24:11 +04:00
|
|
|
{
|
2016-10-12 22:10:04 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2017-08-30 22:57:35 +03:00
|
|
|
if (openfile->current != openfile->fileage)
|
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
|
|
|
|
while (!begpar(openfile->current))
|
|
|
|
openfile->current = openfile->current->prev;
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2005-11-09 07:20:55 +03:00
|
|
|
openfile->current_x = 0;
|
|
|
|
|
2017-04-17 13:01:03 +03:00
|
|
|
if (update_screen)
|
2017-08-18 22:46:14 +03:00
|
|
|
edit_redraw(was_current, CENTERING);
|
2005-07-20 23:24:11 +04:00
|
|
|
}
|
|
|
|
|
2005-11-10 08:26:37 +03:00
|
|
|
/* Move down to the beginning of the last line of the current paragraph.
|
|
|
|
* Then move down one line farther if there is such a line, or to the
|
2017-04-17 13:01:03 +03:00
|
|
|
* end of the current line if not. If update_screen is TRUE, update the
|
2005-12-08 10:09:08 +03:00
|
|
|
* screen afterwards. A line is the last line of a paragraph if it is
|
|
|
|
* in a paragraph, and the next line either is the beginning line of a
|
|
|
|
* paragraph or isn't in a paragraph. */
|
2017-04-17 13:01:03 +03:00
|
|
|
void do_para_end(bool update_screen)
|
2005-07-20 23:24:11 +04:00
|
|
|
{
|
2016-10-12 22:10:04 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2005-11-04 00:08:39 +03:00
|
|
|
while (openfile->current != openfile->filebot &&
|
2016-05-27 22:22:56 +03:00
|
|
|
!inpar(openfile->current))
|
2005-07-20 23:24:11 +04:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
|
2005-11-04 00:08:39 +03:00
|
|
|
while (openfile->current != openfile->filebot &&
|
2016-05-27 22:22:56 +03:00
|
|
|
inpar(openfile->current->next) &&
|
|
|
|
!begpar(openfile->current->next)) {
|
2005-07-20 23:24:11 +04:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
}
|
|
|
|
|
2005-11-09 07:20:55 +03:00
|
|
|
if (openfile->current != openfile->filebot) {
|
2005-07-20 23:24:11 +04:00
|
|
|
openfile->current = openfile->current->next;
|
2005-11-09 07:20:55 +03:00
|
|
|
openfile->current_x = 0;
|
2016-04-10 22:16:19 +03:00
|
|
|
} else
|
2005-11-09 07:20:55 +03:00
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2017-04-17 13:01:03 +03:00
|
|
|
if (update_screen)
|
2017-08-18 22:46:14 +03:00
|
|
|
edit_redraw(was_current, CENTERING);
|
2005-07-20 23:24:11 +04:00
|
|
|
}
|
|
|
|
|
2017-08-18 23:17:05 +03:00
|
|
|
/* Move up to first start of a paragraph before the current line. */
|
|
|
|
void do_para_begin_void(void)
|
|
|
|
{
|
|
|
|
do_para_begin(TRUE);
|
|
|
|
}
|
|
|
|
|
2017-04-07 22:40:33 +03:00
|
|
|
/* Move down to just after the first end of a paragraph. */
|
2005-07-20 23:24:11 +04:00
|
|
|
void do_para_end_void(void)
|
|
|
|
{
|
|
|
|
do_para_end(TRUE);
|
|
|
|
}
|
|
|
|
#endif /* !DISABLE_JUSTIFY */
|
|
|
|
|
2017-08-30 22:57:35 +03:00
|
|
|
/* Move to the preceding block of text. */
|
2016-06-25 16:16:52 +03:00
|
|
|
void do_prev_block(void)
|
|
|
|
{
|
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
bool is_text = FALSE, seen_text = FALSE;
|
|
|
|
|
|
|
|
/* Skip backward until first blank line after some nonblank line(s). */
|
|
|
|
while (openfile->current->prev != NULL && (!seen_text || is_text)) {
|
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
is_text = !white_string(openfile->current->data);
|
|
|
|
seen_text = seen_text || is_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Step forward one line again if this one is blank. */
|
|
|
|
if (openfile->current->next != NULL &&
|
|
|
|
white_string(openfile->current->data))
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
|
|
|
|
openfile->current_x = 0;
|
2017-08-18 22:46:14 +03:00
|
|
|
edit_redraw(was_current, CENTERING);
|
2016-06-25 16:16:52 +03:00
|
|
|
}
|
|
|
|
|
2017-08-30 22:57:35 +03:00
|
|
|
/* Move to the next block of text. */
|
2016-06-25 16:16:52 +03:00
|
|
|
void do_next_block(void)
|
|
|
|
{
|
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
bool is_white = white_string(openfile->current->data);
|
|
|
|
bool seen_white = is_white;
|
|
|
|
|
|
|
|
/* Skip forward until first nonblank line after some blank line(s). */
|
|
|
|
while (openfile->current->next != NULL && (!seen_white || is_white)) {
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
is_white = white_string(openfile->current->data);
|
|
|
|
seen_white = seen_white || is_white;
|
|
|
|
}
|
|
|
|
|
|
|
|
openfile->current_x = 0;
|
2017-08-18 22:46:14 +03:00
|
|
|
edit_redraw(was_current, CENTERING);
|
2016-06-25 16:16:52 +03:00
|
|
|
}
|
|
|
|
|
2017-08-30 22:57:35 +03:00
|
|
|
/* Move to the previous word. If allow_punct is TRUE, treat punctuation
|
|
|
|
* as part of a word. When requested, update the screen afterwards. */
|
2017-04-17 13:01:03 +03:00
|
|
|
void do_prev_word(bool allow_punct, bool update_screen)
|
2005-07-21 01:31:19 +04:00
|
|
|
{
|
2016-10-12 22:10:04 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
2015-09-05 12:40:09 +03:00
|
|
|
bool seen_a_word = FALSE, step_forward = FALSE;
|
2005-07-21 01:31:19 +04:00
|
|
|
|
2015-09-05 12:40:09 +03:00
|
|
|
/* Move backward until we pass over the start of a word. */
|
|
|
|
while (TRUE) {
|
|
|
|
/* If at the head of a line, move to the end of the preceding one. */
|
|
|
|
if (openfile->current_x == 0) {
|
|
|
|
if (openfile->current->prev == NULL)
|
2005-07-21 01:31:19 +04:00
|
|
|
break;
|
2015-09-05 12:40:09 +03:00
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
2005-07-21 01:31:19 +04:00
|
|
|
}
|
|
|
|
|
2015-09-05 12:40:09 +03:00
|
|
|
/* Step back one character. */
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
2005-07-21 01:31:19 +04:00
|
|
|
|
2015-09-05 12:40:09 +03:00
|
|
|
if (is_word_mbchar(openfile->current->data + openfile->current_x,
|
|
|
|
allow_punct)) {
|
|
|
|
seen_a_word = TRUE;
|
|
|
|
/* If at the head of a line now, this surely is a word start. */
|
2005-07-21 01:31:19 +04:00
|
|
|
if (openfile->current_x == 0)
|
2015-09-05 12:40:09 +03:00
|
|
|
break;
|
|
|
|
} else if (seen_a_word) {
|
|
|
|
/* This is space now: we've overshot the start of the word. */
|
|
|
|
step_forward = TRUE;
|
|
|
|
break;
|
2005-07-21 01:31:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-05 12:40:09 +03:00
|
|
|
if (step_forward)
|
|
|
|
/* Move one character forward again to sit on the start of the word. */
|
|
|
|
openfile->current_x = move_mbright(openfile->current->data,
|
|
|
|
openfile->current_x);
|
2005-07-21 01:31:19 +04:00
|
|
|
|
2017-08-18 22:46:14 +03:00
|
|
|
if (update_screen)
|
|
|
|
edit_redraw(was_current, FLOWING);
|
2005-07-21 01:31:19 +04:00
|
|
|
}
|
|
|
|
|
2017-08-30 22:57:35 +03:00
|
|
|
/* Move to the next word. If allow_punct is TRUE, treat punctuation
|
|
|
|
* as part of a word. When requested, update the screen afterwards.
|
|
|
|
* Return TRUE if we started on a word, and FALSE otherwise. */
|
2017-04-17 13:01:03 +03:00
|
|
|
bool do_next_word(bool allow_punct, bool update_screen)
|
2016-02-22 15:49:08 +03:00
|
|
|
{
|
2016-10-12 22:10:04 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
2016-02-22 15:49:08 +03:00
|
|
|
bool started_on_word = is_word_mbchar(openfile->current->data +
|
|
|
|
openfile->current_x, allow_punct);
|
|
|
|
bool seen_space = !started_on_word;
|
|
|
|
|
|
|
|
/* Move forward until we reach the start of a word. */
|
|
|
|
while (TRUE) {
|
|
|
|
/* If at the end of a line, move to the beginning of the next one. */
|
|
|
|
if (openfile->current->data[openfile->current_x] == '\0') {
|
2017-08-30 22:57:35 +03:00
|
|
|
/* When at end of file, stop. */
|
2016-02-22 15:49:08 +03:00
|
|
|
if (openfile->current->next == NULL)
|
|
|
|
break;
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_x = 0;
|
|
|
|
seen_space = TRUE;
|
|
|
|
} else {
|
|
|
|
/* Step forward one character. */
|
|
|
|
openfile->current_x = move_mbright(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this is not a word character, then it's a separator; else
|
|
|
|
* if we've already seen a separator, then it's a word start. */
|
|
|
|
if (!is_word_mbchar(openfile->current->data + openfile->current_x,
|
|
|
|
allow_punct))
|
|
|
|
seen_space = TRUE;
|
|
|
|
else if (seen_space)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-18 22:46:14 +03:00
|
|
|
if (update_screen)
|
|
|
|
edit_redraw(was_current, FLOWING);
|
2016-02-22 15:49:08 +03:00
|
|
|
|
|
|
|
/* Return whether we started on a word. */
|
|
|
|
return started_on_word;
|
|
|
|
}
|
|
|
|
|
2017-08-18 23:17:05 +03:00
|
|
|
/* Move to the previous word in the file, treating punctuation as part of a
|
|
|
|
* word if the WORD_BOUNDS flag is set, and update the screen afterwards. */
|
|
|
|
void do_prev_word_void(void)
|
|
|
|
{
|
|
|
|
do_prev_word(ISSET(WORD_BOUNDS), TRUE);
|
|
|
|
}
|
|
|
|
|
2016-02-22 15:49:08 +03:00
|
|
|
/* Move to the next word in the file, treating punctuation as part of a word
|
|
|
|
* if the WORD_BOUNDS flag is set, and update the screen afterwards. */
|
|
|
|
void do_next_word_void(void)
|
|
|
|
{
|
|
|
|
do_next_word(ISSET(WORD_BOUNDS), TRUE);
|
|
|
|
}
|
2005-07-21 01:31:19 +04:00
|
|
|
|
2017-01-20 09:04:44 +03:00
|
|
|
/* Move to the beginning of the current line (or softwrapped chunk).
|
2017-08-18 00:50:04 +03:00
|
|
|
* When enabled, do a smart home. When softwrapping, go the beginning
|
|
|
|
* of the full line when already at the start of a chunk. */
|
|
|
|
void do_home(void)
|
2005-07-20 23:24:11 +04:00
|
|
|
{
|
2017-01-20 09:04:44 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
size_t was_column = xplustabs();
|
2017-01-20 09:04:44 +03:00
|
|
|
bool moved_off_chunk = TRUE;
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2017-01-20 09:04:44 +03:00
|
|
|
bool moved = FALSE;
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
size_t leftedge = 0, leftedge_x = 0;
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2017-02-19 20:51:50 +03:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2017-07-09 22:07:38 +03:00
|
|
|
leftedge = leftedge_for(was_column, openfile->current);
|
2017-08-24 23:03:07 +03:00
|
|
|
leftedge_x = proper_x(openfile->current, &leftedge, FALSE, leftedge,
|
|
|
|
NULL);
|
2017-02-19 20:51:50 +03:00
|
|
|
}
|
2017-01-20 09:04:44 +03:00
|
|
|
|
2017-08-18 00:50:04 +03:00
|
|
|
if (ISSET(SMART_HOME)) {
|
2017-01-20 09:04:44 +03:00
|
|
|
size_t indent_x = indent_length(openfile->current->data);
|
|
|
|
|
|
|
|
if (openfile->current->data[indent_x] != '\0') {
|
|
|
|
/* If we're exactly on the indent, move fully home. Otherwise,
|
|
|
|
* when not softwrapping or not after the first nonblank chunk,
|
|
|
|
* move to the first nonblank character. */
|
|
|
|
if (openfile->current_x == indent_x) {
|
|
|
|
openfile->current_x = 0;
|
|
|
|
moved = TRUE;
|
|
|
|
} else if (!ISSET(SOFTWRAP) || leftedge_x <= indent_x) {
|
|
|
|
openfile->current_x = indent_x;
|
|
|
|
moved = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2017-01-20 09:04:44 +03:00
|
|
|
if (!moved && ISSET(SOFTWRAP)) {
|
|
|
|
/* If already at the left edge of the screen, move fully home.
|
|
|
|
* Otherwise, move to the left edge. */
|
2017-08-18 00:50:04 +03:00
|
|
|
if (openfile->current_x == leftedge_x)
|
2005-07-20 23:24:11 +04:00
|
|
|
openfile->current_x = 0;
|
2017-01-20 09:04:44 +03:00
|
|
|
else {
|
|
|
|
openfile->current_x = leftedge_x;
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
openfile->placewewant = leftedge;
|
2017-01-20 09:04:44 +03:00
|
|
|
moved_off_chunk = FALSE;
|
|
|
|
}
|
|
|
|
} else if (!moved)
|
2005-07-20 23:24:11 +04:00
|
|
|
#endif
|
|
|
|
openfile->current_x = 0;
|
2016-05-27 22:22:56 +03:00
|
|
|
|
2017-04-07 12:21:26 +03:00
|
|
|
if (moved_off_chunk)
|
|
|
|
openfile->placewewant = 0;
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2017-03-29 20:30:37 +03:00
|
|
|
/* If we changed chunk, we might be offscreen. Otherwise,
|
|
|
|
* update current if the mark is on or we changed "page". */
|
2017-08-18 22:46:14 +03:00
|
|
|
if (ISSET(SOFTWRAP) && moved_off_chunk)
|
|
|
|
edit_redraw(was_current, FLOWING);
|
|
|
|
else if (line_needs_update(was_column, openfile->placewewant))
|
2005-07-20 23:24:11 +04:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2017-01-20 11:07:15 +03:00
|
|
|
/* Move to the end of the current line (or softwrapped chunk).
|
2017-08-18 00:50:04 +03:00
|
|
|
* When softwrapping and alredy at the end of a chunk, go to the
|
|
|
|
* end of the full line. */
|
|
|
|
void do_end(void)
|
2005-07-20 23:24:11 +04:00
|
|
|
{
|
2017-03-29 11:35:11 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
size_t was_column = xplustabs();
|
2017-01-20 11:07:15 +03:00
|
|
|
size_t line_len = strlen(openfile->current->data);
|
|
|
|
bool moved_off_chunk = TRUE;
|
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (ISSET(SOFTWRAP)) {
|
2017-06-27 13:34:11 +03:00
|
|
|
bool last_chunk = FALSE;
|
2017-07-09 22:07:38 +03:00
|
|
|
size_t leftedge = leftedge_for(was_column, openfile->current);
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
|
2017-06-27 13:34:11 +03:00
|
|
|
leftedge, &last_chunk);
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
size_t rightedge_x;
|
2017-06-27 13:34:11 +03:00
|
|
|
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
/* If we're on the last chunk, we're already at the end of the line.
|
|
|
|
* Otherwise, we're one column past the end of the line. Shifting
|
|
|
|
* backwards one column might put us in the middle of a multi-column
|
|
|
|
* character, but actual_x() will fix that. */
|
|
|
|
if (!last_chunk)
|
|
|
|
rightedge--;
|
|
|
|
|
|
|
|
rightedge_x = actual_x(openfile->current->data, rightedge);
|
2017-01-20 11:07:15 +03:00
|
|
|
|
2017-03-29 20:30:37 +03:00
|
|
|
/* If already at the right edge of the screen, move fully to
|
|
|
|
* the end of the line. Otherwise, move to the right edge. */
|
2017-08-18 00:50:04 +03:00
|
|
|
if (openfile->current_x == rightedge_x)
|
2017-01-20 11:07:15 +03:00
|
|
|
openfile->current_x = line_len;
|
|
|
|
else {
|
|
|
|
openfile->current_x = rightedge_x;
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
openfile->placewewant = rightedge;
|
2017-01-20 11:07:15 +03:00
|
|
|
moved_off_chunk = FALSE;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
openfile->current_x = line_len;
|
2005-07-20 23:24:11 +04:00
|
|
|
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 21:44:53 +03:00
|
|
|
if (moved_off_chunk)
|
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2017-01-20 11:07:15 +03:00
|
|
|
/* If we changed chunk, we might be offscreen. Otherwise,
|
|
|
|
* update current if the mark is on or we changed "page". */
|
2017-08-18 22:46:14 +03:00
|
|
|
if (ISSET(SOFTWRAP) && moved_off_chunk)
|
|
|
|
edit_redraw(was_current, FLOWING);
|
|
|
|
else if (line_needs_update(was_column, openfile->placewewant))
|
2005-07-20 23:24:11 +04:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2017-01-20 20:11:17 +03:00
|
|
|
/* Move the cursor to the preceding line or chunk. If scroll_only is TRUE,
|
|
|
|
* also scroll the screen one row, so the cursor stays in the same spot. */
|
2016-07-25 18:23:45 +03:00
|
|
|
void do_up(bool scroll_only)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
2017-08-22 19:51:02 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
2017-03-29 11:27:49 +03:00
|
|
|
size_t leftedge, target_column;
|
2017-01-20 20:11:17 +03:00
|
|
|
|
|
|
|
/* When just scrolling and the top of the file is onscreen, get out. */
|
2017-02-01 04:23:21 +03:00
|
|
|
if (scroll_only && openfile->edittop == openfile->fileage &&
|
|
|
|
openfile->firstcolumn == 0)
|
2017-01-20 20:11:17 +03:00
|
|
|
return;
|
|
|
|
|
2017-03-29 11:27:49 +03:00
|
|
|
get_edge_and_target(&leftedge, &target_column);
|
2016-07-26 12:47:53 +03:00
|
|
|
|
2017-03-28 12:24:32 +03:00
|
|
|
/* If we can't move up one line or chunk, we're at top of file. */
|
2017-01-20 20:11:17 +03:00
|
|
|
if (go_back_chunks(1, &openfile->current, &leftedge) > 0)
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2003-09-08 03:57:24 +04:00
|
|
|
|
2017-08-24 23:03:07 +03:00
|
|
|
set_proper_index_and_pww(&leftedge, target_column, FALSE);
|
2004-05-29 00:44:09 +04:00
|
|
|
|
2017-08-19 02:59:38 +03:00
|
|
|
if (scroll_only)
|
|
|
|
edit_scroll(UPWARD, 1);
|
|
|
|
|
2017-08-22 19:51:02 +03:00
|
|
|
edit_redraw(was_current, FLOWING);
|
2017-08-19 02:59:38 +03:00
|
|
|
|
|
|
|
/* <Up> should not change placewewant, so restore it. */
|
|
|
|
openfile->placewewant = leftedge + target_column;
|
2002-07-19 05:08:59 +04:00
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
|
2017-01-20 20:11:17 +03:00
|
|
|
/* Move the cursor to next line or chunk. If scroll_only is TRUE, also
|
|
|
|
* scroll the screen one row, so the cursor stays in the same spot. */
|
2016-07-25 18:23:45 +03:00
|
|
|
void do_down(bool scroll_only)
|
2002-12-22 19:30:00 +03:00
|
|
|
{
|
2017-08-22 19:51:02 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
2017-03-29 11:27:49 +03:00
|
|
|
size_t leftedge, target_column;
|
2017-03-27 18:34:13 +03:00
|
|
|
|
2017-03-29 11:27:49 +03:00
|
|
|
get_edge_and_target(&leftedge, &target_column);
|
2009-08-30 07:50:16 +04:00
|
|
|
|
2017-03-28 12:24:32 +03:00
|
|
|
/* If we can't move down one line or chunk, we're at bottom of file. */
|
2017-01-20 20:11:17 +03:00
|
|
|
if (go_forward_chunks(1, &openfile->current, &leftedge) > 0)
|
|
|
|
return;
|
|
|
|
|
2017-08-24 23:03:07 +03:00
|
|
|
set_proper_index_and_pww(&leftedge, target_column, TRUE);
|
2016-04-15 15:39:54 +03:00
|
|
|
|
2017-08-19 02:59:38 +03:00
|
|
|
if (scroll_only)
|
|
|
|
edit_scroll(DOWNWARD, 1);
|
|
|
|
|
2017-08-22 19:51:02 +03:00
|
|
|
edit_redraw(was_current, FLOWING);
|
2017-08-19 02:59:38 +03:00
|
|
|
|
|
|
|
/* <Down> should not change placewewant, so restore it. */
|
|
|
|
openfile->placewewant = leftedge + target_column;
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
2005-10-24 06:12:09 +04:00
|
|
|
|
2017-08-18 23:17:05 +03:00
|
|
|
/* Move up one line or chunk. */
|
|
|
|
void do_up_void(void)
|
|
|
|
{
|
|
|
|
do_up(FALSE);
|
|
|
|
}
|
|
|
|
|
2017-01-20 20:11:17 +03:00
|
|
|
/* Move down one line or chunk. */
|
2006-07-07 02:17:47 +04:00
|
|
|
void do_down_void(void)
|
|
|
|
{
|
2016-07-25 18:23:45 +03:00
|
|
|
do_down(FALSE);
|
2006-07-07 02:17:47 +04:00
|
|
|
}
|
|
|
|
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2017-01-20 20:11:17 +03:00
|
|
|
/* Scroll up one line or chunk without scrolling the cursor. */
|
2016-07-25 18:23:45 +03:00
|
|
|
void do_scroll_up(void)
|
|
|
|
{
|
|
|
|
do_up(TRUE);
|
|
|
|
}
|
|
|
|
|
2017-01-20 20:11:17 +03:00
|
|
|
/* Scroll down one line or chunk without scrolling the cursor. */
|
2005-10-24 06:12:09 +04:00
|
|
|
void do_scroll_down(void)
|
|
|
|
{
|
2006-07-07 02:17:47 +04:00
|
|
|
do_down(TRUE);
|
2005-10-24 06:12:09 +04:00
|
|
|
}
|
2006-07-07 02:17:47 +04:00
|
|
|
#endif
|
2000-06-19 08:22:15 +04:00
|
|
|
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Move left one character. */
|
2005-09-13 08:53:44 +04:00
|
|
|
void do_left(void)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
2017-08-22 19:51:02 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
if (openfile->current_x > 0)
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
2016-05-27 22:22:56 +03:00
|
|
|
openfile->current_x);
|
2005-07-09 00:09:16 +04:00
|
|
|
else if (openfile->current != openfile->fileage) {
|
2017-08-18 00:43:30 +03:00
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2017-08-22 19:51:02 +03:00
|
|
|
edit_redraw(was_current, FLOWING);
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
|
|
|
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Move right one character. */
|
2005-09-13 08:53:44 +04:00
|
|
|
void do_right(void)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
2017-08-22 19:51:02 +03:00
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
if (openfile->current->data[openfile->current_x] != '\0')
|
|
|
|
openfile->current_x = move_mbright(openfile->current->data,
|
2016-05-27 22:22:56 +03:00
|
|
|
openfile->current_x);
|
2016-10-18 12:46:15 +03:00
|
|
|
else if (openfile->current != openfile->filebot) {
|
2017-08-18 00:43:30 +03:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_x = 0;
|
2017-01-20 19:34:45 +03:00
|
|
|
}
|
|
|
|
|
2017-08-22 19:51:02 +03:00
|
|
|
edit_redraw(was_current, FLOWING);
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|