2000-08-07 01:13:45 +04:00
|
|
|
/* $Id$ */
|
2000-06-19 08:22:15 +04:00
|
|
|
/**************************************************************************
|
|
|
|
* move.c *
|
|
|
|
* *
|
2005-01-12 06:25:57 +03:00
|
|
|
* Copyright (C) 1999-2005 Chris Allegretta *
|
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 *
|
2001-10-24 15:33:54 +04:00
|
|
|
* the Free Software Foundation; either version 2, 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
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2004-11-18 02:17:05 +03:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
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
|
|
|
#include "proto.h"
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_first_line(void)
|
2004-05-24 01:33:23 +04:00
|
|
|
{
|
2005-07-17 02:50:30 +04:00
|
|
|
const filestruct *current_save = openfile->current;
|
2005-07-09 00:09:16 +04:00
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
check_statusblank();
|
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->current = openfile->fileage;
|
|
|
|
openfile->current_x = 0;
|
2005-07-14 22:01:08 +04:00
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
2005-07-17 02:50:30 +04:00
|
|
|
edit_redraw(current_save, pww_save);
|
2004-05-24 01:33:23 +04:00
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_last_line(void)
|
2004-05-24 01:33:23 +04:00
|
|
|
{
|
2005-07-17 02:50:30 +04:00
|
|
|
const filestruct *current_save = openfile->current;
|
2005-07-09 00:09:16 +04:00
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
check_statusblank();
|
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->current = openfile->filebot;
|
|
|
|
openfile->current_x = 0;
|
2005-07-14 22:01:08 +04:00
|
|
|
openfile->placewewant = 0;
|
2005-08-16 05:27:05 +04:00
|
|
|
openfile->current_y = editwinrows - 1;
|
2005-07-14 22:01:08 +04:00
|
|
|
|
2005-07-17 02:50:30 +04:00
|
|
|
edit_redraw(current_save, pww_save);
|
2004-05-24 01:33:23 +04:00
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_page_up(void)
|
2000-07-03 08:24:39 +04:00
|
|
|
{
|
2005-07-17 04:01:18 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
check_statusblank();
|
|
|
|
|
2003-09-11 00:08:00 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2000-07-03 08:24:39 +04:00
|
|
|
wrap_reset();
|
2003-09-11 00:08:00 +04:00
|
|
|
#endif
|
2000-07-03 08:24:39 +04:00
|
|
|
|
2005-07-17 02:50:30 +04:00
|
|
|
/* If there's less than a page of text left on the screen, put the
|
|
|
|
* cursor at the beginning of the first line of the file, and then
|
|
|
|
* update the edit window. */
|
2005-07-17 04:01:18 +04:00
|
|
|
if (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. */
|
2003-09-08 03:57:24 +04:00
|
|
|
#ifndef NANO_SMALL
|
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;
|
|
|
|
openfile->placewewant = 0;
|
2003-09-08 03:57:24 +04:00
|
|
|
#ifndef NANO_SMALL
|
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
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
for (i = editwinrows - 2; i > 0 && openfile->current->prev != NULL;
|
|
|
|
i--)
|
|
|
|
openfile->current = openfile->current->prev;
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
/* Scroll the edit window up a page. */
|
|
|
|
edit_scroll(UP, editwinrows - 2);
|
2000-07-03 08:24:39 +04:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
check_statusblank();
|
|
|
|
|
2003-09-11 00:08:00 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2003-09-08 03:57:24 +04:00
|
|
|
wrap_reset();
|
2003-09-11 00:08:00 +04:00
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
|
2005-07-17 02:50:30 +04:00
|
|
|
/* If there's less than a page of text left on the screen, put the
|
|
|
|
* cursor at the beginning of the last line of the file, and then
|
|
|
|
* update the edit window. */
|
|
|
|
if (openfile->current->lineno + editwinrows - 2 >=
|
2005-07-17 04:01:18 +04:00
|
|
|
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. */
|
2002-12-22 19:30:00 +03:00
|
|
|
#ifndef NANO_SMALL
|
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;
|
|
|
|
openfile->placewewant = 0;
|
2003-09-08 03:57:24 +04:00
|
|
|
#ifndef NANO_SMALL
|
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
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
for (i = editwinrows - 2; i > 0 && openfile->current->next != NULL;
|
|
|
|
i--)
|
|
|
|
openfile->current = openfile->current->next;
|
2005-07-15 02:15:09 +04:00
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
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. */
|
|
|
|
edit_scroll(DOWN, editwinrows - 2);
|
2002-09-07 00:35:28 +04:00
|
|
|
}
|
|
|
|
|
2005-07-20 23:24:11 +04:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
|
|
|
/* Move up to the last beginning-of-paragraph line before the current
|
|
|
|
* line. */
|
|
|
|
void do_para_begin(bool allow_update)
|
|
|
|
{
|
|
|
|
const filestruct *current_save = openfile->current;
|
|
|
|
const size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
openfile->current_x = 0;
|
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
|
|
|
if (openfile->current->prev != NULL) {
|
|
|
|
do {
|
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_y--;
|
|
|
|
} while (!begpar(openfile->current));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allow_update)
|
|
|
|
edit_redraw(current_save, pww_save);
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_para_begin_void(void)
|
|
|
|
{
|
|
|
|
do_para_begin(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move down to the end of a paragraph, then one line farther. A line
|
|
|
|
* is the last line of a paragraph if it is in a paragraph, and the next
|
|
|
|
* line either is a beginning-of-paragraph line or isn't in a
|
|
|
|
* paragraph. */
|
|
|
|
void do_para_end(bool allow_update)
|
|
|
|
{
|
|
|
|
const filestruct *const current_save = openfile->current;
|
|
|
|
const size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
openfile->current_x = 0;
|
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
|
|
|
while (openfile->current->next != NULL && !inpar(openfile->current))
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
|
|
|
|
while (openfile->current->next != NULL &&
|
|
|
|
inpar(openfile->current->next) &&
|
|
|
|
!begpar(openfile->current->next)) {
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_y++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openfile->current->next != NULL)
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
|
|
|
|
if (allow_update)
|
|
|
|
edit_redraw(current_save, pww_save);
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_para_end_void(void)
|
|
|
|
{
|
|
|
|
do_para_end(TRUE);
|
|
|
|
}
|
|
|
|
#endif /* !DISABLE_JUSTIFY */
|
|
|
|
|
2005-07-21 01:31:19 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
/* Move to the next word in the current filestruct. If allow_punct is
|
|
|
|
* TRUE, treat punctuation as part of a word. If allow_update is TRUE,
|
|
|
|
* update the screen afterward. Return TRUE if we started on a word,
|
|
|
|
* and FALSE otherwise. */
|
|
|
|
bool do_next_word(bool allow_punct, bool allow_update)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
const filestruct *current_save = openfile->current;
|
|
|
|
char *char_mb;
|
|
|
|
int char_mb_len;
|
|
|
|
bool end_line = FALSE, started_on_word = FALSE;
|
|
|
|
|
|
|
|
assert(openfile->current != NULL && openfile->current->data != NULL);
|
|
|
|
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
char_mb = charalloc(mb_cur_max());
|
|
|
|
|
|
|
|
/* Move forward until we find the character after the last letter of
|
|
|
|
* the current word. */
|
|
|
|
while (!end_line) {
|
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
2005-07-26 10:13:45 +04:00
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-21 01:31:19 +04:00
|
|
|
|
|
|
|
/* If we've found it, stop moving forward through the current
|
|
|
|
* line. */
|
|
|
|
if (!is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If we haven't found it, then we've started on a word, so set
|
|
|
|
* started_on_word to TRUE. */
|
|
|
|
started_on_word = TRUE;
|
|
|
|
|
|
|
|
if (openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
end_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x += char_mb_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move forward until we find the first letter of the next word. */
|
|
|
|
if (openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
end_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x += char_mb_len;
|
|
|
|
|
|
|
|
for (; openfile->current != NULL;
|
|
|
|
openfile->current = openfile->current->next) {
|
|
|
|
while (!end_line) {
|
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
2005-07-26 10:13:45 +04:00
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-21 01:31:19 +04:00
|
|
|
|
|
|
|
/* If we've found it, stop moving forward through the
|
|
|
|
* current line. */
|
|
|
|
if (is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
end_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x += char_mb_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we've found it, stop moving forward to the beginnings of
|
|
|
|
* subsequent lines. */
|
|
|
|
if (!end_line)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (openfile->current->next != NULL) {
|
|
|
|
end_line = FALSE;
|
|
|
|
openfile->current_x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(char_mb);
|
|
|
|
|
|
|
|
/* If we haven't found it, leave the cursor at the end of the
|
|
|
|
* file. */
|
|
|
|
if (openfile->current == NULL)
|
|
|
|
openfile->current = openfile->filebot;
|
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
|
|
|
/* If allow_update is TRUE, update the screen. */
|
|
|
|
if (allow_update)
|
|
|
|
edit_redraw(current_save, pww_save);
|
|
|
|
|
|
|
|
/* Return whether we started on a word. */
|
|
|
|
return started_on_word;
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_next_word_void(void)
|
|
|
|
{
|
2005-08-11 02:12:28 +04:00
|
|
|
do_next_word(ISSET(WORD_BOUNDS), TRUE);
|
2005-07-21 01:31:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to the previous word in the current filestruct. If allow_punct
|
|
|
|
* is TRUE, treat punctuation as part of a word. If allow_update is
|
|
|
|
* TRUE, update the screen afterward. Return TRUE if we started on a
|
|
|
|
* word, and FALSE otherwise. */
|
|
|
|
bool do_prev_word(bool allow_punct, bool allow_update)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
const filestruct *current_save = openfile->current;
|
|
|
|
char *char_mb;
|
|
|
|
int char_mb_len;
|
|
|
|
bool begin_line = FALSE, started_on_word = FALSE;
|
|
|
|
|
|
|
|
assert(openfile->current != NULL && openfile->current->data != NULL);
|
|
|
|
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
char_mb = charalloc(mb_cur_max());
|
|
|
|
|
|
|
|
/* Move backward until we find the character before the first letter
|
|
|
|
* of the current word. */
|
|
|
|
while (!begin_line) {
|
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
2005-07-26 10:13:45 +04:00
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-21 01:31:19 +04:00
|
|
|
|
|
|
|
/* If we've found it, stop moving backward through the current
|
|
|
|
* line. */
|
|
|
|
if (!is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If we haven't found it, then we've started on a word, so set
|
|
|
|
* started_on_word to TRUE. */
|
|
|
|
started_on_word = TRUE;
|
|
|
|
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move backward until we find the last letter of the previous
|
|
|
|
* word. */
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
|
|
|
|
for (; openfile->current != NULL;
|
|
|
|
openfile->current = openfile->current->prev) {
|
|
|
|
while (!begin_line) {
|
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
2005-07-26 10:13:45 +04:00
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-21 01:31:19 +04:00
|
|
|
|
|
|
|
/* If we've found it, stop moving backward through the
|
|
|
|
* current line. */
|
|
|
|
if (is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x =
|
|
|
|
move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we've found it, stop moving backward to the ends of
|
|
|
|
* previous lines. */
|
|
|
|
if (!begin_line)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (openfile->current->prev != NULL) {
|
|
|
|
begin_line = FALSE;
|
|
|
|
openfile->current_x = strlen(openfile->current->prev->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we haven't found it, leave the cursor at the beginning of the
|
|
|
|
* file. */
|
|
|
|
if (openfile->current == NULL)
|
|
|
|
openfile->current = openfile->fileage;
|
|
|
|
/* If we've found it, move backward until we find the character
|
|
|
|
* before the first letter of the previous word. */
|
|
|
|
else if (!begin_line) {
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
|
|
|
|
while (!begin_line) {
|
2005-07-26 10:13:45 +04:00
|
|
|
char_mb_len = parse_mbchar(openfile->current->data +
|
|
|
|
openfile->current_x, char_mb, NULL);
|
2005-07-21 01:31:19 +04:00
|
|
|
|
|
|
|
/* If we've found it, stop moving backward through the
|
|
|
|
* current line. */
|
|
|
|
if (!is_word_mbchar(char_mb, allow_punct))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (openfile->current_x == 0)
|
|
|
|
begin_line = TRUE;
|
|
|
|
else
|
|
|
|
openfile->current_x =
|
|
|
|
move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we've found it, move forward to the first letter of the
|
|
|
|
* previous word. */
|
|
|
|
if (!begin_line)
|
|
|
|
openfile->current_x += char_mb_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(char_mb);
|
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
|
|
|
/* If allow_update is TRUE, update the screen. */
|
|
|
|
if (allow_update)
|
|
|
|
edit_redraw(current_save, pww_save);
|
|
|
|
|
|
|
|
/* Return whether we started on a word. */
|
|
|
|
return started_on_word;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
#endif /* !NANO_SMALL */
|
|
|
|
|
2005-07-20 23:24:11 +04:00
|
|
|
void do_home(void)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
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;
|
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
openfile->current_x = 0;
|
|
|
|
openfile->placewewant = 0;
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (need_horizontal_update(pww_save))
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_end(void)
|
|
|
|
{
|
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
|
|
|
if (need_horizontal_update(pww_save))
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_up(void)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
2005-07-17 04:01:18 +04:00
|
|
|
check_statusblank();
|
|
|
|
|
2003-09-11 00:08:00 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2000-06-19 08:22:15 +04:00
|
|
|
wrap_reset();
|
2003-09-11 00:08:00 +04:00
|
|
|
#endif
|
2003-09-08 03:57:24 +04:00
|
|
|
|
2005-07-14 22:01:08 +04:00
|
|
|
/* If we're at the top of the file, get out. */
|
2005-07-09 00:09:16 +04:00
|
|
|
if (openfile->current->prev == NULL)
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2003-09-08 03:57:24 +04:00
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
assert(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,
|
|
|
|
openfile->placewewant);
|
2004-05-29 00:44:09 +04:00
|
|
|
|
2005-07-17 02:35:11 +04:00
|
|
|
/* If we're on the first line of the edit window, scroll the edit
|
2005-07-15 00:37:01 +04:00
|
|
|
* window up one line if we're in smooth scrolling mode, or up half
|
|
|
|
* a page if we're not. */
|
2005-07-09 00:09:16 +04:00
|
|
|
if (openfile->current_y == 0)
|
2004-05-29 00:44:09 +04:00
|
|
|
edit_scroll(UP,
|
2003-09-08 03:57:24 +04:00
|
|
|
#ifndef NANO_SMALL
|
2005-06-16 06:13:10 +04:00
|
|
|
ISSET(SMOOTH_SCROLL) ? 1 :
|
2003-09-08 03:57:24 +04:00
|
|
|
#endif
|
2004-05-29 00:44:09 +04:00
|
|
|
editwinrows / 2);
|
2005-07-15 02:15:09 +04:00
|
|
|
/* Update the line we were on before and the line we're on now. The
|
|
|
|
* former needs to be redrawn if we're not on the first page, and
|
|
|
|
* the latter needs to be drawn unconditionally. */
|
2005-07-17 02:50:30 +04:00
|
|
|
else {
|
|
|
|
if (need_vertical_update(0))
|
|
|
|
update_line(openfile->current->next, 0);
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
|
2005-10-24 06:12:09 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
void do_scroll_up(void)
|
|
|
|
{
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
#ifndef DISABLE_WRAPPING
|
|
|
|
wrap_reset();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If the top of the file is onscreen, get out. */
|
|
|
|
if (openfile->edittop == openfile->fileage)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
|
|
|
|
|
|
|
|
/* Move the current line of the edit window up. */
|
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
|
|
|
|
|
|
|
/* Scroll the edit window up one line. */
|
|
|
|
edit_scroll(UP, 1);
|
|
|
|
}
|
|
|
|
#endif /* !NANO_SMALL */
|
|
|
|
|
2004-07-02 18:31:03 +04:00
|
|
|
void do_down(void)
|
2002-12-22 19:30:00 +03:00
|
|
|
{
|
2005-07-17 04:01:18 +04:00
|
|
|
check_statusblank();
|
|
|
|
|
2003-09-11 00:08:00 +04:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2002-07-19 05:08:59 +04:00
|
|
|
wrap_reset();
|
2003-09-11 00:08:00 +04:00
|
|
|
#endif
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2005-07-14 22:01:08 +04:00
|
|
|
/* If we're at the bottom of the file, get out. */
|
2005-07-09 00:09:16 +04:00
|
|
|
if (openfile->current->next == NULL)
|
2004-07-02 18:31:03 +04:00
|
|
|
return;
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
|
2005-06-28 22:57:28 +04:00
|
|
|
|
2005-07-17 02:35:11 +04:00
|
|
|
/* Move the current line of the edit window down. */
|
2005-07-09 00:09:16 +04:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2002-07-19 05:08:59 +04:00
|
|
|
|
2005-07-17 02:35:11 +04:00
|
|
|
/* If we're on the last line of the edit window, scroll the edit
|
2005-07-15 00:37:01 +04:00
|
|
|
* window down one line if we're in smooth scrolling mode, or down
|
|
|
|
* half a page if we're not. */
|
2005-07-09 00:09:16 +04:00
|
|
|
if (openfile->current_y == editwinrows - 1)
|
2004-05-29 00:44:09 +04:00
|
|
|
edit_scroll(DOWN,
|
2003-09-08 03:57:24 +04:00
|
|
|
#ifndef NANO_SMALL
|
2005-06-16 06:13:10 +04:00
|
|
|
ISSET(SMOOTH_SCROLL) ? 1 :
|
2003-09-08 03:57:24 +04:00
|
|
|
#endif
|
2004-05-29 00:44:09 +04:00
|
|
|
editwinrows / 2);
|
2005-07-15 02:15:09 +04:00
|
|
|
/* Update the line we were on before and the line we're on now. The
|
|
|
|
* former needs to be redrawn if we're not on the first page, and
|
|
|
|
* the latter needs to be drawn unconditionally. */
|
2005-07-17 02:50:30 +04:00
|
|
|
else {
|
|
|
|
if (need_vertical_update(0))
|
|
|
|
update_line(openfile->current->prev, 0);
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
2005-10-24 06:12:09 +04:00
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
void do_scroll_down(void)
|
|
|
|
{
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
#ifndef DISABLE_WRAPPING
|
|
|
|
wrap_reset();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If we're at the bottom of the file, get out. */
|
|
|
|
if (openfile->current->next == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
|
|
|
|
|
|
|
|
/* Move the current line of the edit window down. */
|
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
|
|
|
|
|
|
|
/* Scroll the edit window down one line. */
|
|
|
|
edit_scroll(DOWN, 1);
|
|
|
|
}
|
|
|
|
#endif /* !NANO_SMALL */
|
2000-06-19 08:22:15 +04:00
|
|
|
|
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;
|
|
|
|
|
2005-07-17 04:01:18 +04:00
|
|
|
check_statusblank();
|
|
|
|
|
2005-07-09 00:09:16 +04:00
|
|
|
if (openfile->current_x > 0)
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
else if (openfile->current != openfile->fileage) {
|
2002-09-07 00:35:28 +04:00
|
|
|
do_up();
|
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
|
|
|
|
2005-09-13 08:53:44 +04:00
|
|
|
if (need_horizontal_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-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-17 04:01:18 +04:00
|
|
|
check_statusblank();
|
|
|
|
|
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,
|
|
|
|
openfile->current_x);
|
|
|
|
else if (openfile->current->next != NULL) {
|
2002-09-07 00:35:28 +04:00
|
|
|
do_down();
|
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
|
|
|
|
2005-09-13 08:53:44 +04:00
|
|
|
if (need_horizontal_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
|
|
|
}
|