2000-06-19 04:22:15 +00:00
|
|
|
/**************************************************************************
|
2016-08-29 15:10:49 +00:00
|
|
|
* move.c -- This file is part of GNU nano. *
|
2000-06-19 04:22:15 +00:00
|
|
|
* *
|
2009-12-02 03:36:22 +00:00
|
|
|
* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
|
2014-04-30 20:18:26 +00:00
|
|
|
* 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. *
|
2016-08-29 13:14:18 +00:00
|
|
|
* Copyright (C) 2014, 2015, 2016 Benno Schulenberg *
|
|
|
|
* *
|
2016-08-29 15:10:49 +00: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 04:22:15 +00:00
|
|
|
* *
|
2016-08-29 15:10:49 +00: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 04:22:15 +00:00
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
2016-08-29 15:10:49 +00:00
|
|
|
* along with this program. If not, see http://www.gnu.org/licenses/. *
|
2000-06-19 04:22:15 +00:00
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2005-12-08 02:47:10 +00:00
|
|
|
#include "proto.h"
|
2001-04-28 18:03:52 +00:00
|
|
|
|
2000-06-19 04:22:15 +00:00
|
|
|
#include <string.h>
|
2004-05-22 20:15:20 +00:00
|
|
|
#include <ctype.h>
|
2000-06-19 04:22:15 +00:00
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the first line of the file. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_first_line(void)
|
2004-05-23 21:33:23 +00:00
|
|
|
{
|
2016-10-12 19:07:16 +00:00
|
|
|
openfile->current = openfile->fileage;
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = 0;
|
2005-07-14 18:01:08 +00:00
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
2016-04-25 19:14:18 +00:00
|
|
|
refresh_needed = TRUE;
|
2004-05-23 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the last line of the file. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_last_line(void)
|
2004-05-23 21:33:23 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->filebot;
|
2005-11-05 17:50:06 +00:00
|
|
|
openfile->current_x = strlen(openfile->filebot->data);
|
|
|
|
openfile->placewewant = xplustabs();
|
2016-10-12 19:07:16 +00:00
|
|
|
|
|
|
|
/* Set the last line of the screen as the target for the cursor. */
|
2005-08-16 01:27:05 +00:00
|
|
|
openfile->current_y = editwinrows - 1;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2016-04-25 19:14:18 +00:00
|
|
|
refresh_needed = TRUE;
|
2016-04-12 08:24:57 +00:00
|
|
|
focusing = FALSE;
|
2004-05-23 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move up one page. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_page_up(void)
|
2000-07-03 04:24:39 +00:00
|
|
|
{
|
2017-03-27 09:38:52 +00:00
|
|
|
int mustmove = (editwinrows < 3) ? 1 : editwinrows - 2;
|
|
|
|
size_t leftedge = 0, target_column;
|
2005-07-16 22:50:30 +00:00
|
|
|
|
2005-07-17 00:01:18 +00: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 12:31:04 +00:00
|
|
|
if (!ISSET(SMOOTH_SCROLL)) {
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->current = openfile->edittop;
|
2017-03-27 09:38:52 +00:00
|
|
|
openfile->placewewant = openfile->firstcolumn;
|
2017-03-26 23:50:55 +00:00
|
|
|
openfile->current_y = 0;
|
2005-07-17 00:01:18 +00:00
|
|
|
}
|
2000-07-03 04:24:39 +00:00
|
|
|
|
2014-06-21 19:01:51 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-01-20 18:03:49 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
|
|
|
leftedge = (openfile->placewewant / editwincols) * editwincols;
|
|
|
|
target_column = openfile->placewewant % editwincols;
|
2017-03-27 09:38:52 +00:00
|
|
|
} else
|
2014-06-21 19:01:51 +00:00
|
|
|
#endif
|
2017-03-27 09:38:52 +00:00
|
|
|
target_column = openfile->placewewant;
|
2017-01-20 18:03:49 +00: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 17:15:53 +00:00
|
|
|
}
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2017-01-20 18:03:49 +00:00
|
|
|
openfile->placewewant = leftedge + target_column;
|
2017-03-27 09:38:52 +00:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2005-07-17 00:01:18 +00:00
|
|
|
/* Scroll the edit window up a page. */
|
2016-10-20 19:11:11 +00:00
|
|
|
adjust_viewport(STATIONARY);
|
2016-04-25 19:14:18 +00:00
|
|
|
refresh_needed = TRUE;
|
2000-07-03 04:24:39 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move down one page. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_page_down(void)
|
2002-09-06 20:35:28 +00:00
|
|
|
{
|
2017-03-27 09:38:52 +00:00
|
|
|
int mustmove = (editwinrows < 3) ? 1 : editwinrows - 2;
|
|
|
|
size_t leftedge = 0, target_column;
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2005-07-17 00:01:18 +00: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 12:31:04 +00:00
|
|
|
if (!ISSET(SMOOTH_SCROLL)) {
|
2005-07-17 00:01:18 +00:00
|
|
|
openfile->current = openfile->edittop;
|
2017-03-27 09:38:52 +00:00
|
|
|
openfile->placewewant = openfile->firstcolumn;
|
2017-03-26 23:50:55 +00:00
|
|
|
openfile->current_y = 0;
|
2005-07-17 00:01:18 +00:00
|
|
|
}
|
2002-09-06 20:35:28 +00:00
|
|
|
|
2017-01-20 18:03:49 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (ISSET(SOFTWRAP)) {
|
|
|
|
leftedge = (openfile->placewewant / editwincols) * editwincols;
|
|
|
|
target_column = openfile->placewewant % editwincols;
|
2017-03-27 09:38:52 +00:00
|
|
|
} else
|
2017-01-20 18:03:49 +00:00
|
|
|
#endif
|
2017-03-27 09:38:52 +00:00
|
|
|
target_column = openfile->placewewant;
|
2016-08-21 13:49:39 +00:00
|
|
|
|
2017-01-20 18:03:49 +00: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-14 22:15:09 +00:00
|
|
|
|
2017-01-20 18:03:49 +00:00
|
|
|
openfile->placewewant = leftedge + target_column;
|
2017-03-27 09:38:52 +00:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2005-07-14 22:15:09 +00:00
|
|
|
|
2005-07-17 00:01:18 +00:00
|
|
|
/* Scroll the edit window down a page. */
|
2016-10-20 19:11:11 +00:00
|
|
|
adjust_viewport(STATIONARY);
|
2016-04-25 19:14:18 +00:00
|
|
|
refresh_needed = TRUE;
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
2005-07-20 19:24:11 +00:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
2005-11-10 05:26:37 +00:00
|
|
|
/* Move up to the beginning of the last beginning-of-paragraph line
|
2005-12-08 07:09:08 +00:00
|
|
|
* before the current line. If allow_update is TRUE, update the screen
|
|
|
|
* afterwards. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_para_begin(bool allow_update)
|
|
|
|
{
|
2016-10-12 19:10:04 +00:00
|
|
|
filestruct *was_current = openfile->current;
|
2005-07-20 19:24:11 +00:00
|
|
|
|
2005-11-03 21:08:39 +00:00
|
|
|
if (openfile->current != openfile->fileage) {
|
weeding: remove unnecessary settings of openfile->current_y
Many of the adjustments of the value of openfile->current_y appear to be
a holdover from the days when certain functions had to account for what
is now called STATIONARY scrolling mode, which depends on the value of
current_y. Remove these adjustement where they are superfluous.
do_para_begin(), do_para_end(), and do_bracket_match() update the screen
through edit_redraw(), which uses either CENTERING or FLOWING scrolling
mode, so their setting of current_y is redundant and useless, as it will
be ignored and then overridden by the next call to reset_cursor().
findnextstr() is called by go_looking() [which calls edit_redraw(), see
above], and by do_replace_loop() and do_int_spell_fix(), which both call
edit_refresh(), which in this case only uses CENTERING scrolling mode
since focusing is TRUE.
(Additionally, the adjustments of current_y in findnextstr() and
do_bracket_match() use incorrect values when in softwrap mode.)
find_paragraph() doesn't need to save or restore current_y, because it
doesn't do any screen updates. do_justify() calls edit_refresh() with
focusing set to TRUE, so it uses the CENTERING scrolling mode.
do_alt_speller() and do_formatter() do not need to save and restore
current_y, because they don't modify it in any way.
This addresses https://savannah.gnu.org/patch/?9197.
2016-12-22 19:01:27 +00:00
|
|
|
do
|
2005-07-20 19:24:11 +00:00
|
|
|
openfile->current = openfile->current->prev;
|
weeding: remove unnecessary settings of openfile->current_y
Many of the adjustments of the value of openfile->current_y appear to be
a holdover from the days when certain functions had to account for what
is now called STATIONARY scrolling mode, which depends on the value of
current_y. Remove these adjustement where they are superfluous.
do_para_begin(), do_para_end(), and do_bracket_match() update the screen
through edit_redraw(), which uses either CENTERING or FLOWING scrolling
mode, so their setting of current_y is redundant and useless, as it will
be ignored and then overridden by the next call to reset_cursor().
findnextstr() is called by go_looking() [which calls edit_redraw(), see
above], and by do_replace_loop() and do_int_spell_fix(), which both call
edit_refresh(), which in this case only uses CENTERING scrolling mode
since focusing is TRUE.
(Additionally, the adjustments of current_y in findnextstr() and
do_bracket_match() use incorrect values when in softwrap mode.)
find_paragraph() doesn't need to save or restore current_y, because it
doesn't do any screen updates. do_justify() calls edit_refresh() with
focusing set to TRUE, so it uses the CENTERING scrolling mode.
do_alt_speller() and do_formatter() do not need to save and restore
current_y, because they don't modify it in any way.
This addresses https://savannah.gnu.org/patch/?9197.
2016-12-22 19:01:27 +00:00
|
|
|
while (!begpar(openfile->current));
|
2005-07-20 19:24:11 +00:00
|
|
|
}
|
|
|
|
|
2005-11-09 04:20:55 +00:00
|
|
|
openfile->current_x = 0;
|
|
|
|
|
2005-07-20 19:24:11 +00:00
|
|
|
if (allow_update)
|
2016-10-12 19:10:04 +00:00
|
|
|
edit_redraw(was_current);
|
2005-07-20 19:24:11 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move up to the beginning of the last beginning-of-paragraph line
|
|
|
|
* before the current line, and update the screen afterwards. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_para_begin_void(void)
|
|
|
|
{
|
|
|
|
do_para_begin(TRUE);
|
|
|
|
}
|
|
|
|
|
2005-11-10 05:26:37 +00: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
|
2005-12-08 07:09:08 +00:00
|
|
|
* end of the current line if not. If allow_update is TRUE, update the
|
|
|
|
* 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. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_para_end(bool allow_update)
|
|
|
|
{
|
2016-10-12 19:10:04 +00:00
|
|
|
filestruct *was_current = openfile->current;
|
2005-07-20 19:24:11 +00:00
|
|
|
|
2005-11-03 21:08:39 +00:00
|
|
|
while (openfile->current != openfile->filebot &&
|
2016-05-27 19:22:56 +00:00
|
|
|
!inpar(openfile->current))
|
2005-07-20 19:24:11 +00:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
|
2005-11-03 21:08:39 +00:00
|
|
|
while (openfile->current != openfile->filebot &&
|
2016-05-27 19:22:56 +00:00
|
|
|
inpar(openfile->current->next) &&
|
|
|
|
!begpar(openfile->current->next)) {
|
2005-07-20 19:24:11 +00:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
}
|
|
|
|
|
2005-11-09 04:20:55 +00:00
|
|
|
if (openfile->current != openfile->filebot) {
|
2005-07-20 19:24:11 +00:00
|
|
|
openfile->current = openfile->current->next;
|
2005-11-09 04:20:55 +00:00
|
|
|
openfile->current_x = 0;
|
2016-04-10 19:16:19 +00:00
|
|
|
} else
|
2005-11-09 04:20:55 +00:00
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
2005-07-20 19:24:11 +00:00
|
|
|
|
|
|
|
if (allow_update)
|
2016-10-12 19:10:04 +00:00
|
|
|
edit_redraw(was_current);
|
2005-07-20 19:24:11 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00: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
|
|
|
|
* end of the current line if not, and update the screen afterwards. */
|
2005-07-20 19:24:11 +00:00
|
|
|
void do_para_end_void(void)
|
|
|
|
{
|
|
|
|
do_para_end(TRUE);
|
|
|
|
}
|
|
|
|
#endif /* !DISABLE_JUSTIFY */
|
|
|
|
|
2016-06-25 13:16:52 +00:00
|
|
|
/* Move to the preceding block of text in the file. */
|
|
|
|
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;
|
|
|
|
edit_redraw(was_current);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the next block of text in the file. */
|
|
|
|
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;
|
|
|
|
edit_redraw(was_current);
|
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move to the previous word in the file. If allow_punct is TRUE, treat
|
|
|
|
* punctuation as part of a word. If allow_update is TRUE, update the
|
2015-09-05 09:22:50 +00:00
|
|
|
* screen afterwards. */
|
|
|
|
void do_prev_word(bool allow_punct, bool allow_update)
|
2005-07-20 21:31:19 +00:00
|
|
|
{
|
2016-10-12 19:10:04 +00:00
|
|
|
filestruct *was_current = openfile->current;
|
2015-09-05 09:40:09 +00:00
|
|
|
bool seen_a_word = FALSE, step_forward = FALSE;
|
2005-07-20 21:31:19 +00:00
|
|
|
|
2015-09-05 09:40:09 +00: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-20 21:31:19 +00:00
|
|
|
break;
|
2015-09-05 09:40:09 +00:00
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
2005-07-20 21:31:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-05 09:40:09 +00:00
|
|
|
/* Step back one character. */
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
2005-07-20 21:31:19 +00:00
|
|
|
|
2015-09-05 09:40:09 +00: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-20 21:31:19 +00:00
|
|
|
if (openfile->current_x == 0)
|
2015-09-05 09:40:09 +00: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-20 21:31:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-05 09:40:09 +00: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-20 21:31:19 +00:00
|
|
|
|
|
|
|
/* If allow_update is TRUE, update the screen. */
|
2016-04-12 08:24:57 +00:00
|
|
|
if (allow_update) {
|
|
|
|
focusing = FALSE;
|
2016-10-12 19:10:04 +00:00
|
|
|
edit_redraw(was_current);
|
2016-04-12 08:24:57 +00:00
|
|
|
}
|
2005-07-20 21:31:19 +00:00
|
|
|
}
|
|
|
|
|
2016-02-22 12:49:08 +00: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. */
|
2005-07-20 21:31:19 +00:00
|
|
|
void do_prev_word_void(void)
|
|
|
|
{
|
2005-08-10 22:12:28 +00:00
|
|
|
do_prev_word(ISSET(WORD_BOUNDS), TRUE);
|
2005-07-20 21:31:19 +00:00
|
|
|
}
|
2016-02-22 12:49:08 +00:00
|
|
|
|
|
|
|
/* Move to the next word in the file. If allow_punct is TRUE, treat
|
|
|
|
* punctuation as part of a word. If allow_update is TRUE, update the
|
|
|
|
* screen afterwards. Return TRUE if we started on a word, and FALSE
|
|
|
|
* otherwise. */
|
|
|
|
bool do_next_word(bool allow_punct, bool allow_update)
|
|
|
|
{
|
2016-10-12 19:10:04 +00:00
|
|
|
filestruct *was_current = openfile->current;
|
2016-02-22 12:49:08 +00: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') {
|
|
|
|
/* If at the end of the file, stop. */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If allow_update is TRUE, update the screen. */
|
2016-04-12 08:24:57 +00:00
|
|
|
if (allow_update) {
|
|
|
|
focusing = FALSE;
|
2016-10-12 19:10:04 +00:00
|
|
|
edit_redraw(was_current);
|
2016-04-12 08:24:57 +00:00
|
|
|
}
|
2016-02-22 12:49:08 +00:00
|
|
|
|
|
|
|
/* Return whether we started on a word. */
|
|
|
|
return started_on_word;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-20 21:31:19 +00:00
|
|
|
|
2017-01-20 06:04:44 +00:00
|
|
|
/* Move to the beginning of the current line (or softwrapped chunk).
|
2017-01-22 20:42:58 +00:00
|
|
|
* If be_clever is TRUE, do a smart home when wanted and possible,
|
|
|
|
* and do a dynamic home when in softwrap mode and it'spossible.
|
|
|
|
* If be_clever is FALSE, just do a simple home. */
|
|
|
|
void do_home(bool be_clever)
|
2005-07-20 19:24:11 +00:00
|
|
|
{
|
2016-07-26 09:47:53 +00:00
|
|
|
size_t was_column = xplustabs();
|
2017-01-20 06:04:44 +00:00
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
bool moved_off_chunk = TRUE;
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-01-20 06:04:44 +00:00
|
|
|
bool moved = FALSE;
|
|
|
|
size_t leftedge_x = 0;
|
2005-07-20 19:24:11 +00:00
|
|
|
|
2017-01-20 06:04:44 +00:00
|
|
|
if (ISSET(SOFTWRAP))
|
|
|
|
leftedge_x = actual_x(openfile->current->data,
|
|
|
|
(was_column / editwincols) * editwincols);
|
|
|
|
|
2017-01-22 20:42:58 +00:00
|
|
|
if (ISSET(SMART_HOME) && be_clever) {
|
2017-01-20 06:04:44 +00: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 19:24:11 +00:00
|
|
|
|
2017-01-20 06:04:44 +00:00
|
|
|
if (!moved && ISSET(SOFTWRAP)) {
|
|
|
|
/* If already at the left edge of the screen, move fully home.
|
|
|
|
* Otherwise, move to the left edge. */
|
2017-01-22 20:42:58 +00:00
|
|
|
if (openfile->current_x == leftedge_x && be_clever)
|
2005-07-20 19:24:11 +00:00
|
|
|
openfile->current_x = 0;
|
2017-01-20 06:04:44 +00:00
|
|
|
else {
|
|
|
|
openfile->current_x = leftedge_x;
|
|
|
|
moved_off_chunk = FALSE;
|
|
|
|
}
|
|
|
|
} else if (!moved)
|
2005-07-20 19:24:11 +00:00
|
|
|
#endif
|
|
|
|
openfile->current_x = 0;
|
2016-05-27 19:22:56 +00:00
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-20 19:24:11 +00:00
|
|
|
|
2017-01-20 06:04:44 +00:00
|
|
|
/* If we changed chunk, we might be offscreen. Otherwise, update
|
|
|
|
* current if the mark is on or we changed "page". */
|
|
|
|
if (ISSET(SOFTWRAP) && moved_off_chunk) {
|
|
|
|
focusing = FALSE;
|
|
|
|
edit_redraw(was_current);
|
|
|
|
} else if (line_needs_update(was_column, openfile->placewewant))
|
2005-07-20 19:24:11 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2017-01-22 20:42:58 +00:00
|
|
|
/* Do a (smart or dynamic) home. */
|
2017-01-22 20:09:15 +00:00
|
|
|
void do_home_void(void)
|
|
|
|
{
|
2017-01-22 20:42:58 +00:00
|
|
|
do_home(TRUE);
|
2017-01-22 20:09:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 08:07:15 +00:00
|
|
|
/* Move to the end of the current line (or softwrapped chunk).
|
2017-01-22 20:42:58 +00:00
|
|
|
* If be_clever is TRUE, do a dynamic end when in softwrap mode and
|
|
|
|
* it's possible. If be_clever is FALSE, just do a simple end. */
|
|
|
|
void do_end(bool be_clever)
|
2005-07-20 19:24:11 +00:00
|
|
|
{
|
2016-07-26 09:47:53 +00:00
|
|
|
size_t was_column = xplustabs();
|
2017-01-20 08:07:15 +00:00
|
|
|
size_t line_len = strlen(openfile->current->data);
|
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
bool moved_off_chunk = TRUE;
|
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (ISSET(SOFTWRAP)) {
|
|
|
|
size_t rightedge_x = actual_x(openfile->current->data,
|
|
|
|
((was_column / editwincols) * editwincols) +
|
|
|
|
(editwincols - 1));
|
|
|
|
|
|
|
|
/* If already at the right edge of the screen, move fully to the
|
|
|
|
* end of the line. Otherwise, move to the right edge. */
|
2017-01-22 20:42:58 +00:00
|
|
|
if (openfile->current_x == rightedge_x && be_clever)
|
2017-01-20 08:07:15 +00:00
|
|
|
openfile->current_x = line_len;
|
|
|
|
else {
|
|
|
|
openfile->current_x = rightedge_x;
|
|
|
|
moved_off_chunk = FALSE;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
openfile->current_x = line_len;
|
2005-07-20 19:24:11 +00:00
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
2017-01-20 08:07:15 +00:00
|
|
|
/* If we changed chunk, we might be offscreen. Otherwise,
|
|
|
|
* update current if the mark is on or we changed "page". */
|
|
|
|
if (ISSET(SOFTWRAP) && moved_off_chunk) {
|
|
|
|
focusing = FALSE;
|
|
|
|
edit_redraw(was_current);
|
|
|
|
} else if (line_needs_update(was_column, openfile->placewewant))
|
2005-07-20 19:24:11 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2017-01-22 20:42:58 +00:00
|
|
|
/* Do a (dynamic) end. */
|
2017-01-22 20:09:15 +00:00
|
|
|
void do_end_void(void)
|
|
|
|
{
|
2017-01-22 20:42:58 +00:00
|
|
|
do_end(TRUE);
|
2017-01-22 20:09:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 17:11:17 +00: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 15:23:45 +00:00
|
|
|
void do_up(bool scroll_only)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2016-07-26 09:47:53 +00:00
|
|
|
size_t was_column = xplustabs();
|
2017-01-20 17:11:17 +00:00
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
size_t leftedge = 0;
|
|
|
|
size_t target_column = openfile->placewewant;
|
|
|
|
|
|
|
|
/* When just scrolling and the top of the file is onscreen, get out. */
|
2017-02-01 01:23:21 +00:00
|
|
|
if (scroll_only && openfile->edittop == openfile->fileage &&
|
|
|
|
openfile->firstcolumn == 0)
|
2017-01-20 17:11:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (ISSET(SOFTWRAP)) {
|
2017-03-27 15:34:13 +00:00
|
|
|
size_t realspan = strlenpt(openfile->current->data);
|
|
|
|
|
|
|
|
if (openfile->placewewant < realspan)
|
|
|
|
realspan = openfile->placewewant;
|
|
|
|
|
|
|
|
leftedge = (realspan / editwincols) * editwincols;
|
2017-01-20 17:11:17 +00:00
|
|
|
target_column = openfile->placewewant % editwincols;
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-26 09:47:53 +00:00
|
|
|
|
2017-01-20 17:11:17 +00:00
|
|
|
/* Move up one line or chunk. */
|
|
|
|
if (go_back_chunks(1, &openfile->current, &leftedge) > 0)
|
2004-07-02 14:31:03 +00:00
|
|
|
return;
|
2003-09-07 23:57:24 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
2017-01-20 17:11:17 +00:00
|
|
|
leftedge + target_column);
|
|
|
|
openfile->placewewant = leftedge + target_column;
|
2004-05-28 20:44:09 +00:00
|
|
|
|
2016-10-28 09:37:03 +00:00
|
|
|
/* When the cursor was on the first line of the edit window (or when just
|
|
|
|
* scrolling without moving the cursor), scroll the edit window up -- one
|
|
|
|
* line if we're in smooth scrolling mode, and half a page otherwise. */
|
2017-02-01 01:23:21 +00:00
|
|
|
if (openfile->current_y == 0 || scroll_only)
|
2016-10-24 11:56:00 +00:00
|
|
|
edit_scroll(UPWARD, (ISSET(SMOOTH_SCROLL) || scroll_only) ?
|
|
|
|
1 : editwinrows / 2 + 1);
|
2006-07-06 22:17:47 +00:00
|
|
|
|
2017-03-28 08:23:27 +00:00
|
|
|
if (openfile->current_y > 0) {
|
2017-03-28 08:38:08 +00:00
|
|
|
/* Redraw the prior line if it's not offscreen, and it's not the same
|
|
|
|
* line as the current one, and the line was horizontally scrolled. */
|
|
|
|
if ((!scroll_only || openfile->current_y < editwinrows - 1) &&
|
|
|
|
openfile->current != was_current &&
|
|
|
|
line_needs_update(was_column, 0))
|
2016-07-26 18:06:10 +00:00
|
|
|
update_line(openfile->current->next, 0);
|
|
|
|
/* Redraw the current line if it needs to be horizontally scrolled. */
|
2017-01-31 22:51:06 +00:00
|
|
|
if (line_needs_update(0, xplustabs()))
|
2016-07-26 18:06:10 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2002-07-19 01:08:59 +00:00
|
|
|
}
|
2000-06-19 04:22:15 +00:00
|
|
|
|
2017-01-20 17:11:17 +00:00
|
|
|
/* Move up one line or chunk. */
|
2006-07-06 22:17:47 +00:00
|
|
|
void do_up_void(void)
|
|
|
|
{
|
2016-07-25 15:23:45 +00:00
|
|
|
do_up(FALSE);
|
2005-10-24 02:12:09 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 17:11:17 +00: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 15:23:45 +00:00
|
|
|
void do_down(bool scroll_only)
|
2002-12-22 16:30:00 +00:00
|
|
|
{
|
2016-07-26 09:47:53 +00:00
|
|
|
size_t was_column = xplustabs();
|
2017-01-20 17:11:17 +00:00
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
size_t leftedge = 0;
|
|
|
|
size_t target_column = openfile->placewewant;
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2014-03-03 13:24:09 +00:00
|
|
|
#ifndef NANO_TINY
|
2009-08-30 03:50:16 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2017-03-27 15:34:13 +00:00
|
|
|
size_t realspan = strlenpt(openfile->current->data);
|
|
|
|
|
|
|
|
if (openfile->placewewant < realspan)
|
|
|
|
realspan = openfile->placewewant;
|
|
|
|
|
|
|
|
leftedge = (realspan / editwincols) * editwincols;
|
2017-01-20 17:11:17 +00:00
|
|
|
target_column = openfile->placewewant % editwincols;
|
2009-08-30 03:50:16 +00:00
|
|
|
}
|
2014-03-03 13:24:09 +00:00
|
|
|
#endif
|
2009-08-30 03:50:16 +00:00
|
|
|
|
2017-01-20 17:11:17 +00:00
|
|
|
/* Move down one line or chunk. */
|
|
|
|
if (go_forward_chunks(1, &openfile->current, &leftedge) > 0)
|
|
|
|
return;
|
|
|
|
|
2016-04-15 12:39:54 +00:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
2017-01-20 17:11:17 +00:00
|
|
|
leftedge + target_column);
|
|
|
|
openfile->placewewant = leftedge + target_column;
|
2016-04-15 12:39:54 +00:00
|
|
|
|
2016-12-28 15:43:23 +00:00
|
|
|
/* When the cursor was on the last line of the edit window (or when just
|
|
|
|
* scrolling without moving the cursor), scroll the edit window down -- one
|
|
|
|
* line if we're in smooth scrolling mode, and half a page otherwise. */
|
2017-01-20 17:11:17 +00:00
|
|
|
if (openfile->current_y == editwinrows - 1 || scroll_only)
|
2016-09-13 20:06:11 +00:00
|
|
|
edit_scroll(DOWNWARD, (ISSET(SMOOTH_SCROLL) || scroll_only) ?
|
2017-01-20 17:11:17 +00:00
|
|
|
1 : editwinrows / 2 + 1);
|
2016-04-12 11:29:51 +00:00
|
|
|
|
2017-03-28 08:23:27 +00:00
|
|
|
if (openfile->current_y < editwinrows - 1) {
|
2017-03-28 08:38:08 +00:00
|
|
|
/* Redraw the prior line if it's not offscreen, and it's not the same
|
|
|
|
* line as the current one, and the line was horizontally scrolled. */
|
|
|
|
if ((!scroll_only || openfile->current_y > 0) &&
|
|
|
|
openfile->current != was_current &&
|
|
|
|
line_needs_update(was_column, 0))
|
2016-07-26 18:06:10 +00:00
|
|
|
update_line(openfile->current->prev, 0);
|
|
|
|
/* Redraw the current line if it needs to be horizontally scrolled. */
|
2017-01-31 22:51:06 +00:00
|
|
|
if (line_needs_update(0, xplustabs()))
|
2016-07-26 18:06:10 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
2005-10-24 02:12:09 +00:00
|
|
|
|
2017-01-20 17:11:17 +00:00
|
|
|
/* Move down one line or chunk. */
|
2006-07-06 22:17:47 +00:00
|
|
|
void do_down_void(void)
|
|
|
|
{
|
2016-07-25 15:23:45 +00:00
|
|
|
do_down(FALSE);
|
2006-07-06 22:17:47 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-01-20 17:11:17 +00:00
|
|
|
/* Scroll up one line or chunk without scrolling the cursor. */
|
2016-07-25 15:23:45 +00:00
|
|
|
void do_scroll_up(void)
|
|
|
|
{
|
|
|
|
do_up(TRUE);
|
|
|
|
}
|
|
|
|
|
2017-01-20 17:11:17 +00:00
|
|
|
/* Scroll down one line or chunk without scrolling the cursor. */
|
2005-10-24 02:12:09 +00:00
|
|
|
void do_scroll_down(void)
|
|
|
|
{
|
2006-07-06 22:17:47 +00:00
|
|
|
do_down(TRUE);
|
2005-10-24 02:12:09 +00:00
|
|
|
}
|
2006-07-06 22:17:47 +00:00
|
|
|
#endif
|
2000-06-19 04:22:15 +00:00
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move left one character. */
|
2005-09-13 04:53:44 +00:00
|
|
|
void do_left(void)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2016-07-26 09:47:53 +00:00
|
|
|
size_t was_column = xplustabs();
|
2017-01-20 16:34:45 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
size_t was_chunk = (was_column / editwincols);
|
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
#endif
|
2005-07-08 20:09:16 +00:00
|
|
|
|
|
|
|
if (openfile->current_x > 0)
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
2016-05-27 19:22:56 +00:00
|
|
|
openfile->current_x);
|
2005-07-08 20:09:16 +00:00
|
|
|
else if (openfile->current != openfile->fileage) {
|
2006-07-06 22:17:47 +00:00
|
|
|
do_up_void();
|
2017-01-20 16:34:45 +00:00
|
|
|
do_end(FALSE);
|
|
|
|
return;
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2017-01-20 16:34:45 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* If we were on the first line of the edit window, and we changed chunk,
|
|
|
|
* we're now above the first line of the edit window, so scroll up. */
|
|
|
|
if (ISSET(SOFTWRAP) && openfile->current_y == 0 &&
|
|
|
|
openfile->current == was_current &&
|
|
|
|
(openfile->placewewant / editwincols) != was_chunk) {
|
|
|
|
edit_scroll(UPWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Update current if the mark is on or it has changed "page". */
|
2017-01-31 22:51:06 +00:00
|
|
|
if (line_needs_update(was_column, openfile->placewewant))
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Move right one character. */
|
2005-09-13 04:53:44 +00:00
|
|
|
void do_right(void)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2016-07-26 09:47:53 +00:00
|
|
|
size_t was_column = xplustabs();
|
2017-01-20 16:34:45 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
size_t was_chunk = (was_column / editwincols);
|
|
|
|
filestruct *was_current = openfile->current;
|
|
|
|
#endif
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->current->data[openfile->current_x] != '\0')
|
|
|
|
openfile->current_x = move_mbright(openfile->current->data,
|
2016-05-27 19:22:56 +00:00
|
|
|
openfile->current_x);
|
2016-10-18 09:46:15 +00:00
|
|
|
else if (openfile->current != openfile->filebot) {
|
2017-01-20 16:34:45 +00:00
|
|
|
do_home(FALSE);
|
|
|
|
do_down_void();
|
|
|
|
return;
|
2016-10-18 09:46:15 +00:00
|
|
|
}
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2017-01-20 16:34:45 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* If we were on the last line of the edit window, and we changed chunk,
|
|
|
|
* we're now below the first line of the edit window, so scroll down. */
|
|
|
|
if (ISSET(SOFTWRAP) && openfile->current_y == editwinrows - 1 &&
|
|
|
|
openfile->current == was_current &&
|
|
|
|
openfile->placewewant / editwincols != was_chunk) {
|
|
|
|
edit_scroll(DOWNWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Update current if the mark is on or it has changed "page". */
|
2017-01-31 22:51:06 +00:00
|
|
|
if (line_needs_update(was_column, openfile->placewewant))
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|