2000-06-19 08:22:15 +04:00
|
|
|
/**************************************************************************
|
|
|
|
* move.c *
|
|
|
|
* *
|
2009-12-02 06:36:22 +03:00
|
|
|
* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
|
2014-05-01 00:18:26 +04:00
|
|
|
* 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. *
|
2000-06-19 08:22:15 +04:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
2007-08-11 09:17:36 +04:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option) *
|
2000-06-19 08:22:15 +04:00
|
|
|
* any later version. *
|
|
|
|
* *
|
2005-05-15 23:57:17 +04:00
|
|
|
* This program 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 *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
2005-05-15 23:57:17 +04:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
|
|
|
|
* 02110-1301, USA. *
|
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>
|
2004-05-23 00:15:20 +04:00
|
|
|
#include <ctype.h>
|
2000-06-19 08:22:15 +04:00
|
|
|
|
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
|
|
|
{
|
2009-11-16 07:28:40 +03:00
|
|
|
openfile->current = openfile->edittop = 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();
|
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
|
|
|
}
|
|
|
|
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Move up one page. */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_page_up(void)
|
2000-07-03 08:24:39 +04:00
|
|
|
{
|
2009-11-24 20:15:53 +03:00
|
|
|
int i, skipped = 0;
|
2005-07-17 04:01:18 +04:00
|
|
|
|
2015-07-26 20:04:29 +03:00
|
|
|
/* If the cursor is less than a page away from the top of the file,
|
|
|
|
* put it at the beginning of the first line. */
|
2014-06-10 00:26:54 +04:00
|
|
|
if (openfile->current->lineno == 1 || (
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
!ISSET(SOFTWRAP) &&
|
|
|
|
#endif
|
2010-01-13 06:21:19 +03:00
|
|
|
openfile->current->lineno <= editwinrows - 2)) {
|
2005-07-17 02:50:30 +04:00
|
|
|
do_first_line();
|
2005-07-17 04:01:18 +04:00
|
|
|
return;
|
|
|
|
}
|
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. */
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2005-07-17 04:01:18 +04:00
|
|
|
if (!ISSET(SMOOTH_SCROLL)) {
|
2003-09-08 03:57:24 +04:00
|
|
|
#endif
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current = openfile->edittop;
|
2010-03-21 07:56:37 +03:00
|
|
|
openfile->placewewant = openfile->current_y = 0;
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2005-07-17 04:01:18 +04:00
|
|
|
}
|
2003-09-08 03:57:24 +04:00
|
|
|
#endif
|
2000-07-03 08:24:39 +04:00
|
|
|
|
2009-11-24 20:15:53 +03:00
|
|
|
for (i = editwinrows - 2; i - skipped > 0 && openfile->current !=
|
|
|
|
openfile->fileage; i--) {
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current = openfile->current->prev;
|
2014-06-21 23:01:51 +04:00
|
|
|
#ifndef NANO_TINY
|
2009-11-26 21:23:00 +03:00
|
|
|
if (ISSET(SOFTWRAP) && openfile->current) {
|
2009-11-24 20:15:53 +03:00
|
|
|
skipped += strlenpt(openfile->current->data) / COLS;
|
2009-11-26 21:23:00 +03:00
|
|
|
#ifdef DEBUG
|
2014-06-21 23:01:51 +04:00
|
|
|
fprintf(stderr, "do_page_up: i = %d, skipped = %d based on line %ld len %lu\n",
|
|
|
|
i, skipped, (long)openfile->current->lineno, (unsigned long)strlenpt(openfile->current->data));
|
2009-11-26 21:23:00 +03:00
|
|
|
#endif
|
|
|
|
}
|
2014-06-21 23:01:51 +04:00
|
|
|
#endif
|
2009-11-24 20:15:53 +03:00
|
|
|
}
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
2016-05-27 22:22:56 +03:00
|
|
|
openfile->placewewant);
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2009-11-24 20:15:53 +03:00
|
|
|
#ifdef DEBUG
|
2014-03-24 17:35:50 +04:00
|
|
|
fprintf(stderr, "do_page_up: openfile->current->lineno = %lu, skipped = %d\n",
|
2014-06-21 23:01:51 +04:00
|
|
|
(unsigned long)openfile->current->lineno, skipped);
|
2009-11-24 20:15:53 +03:00
|
|
|
#endif
|
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
/* Scroll the edit window up a page. */
|
2016-04-07 14:58:51 +03:00
|
|
|
edit_update(STATIONARY);
|
2016-04-25 22:14:18 +03:00
|
|
|
refresh_needed = TRUE;
|
2000-07-03 08:24:39 +04:00
|
|
|
}
|
|
|
|
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Move down one page. */
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_page_down(void)
|
2002-09-07 00:35:28 +04:00
|
|
|
{
|
2005-07-17 04:01:18 +04:00
|
|
|
int i;
|
|
|
|
|
2015-07-26 20:04:29 +03:00
|
|
|
/* If the cursor is less than a page away from the bottom of the file,
|
|
|
|
* put it at the end of the last line. */
|
2016-05-27 22:22:56 +03:00
|
|
|
if (openfile->current->lineno + maxrows - 2 >= openfile->filebot->lineno) {
|
2005-07-17 02:50:30 +04:00
|
|
|
do_last_line();
|
2005-07-17 04:01:18 +04:00
|
|
|
return;
|
|
|
|
}
|
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. */
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2005-07-17 04:01:18 +04:00
|
|
|
if (!ISSET(SMOOTH_SCROLL)) {
|
2002-12-22 19:30:00 +03:00
|
|
|
#endif
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current = openfile->edittop;
|
2010-03-21 07:56:37 +03:00
|
|
|
openfile->placewewant = openfile->current_y = 0;
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2005-07-17 04:01:18 +04:00
|
|
|
}
|
2003-09-08 03:57:24 +04:00
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2009-11-16 07:28:40 +03:00
|
|
|
for (i = maxrows - 2; i > 0 && openfile->current !=
|
|
|
|
openfile->filebot; i--) {
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current = openfile->current->next;
|
2009-11-16 07:28:40 +03:00
|
|
|
#ifdef DEBUG
|
2014-06-21 23:01:51 +04:00
|
|
|
fprintf(stderr, "do_page_down: moving to line %lu\n", (unsigned long)openfile->current->lineno);
|
2009-11-16 07:28:40 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
2016-05-27 22:22:56 +03:00
|
|
|
openfile->placewewant);
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
/* Scroll the edit window down a page. */
|
2016-04-07 14:58:51 +03:00
|
|
|
edit_update(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
|
2005-11-10 08:26:37 +03:00
|
|
|
/* Move up to the beginning of the last beginning-of-paragraph line
|
2005-12-08 10:09:08 +03:00
|
|
|
* before the current line. If allow_update is TRUE, update the screen
|
|
|
|
* afterwards. */
|
2005-07-20 23:24:11 +04:00
|
|
|
void do_para_begin(bool allow_update)
|
|
|
|
{
|
2009-01-25 10:25:17 +03:00
|
|
|
filestruct *current_save = openfile->current;
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2005-11-04 00:08:39 +03:00
|
|
|
if (openfile->current != openfile->fileage) {
|
2005-07-20 23:24:11 +04:00
|
|
|
do {
|
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_y--;
|
|
|
|
} while (!begpar(openfile->current));
|
|
|
|
}
|
|
|
|
|
2005-11-09 07:20:55 +03:00
|
|
|
openfile->current_x = 0;
|
|
|
|
|
2005-07-20 23:24:11 +04:00
|
|
|
if (allow_update)
|
2016-04-10 22:16:19 +03:00
|
|
|
edit_redraw(current_save);
|
2005-07-20 23:24:11 +04:00
|
|
|
}
|
|
|
|
|
2005-12-08 10:09:08 +03: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 23:24:11 +04:00
|
|
|
void do_para_begin_void(void)
|
|
|
|
{
|
|
|
|
do_para_begin(TRUE);
|
|
|
|
}
|
|
|
|
|
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
|
2005-12-08 10:09:08 +03: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 23:24:11 +04:00
|
|
|
void do_para_end(bool allow_update)
|
|
|
|
{
|
2009-01-25 10:25:17 +03:00
|
|
|
filestruct *const current_save = 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;
|
|
|
|
openfile->current_y++;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (allow_update)
|
2016-04-10 22:16:19 +03:00
|
|
|
edit_redraw(current_save);
|
2005-07-20 23:24:11 +04:00
|
|
|
}
|
|
|
|
|
2005-12-08 10:09:08 +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
|
|
|
|
* end of the current line if not, and update the screen afterwards. */
|
2005-07-20 23:24:11 +04:00
|
|
|
void do_para_end_void(void)
|
|
|
|
{
|
|
|
|
do_para_end(TRUE);
|
|
|
|
}
|
|
|
|
#endif /* !DISABLE_JUSTIFY */
|
|
|
|
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2005-12-08 10:09:08 +03: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 12:22:50 +03:00
|
|
|
* screen afterwards. */
|
|
|
|
void do_prev_word(bool allow_punct, bool allow_update)
|
2005-07-21 01:31:19 +04:00
|
|
|
{
|
2009-01-25 10:25:17 +03:00
|
|
|
filestruct *current_save = 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
|
|
|
|
|
|
|
assert(openfile->current != NULL && openfile->current->data != NULL);
|
|
|
|
|
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
|
|
|
|
|
|
|
/* If allow_update is TRUE, update the screen. */
|
2016-04-12 11:24:57 +03:00
|
|
|
if (allow_update) {
|
|
|
|
focusing = FALSE;
|
2016-04-10 22:16:19 +03:00
|
|
|
edit_redraw(current_save);
|
2016-04-12 11:24:57 +03:00
|
|
|
}
|
2005-07-21 01:31:19 +04:00
|
|
|
}
|
|
|
|
|
2016-02-22 15:49:08 +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. */
|
2005-07-21 01:31:19 +04:00
|
|
|
void do_prev_word_void(void)
|
|
|
|
{
|
2005-08-11 02:12:28 +04:00
|
|
|
do_prev_word(ISSET(WORD_BOUNDS), TRUE);
|
2005-07-21 01:31:19 +04:00
|
|
|
}
|
2016-02-22 15:49:08 +03: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)
|
|
|
|
{
|
|
|
|
filestruct *current_save = openfile->current;
|
|
|
|
bool started_on_word = is_word_mbchar(openfile->current->data +
|
|
|
|
openfile->current_x, allow_punct);
|
|
|
|
bool seen_space = !started_on_word;
|
|
|
|
|
|
|
|
assert(openfile->current != NULL && openfile->current->data != NULL);
|
|
|
|
|
|
|
|
/* 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 11:24:57 +03:00
|
|
|
if (allow_update) {
|
|
|
|
focusing = FALSE;
|
2016-04-10 22:16:19 +03:00
|
|
|
edit_redraw(current_save);
|
2016-04-12 11:24:57 +03:00
|
|
|
}
|
2016-02-22 15:49:08 +03: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-11-15 06:17:35 +03:00
|
|
|
#endif /* !NANO_TINY */
|
2005-07-21 01:31:19 +04:00
|
|
|
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Move to the beginning of the current line. If the SMART_HOME flag is
|
|
|
|
* set, move to the first non-whitespace character of the current line
|
2006-04-24 23:44:04 +04:00
|
|
|
* if we aren't already there, or to the beginning of the current line
|
2005-12-08 10:09:08 +03:00
|
|
|
* if we are. */
|
2005-07-20 23:24:11 +04:00
|
|
|
void do_home(void)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2005-07-20 23:24:11 +04:00
|
|
|
if (ISSET(SMART_HOME)) {
|
|
|
|
size_t current_x_save = openfile->current_x;
|
|
|
|
|
|
|
|
openfile->current_x = indent_length(openfile->current->data);
|
|
|
|
|
|
|
|
if (openfile->current_x == current_x_save ||
|
|
|
|
openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
openfile->current_x = 0;
|
2016-05-27 22:22:56 +03:00
|
|
|
} else
|
2005-07-20 23:24:11 +04:00
|
|
|
#endif
|
|
|
|
openfile->current_x = 0;
|
2016-05-27 22:22:56 +03:00
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-20 23:24:11 +04:00
|
|
|
|
2015-04-20 11:16:41 +03:00
|
|
|
if (need_screen_update(pww_save))
|
2005-07-20 23:24:11 +04:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Move to the end of the current line. */
|
2005-07-20 23:24:11 +04:00
|
|
|
void do_end(void)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
2015-04-20 11:16:41 +03:00
|
|
|
if (need_screen_update(pww_save))
|
2005-07-20 23:24:11 +04:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2006-07-07 02:17:47 +04:00
|
|
|
/* If scroll_only is FALSE, move up one line. If scroll_only is TRUE,
|
|
|
|
* scroll up one line without scrolling the cursor. */
|
|
|
|
void do_up(
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
bool scroll_only
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
#endif
|
|
|
|
)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
2006-07-07 02:17:47 +04:00
|
|
|
/* If we're at the top of the file, or if scroll_only is TRUE and
|
|
|
|
* the top of the file is onscreen, get out. */
|
|
|
|
if (openfile->current == openfile->fileage
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
|| (scroll_only && openfile->edittop == openfile->fileage)
|
|
|
|
#endif
|
|
|
|
)
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2003-09-08 03:57:24 +04:00
|
|
|
|
2009-09-04 03:29:14 +04:00
|
|
|
assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
|
2005-03-09 23:35:10 +03:00
|
|
|
|
2005-07-17 02:35:11 +04:00
|
|
|
/* Move the current line of the edit window up. */
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
2016-05-27 22:22:56 +03:00
|
|
|
openfile->placewewant);
|
2004-05-29 00:44:09 +04:00
|
|
|
|
2006-07-07 02:17:47 +04:00
|
|
|
/* If scroll_only is FALSE and if we're on the first line of the
|
|
|
|
* edit window, scroll the edit window up one line if we're in
|
|
|
|
* smooth scrolling mode, or up half a page if we're not. If
|
|
|
|
* scroll_only is TRUE, scroll the edit window up one line
|
|
|
|
* unconditionally. */
|
2014-06-10 00:26:54 +04:00
|
|
|
if (openfile->current_y == 0
|
2006-07-07 02:17:47 +04:00
|
|
|
#ifndef NANO_TINY
|
2014-06-10 00:26:54 +04:00
|
|
|
|| (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->current->next->lineno) || scroll_only
|
2006-07-07 02:17:47 +04:00
|
|
|
#endif
|
|
|
|
)
|
2014-06-23 22:20:12 +04:00
|
|
|
edit_scroll(UPWARD,
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2006-07-07 02:17:47 +04:00
|
|
|
(ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 :
|
2003-09-08 03:57:24 +04:00
|
|
|
#endif
|
2010-01-13 06:21:19 +03:00
|
|
|
editwinrows / 2 + 1);
|
2006-07-07 02:17:47 +04:00
|
|
|
|
2016-04-12 14:29:51 +03:00
|
|
|
/* If we're not on the first line of the edit window, and the target
|
|
|
|
* column is beyond the screen or the mark is on, redraw the prior
|
|
|
|
* and current lines. */
|
|
|
|
if (openfile->current_y > 0 && need_screen_update(0)) {
|
|
|
|
update_line(openfile->current->next, 0);
|
2005-07-17 02:50:30 +04:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
|
2006-07-07 02:17:47 +04:00
|
|
|
/* Move up one line. */
|
|
|
|
void do_up_void(void)
|
|
|
|
{
|
|
|
|
do_up(
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
FALSE
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Scroll up one line without scrolling the cursor. */
|
2005-10-24 06:12:09 +04:00
|
|
|
void do_scroll_up(void)
|
|
|
|
{
|
2006-07-07 02:17:47 +04:00
|
|
|
do_up(TRUE);
|
2005-10-24 06:12:09 +04:00
|
|
|
}
|
2006-07-07 02:17:47 +04:00
|
|
|
#endif
|
2005-10-24 06:12:09 +04:00
|
|
|
|
2006-07-07 02:17:47 +04:00
|
|
|
/* If scroll_only is FALSE, move down one line. If scroll_only is TRUE,
|
|
|
|
* scroll down one line without scrolling the cursor. */
|
|
|
|
void do_down(
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
bool scroll_only
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
#endif
|
|
|
|
)
|
2002-12-22 19:30:00 +03:00
|
|
|
{
|
2014-03-03 17:24:09 +04:00
|
|
|
#ifndef NANO_TINY
|
2014-03-05 13:47:35 +04:00
|
|
|
int amount = 0, enough;
|
2014-03-03 14:02:13 +04:00
|
|
|
filestruct *topline;
|
2014-03-03 17:24:09 +04:00
|
|
|
#endif
|
2009-08-30 07:50:16 +04:00
|
|
|
|
2005-07-14 22:01:08 +04:00
|
|
|
/* If we're at the bottom of the file, get out. */
|
2015-12-08 21:54:13 +03:00
|
|
|
if (openfile->current == openfile->filebot)
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2015-12-08 21:54:13 +03:00
|
|
|
assert(ISSET(SOFTWRAP) || openfile->current_y ==
|
|
|
|
openfile->current->lineno - openfile->edittop->lineno);
|
|
|
|
assert(openfile->current->next != NULL);
|
2005-06-28 22:57:28 +04:00
|
|
|
|
2014-03-03 17:24:09 +04:00
|
|
|
#ifndef NANO_TINY
|
2009-08-30 07:50:16 +04:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2016-04-15 15:39:54 +03:00
|
|
|
/* Compute the number of lines to scroll. */
|
|
|
|
amount = strlenpt(openfile->current->data) / COLS - xplustabs() / COLS +
|
|
|
|
strlenpt(openfile->current->next->data) / COLS +
|
|
|
|
openfile->current_y - editwinrows + 2;
|
2014-03-03 14:02:13 +04:00
|
|
|
topline = openfile->edittop;
|
|
|
|
/* Reduce the amount when there are overlong lines at the top. */
|
|
|
|
for (enough = 1; enough < amount; enough++) {
|
2015-10-27 19:57:32 +03:00
|
|
|
amount -= strlenpt(topline->data) / COLS;
|
|
|
|
if (amount <= 0) {
|
2014-03-03 14:02:13 +04:00
|
|
|
amount = enough;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
topline = topline->next;
|
|
|
|
}
|
2009-08-30 07:50:16 +04:00
|
|
|
}
|
2014-03-03 17:24:09 +04:00
|
|
|
#endif
|
2009-08-30 07:50:16 +04:00
|
|
|
|
2016-04-15 15:39:54 +03:00
|
|
|
/* Move to the next line in the file. */
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
|
|
|
|
2014-03-03 14:02:13 +04:00
|
|
|
/* If scroll_only is FALSE and if we're on the last line of the
|
2006-07-07 02:17:47 +04:00
|
|
|
* edit window, scroll the edit window down one line if we're in
|
|
|
|
* smooth scrolling mode, or down half a page if we're not. If
|
|
|
|
* scroll_only is TRUE, scroll the edit window down one line
|
|
|
|
* unconditionally. */
|
2014-03-03 17:24:09 +04:00
|
|
|
if (openfile->current_y == editwinrows - 1
|
2006-07-07 02:17:47 +04:00
|
|
|
#ifndef NANO_TINY
|
2014-03-03 17:24:09 +04:00
|
|
|
|| amount > 0 || scroll_only
|
2006-07-07 02:17:47 +04:00
|
|
|
#endif
|
2010-01-13 06:21:19 +03:00
|
|
|
) {
|
2014-03-03 17:24:09 +04:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (amount < 1 || scroll_only)
|
|
|
|
amount = 1;
|
|
|
|
#endif
|
2014-06-23 22:20:12 +04:00
|
|
|
edit_scroll(DOWNWARD,
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2014-03-03 17:24:09 +04:00
|
|
|
(ISSET(SMOOTH_SCROLL) || scroll_only) ? amount :
|
2003-09-08 03:57:24 +04:00
|
|
|
#endif
|
2010-01-13 06:21:19 +03:00
|
|
|
editwinrows / 2 + 1);
|
2016-04-12 15:00:36 +03:00
|
|
|
|
|
|
|
if (ISSET(SOFTWRAP)) {
|
2016-04-25 22:14:18 +03:00
|
|
|
refresh_needed = TRUE;
|
2016-04-12 15:00:36 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-01-13 06:21:19 +03:00
|
|
|
}
|
2016-04-12 14:29:51 +03:00
|
|
|
|
|
|
|
/* If we're not on the last line of the edit window, and the target
|
|
|
|
* column is beyond the screen or the mark is on, redraw the prior
|
|
|
|
* and current lines. */
|
|
|
|
if (openfile->current_y < editwinrows - 1 && need_screen_update(0)) {
|
|
|
|
update_line(openfile->current->prev, 0);
|
2005-07-17 02:50:30 +04:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
2005-10-24 06:12:09 +04:00
|
|
|
|
2006-07-07 02:17:47 +04:00
|
|
|
/* Move down one line. */
|
|
|
|
void do_down_void(void)
|
|
|
|
{
|
|
|
|
do_down(
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
FALSE
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-11-15 06:17:35 +03:00
|
|
|
#ifndef NANO_TINY
|
2005-12-08 10:09:08 +03:00
|
|
|
/* Scroll down one line 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
|
|
|
{
|
2005-07-09 00:09:16 +04:00
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
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) {
|
2006-07-07 02:17:47 +04:00
|
|
|
do_up_void();
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2015-04-20 11:16:41 +03:00
|
|
|
if (need_screen_update(pww_save))
|
2005-07-09 00:09:16 +04:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
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
|
|
|
{
|
2005-07-09 00:09:16 +04:00
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
assert(openfile->current_x <= strlen(openfile->current->data));
|
2002-09-07 00:35:28 +04:00
|
|
|
|
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);
|
2005-11-04 00:08:39 +03:00
|
|
|
else if (openfile->current != openfile->filebot) {
|
2006-07-07 02:17:47 +04:00
|
|
|
do_down_void();
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->current_x = 0;
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2015-04-20 11:16:41 +03:00
|
|
|
if (need_screen_update(pww_save))
|
2005-07-09 00:09:16 +04:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|