2000-08-06 21:13:45 +00:00
|
|
|
/* $Id$ */
|
2000-06-19 04:22:15 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* move.c *
|
|
|
|
* *
|
2005-01-12 03:25:57 +00:00
|
|
|
* Copyright (C) 1999-2005 Chris Allegretta *
|
2000-06-19 04:22:15 +00: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 11:33:54 +00:00
|
|
|
* the Free Software Foundation; either version 2, or (at your option) *
|
2000-06-19 04:22:15 +00:00
|
|
|
* any later version. *
|
|
|
|
* *
|
2005-05-15 19:57:17 +00: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 04:22:15 +00: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 19:57:17 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
|
|
|
|
* 02110-1301, USA. *
|
2000-06-19 04:22:15 +00:00
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2004-11-17 23:17:05 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2001-04-28 18:03:52 +00:00
|
|
|
|
2000-06-19 04:22:15 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-05-22 20:15:20 +00:00
|
|
|
#include <ctype.h>
|
2002-07-19 01:08:59 +00:00
|
|
|
#include <assert.h>
|
2000-06-19 04:22:15 +00:00
|
|
|
#include "proto.h"
|
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_first_line(void)
|
2004-05-23 21:33:23 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->fileage;
|
|
|
|
openfile->current_x = 0;
|
2005-07-14 18:01:08 +00:00
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->edittop != openfile->fileage ||
|
|
|
|
need_vertical_update(pww_save))
|
2004-08-26 18:07:58 +00:00
|
|
|
edit_update(TOP);
|
2004-05-23 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->filebot;
|
|
|
|
openfile->current_x = 0;
|
2005-07-14 18:01:08 +00:00
|
|
|
openfile->placewewant = 0;
|
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->edittop->lineno + (editwinrows / 2) !=
|
|
|
|
openfile->filebot->lineno || need_vertical_update(pww_save))
|
2004-08-26 18:07:58 +00:00
|
|
|
edit_update(CENTER);
|
2004-05-23 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_home(void)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2004-05-22 20:15:20 +00:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (ISSET(SMART_HOME)) {
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t current_x_save = openfile->current_x;
|
2004-05-22 20:15:20 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = indent_length(openfile->current->data);
|
2004-05-22 20:15:20 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->current_x == current_x_save ||
|
|
|
|
openfile->current->data[openfile->current_x] == '\0')
|
|
|
|
openfile->current_x = 0;
|
2004-05-22 20:15:20 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = xplustabs();
|
2004-05-22 20:15:20 +00:00
|
|
|
} else {
|
|
|
|
#endif
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = 0;
|
|
|
|
openfile->placewewant = 0;
|
2004-05-22 20:15:20 +00:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
}
|
|
|
|
#endif
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2004-09-30 22:07:21 +00:00
|
|
|
check_statusblank();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2004-12-07 21:22:48 +00:00
|
|
|
if (need_horizontal_update(pww_save))
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_end(void)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
|
|
|
openfile->placewewant = xplustabs();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2004-09-30 22:07:21 +00:00
|
|
|
check_statusblank();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2004-12-07 21:22:48 +00:00
|
|
|
if (need_horizontal_update(pww_save))
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_page_up(void)
|
2000-07-03 04:24:39 +00:00
|
|
|
{
|
2003-09-10 20:08:00 +00:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2000-07-03 04:24:39 +00:00
|
|
|
wrap_reset();
|
2003-09-10 20:08:00 +00:00
|
|
|
#endif
|
2000-07-03 04:24:39 +00:00
|
|
|
|
2004-05-28 20:44:09 +00:00
|
|
|
/* If the first line of the file is onscreen, move current up there
|
2003-09-07 23:57:24 +00:00
|
|
|
* and put the cursor at the beginning of the line. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->edittop == openfile->fileage) {
|
|
|
|
openfile->current = openfile->fileage;
|
2005-07-14 18:01:08 +00:00
|
|
|
openfile->current_x = 0;
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = 0;
|
2003-09-07 23:57:24 +00:00
|
|
|
} else {
|
|
|
|
#ifndef NANO_SMALL
|
2004-05-28 20:44:09 +00:00
|
|
|
/* If we're in smooth scrolling mode and there's at least one
|
2003-09-07 23:57:24 +00:00
|
|
|
* page of text left, move the current line of the edit window
|
|
|
|
* up a page. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno >
|
|
|
|
editwinrows - 2) {
|
2005-07-14 18:01:08 +00:00
|
|
|
int i = 0;
|
|
|
|
for (; i < editwinrows - 2; i++)
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->current->prev;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
|
|
|
/* Get the equivalent x-coordinate of the new line. */
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
/* If we're not in smooth scrolling mode or there isn't at least
|
2003-09-07 23:57:24 +00:00
|
|
|
* one page of text left, put the cursor at the beginning of the
|
|
|
|
* top line of the edit window, as Pico does. */
|
|
|
|
else {
|
|
|
|
#endif
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->edittop;
|
2005-07-14 18:01:08 +00:00
|
|
|
openfile->current_x = 0;
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = 0;
|
2003-09-07 23:57:24 +00:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-29 02:26:17 +00:00
|
|
|
|
2005-07-14 18:01:08 +00:00
|
|
|
edit_scroll(UP, editwinrows - 2);
|
|
|
|
}
|
2000-07-03 04:24:39 +00:00
|
|
|
|
2004-09-30 22:07:21 +00:00
|
|
|
check_statusblank();
|
2000-07-03 04:24:39 +00:00
|
|
|
}
|
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_page_down(void)
|
2002-09-06 20:35:28 +00:00
|
|
|
{
|
2003-09-10 20:08:00 +00:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2003-09-07 23:57:24 +00:00
|
|
|
wrap_reset();
|
2003-09-10 20:08:00 +00:00
|
|
|
#endif
|
2002-09-06 20:35:28 +00:00
|
|
|
|
2003-09-07 23:57:24 +00:00
|
|
|
/* If the last line of the file is onscreen, move current down
|
|
|
|
* there and put the cursor at the beginning of the line. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->edittop->lineno + editwinrows >
|
|
|
|
openfile->filebot->lineno) {
|
|
|
|
openfile->current = openfile->filebot;
|
2005-07-14 18:01:08 +00:00
|
|
|
openfile->current_x = 0;
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = 0;
|
2003-09-07 23:57:24 +00:00
|
|
|
} else {
|
2002-12-22 16:30:00 +00:00
|
|
|
#ifndef NANO_SMALL
|
2004-05-28 20:44:09 +00:00
|
|
|
/* If we're in smooth scrolling mode and there's at least one
|
2003-09-07 23:57:24 +00:00
|
|
|
* page of text left, move the current line of the edit window
|
|
|
|
* down a page. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno +
|
|
|
|
editwinrows - 2 <= openfile->filebot->lineno) {
|
2005-07-14 18:01:08 +00:00
|
|
|
int i = 0;
|
|
|
|
for (; i < editwinrows - 2; i++)
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->current->next;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
|
|
|
/* Get the equivalent x-coordinate of the new line. */
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
/* If we're not in smooth scrolling mode or there isn't at least
|
2003-09-07 23:57:24 +00:00
|
|
|
* one page of text left, put the cursor at the beginning of the
|
|
|
|
* top line of the edit window, as Pico does. */
|
|
|
|
else {
|
2002-12-22 16:30:00 +00:00
|
|
|
#endif
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->edittop;
|
2005-07-14 18:01:08 +00:00
|
|
|
openfile->current_x = 0;
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->placewewant = 0;
|
2003-09-07 23:57:24 +00:00
|
|
|
#ifndef NANO_SMALL
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
2003-09-07 23:57:24 +00:00
|
|
|
#endif
|
2004-05-28 20:44:09 +00:00
|
|
|
|
2005-07-14 18:01:08 +00:00
|
|
|
edit_scroll(DOWN, editwinrows - 2);
|
|
|
|
}
|
2002-09-06 20:35:28 +00:00
|
|
|
|
2004-09-30 22:07:21 +00:00
|
|
|
check_statusblank();
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_up(void)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2003-09-10 20:08:00 +00:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2000-06-19 04:22:15 +00:00
|
|
|
wrap_reset();
|
2003-09-10 20:08:00 +00:00
|
|
|
#endif
|
2004-09-30 22:07:21 +00:00
|
|
|
check_statusblank();
|
2003-09-07 23:57:24 +00:00
|
|
|
|
2005-07-14 18:01:08 +00:00
|
|
|
/* If we're at the top of the file, get out. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->current->prev == NULL)
|
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
|
|
|
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
|
2005-03-09 20:35:10 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->current->prev;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2004-05-28 20:44:09 +00:00
|
|
|
|
|
|
|
/* If we're on the first row of the edit window, scroll up one line
|
|
|
|
* if we're in smooth scrolling mode, or up half a page if we're
|
|
|
|
* not. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->current_y == 0)
|
2004-05-28 20:44:09 +00:00
|
|
|
edit_scroll(UP,
|
2003-09-07 23:57:24 +00:00
|
|
|
#ifndef NANO_SMALL
|
2005-06-16 02:13:10 +00:00
|
|
|
ISSET(SMOOTH_SCROLL) ? 1 :
|
2003-09-07 23:57:24 +00:00
|
|
|
#endif
|
2004-05-28 20:44:09 +00:00
|
|
|
editwinrows / 2);
|
2005-07-14 18:01:08 +00:00
|
|
|
/* Otherwise, 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 redrawn unconditionally. */
|
|
|
|
else {
|
|
|
|
if (need_vertical_update(0))
|
|
|
|
update_line(openfile->current->next, 0);
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2002-07-19 01:08:59 +00:00
|
|
|
}
|
2000-06-19 04:22:15 +00:00
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_down(void)
|
2002-12-22 16:30:00 +00:00
|
|
|
{
|
2003-09-10 20:08:00 +00:00
|
|
|
#ifndef DISABLE_WRAPPING
|
2002-07-19 01:08:59 +00:00
|
|
|
wrap_reset();
|
2003-09-10 20:08:00 +00:00
|
|
|
#endif
|
2004-09-30 22:07:21 +00:00
|
|
|
check_statusblank();
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2005-07-14 18:01:08 +00:00
|
|
|
/* If we're at the bottom of the file, get out. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->current->next == NULL)
|
2004-07-02 14:31:03 +00:00
|
|
|
return;
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
|
2005-06-28 18:57:28 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current = openfile->current->next;
|
|
|
|
openfile->current_x = actual_x(openfile->current->data,
|
|
|
|
openfile->placewewant);
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2004-05-28 20:44:09 +00:00
|
|
|
/* If we're on the last row of the edit window, scroll down one line
|
|
|
|
* if we're in smooth scrolling mode, or down half a page if we're
|
|
|
|
* not. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->current_y == editwinrows - 1)
|
2004-05-28 20:44:09 +00:00
|
|
|
edit_scroll(DOWN,
|
2003-09-07 23:57:24 +00:00
|
|
|
#ifndef NANO_SMALL
|
2005-06-16 02:13:10 +00:00
|
|
|
ISSET(SMOOTH_SCROLL) ? 1 :
|
2003-09-07 23:57:24 +00:00
|
|
|
#endif
|
2004-05-28 20:44:09 +00:00
|
|
|
editwinrows / 2);
|
2005-07-14 18:01:08 +00:00
|
|
|
/* Otherwise, 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 redrawn unconditionally. */
|
|
|
|
else {
|
|
|
|
if (need_vertical_update(0))
|
|
|
|
update_line(openfile->current->prev, 0);
|
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
}
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
|
|
|
|
2004-12-31 04:10:28 +00:00
|
|
|
void do_left(bool allow_update)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t pww_save = openfile->placewewant;
|
|
|
|
|
|
|
|
if (openfile->current_x > 0)
|
|
|
|
openfile->current_x = move_mbleft(openfile->current->data,
|
|
|
|
openfile->current_x);
|
|
|
|
else if (openfile->current != openfile->fileage) {
|
2002-09-06 20:35:28 +00:00
|
|
|
do_up();
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
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
|
|
|
|
2004-09-30 22:07:21 +00:00
|
|
|
check_statusblank();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2004-12-07 21:22:48 +00:00
|
|
|
if (allow_update && need_horizontal_update(pww_save))
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_left_void(void)
|
2004-05-28 20:44:09 +00:00
|
|
|
{
|
2004-07-02 14:31:03 +00:00
|
|
|
do_left(TRUE);
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
|
2004-12-31 04:10:28 +00:00
|
|
|
void do_right(bool allow_update)
|
2000-06-19 04:22:15 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t pww_save = openfile->placewewant;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
assert(openfile->current_x <= strlen(openfile->current->data));
|
2002-09-06 20:35:28 +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,
|
|
|
|
openfile->current_x);
|
|
|
|
else if (openfile->current->next != NULL) {
|
2002-09-06 20:35:28 +00:00
|
|
|
do_down();
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x = 0;
|
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
|
|
|
|
2004-09-30 22:07:21 +00:00
|
|
|
check_statusblank();
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2004-12-07 21:22:48 +00:00
|
|
|
if (allow_update && need_horizontal_update(pww_save))
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2000-06-19 04:22:15 +00:00
|
|
|
}
|
2004-05-28 20:44:09 +00:00
|
|
|
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_right_void(void)
|
2004-05-28 20:44:09 +00:00
|
|
|
{
|
2004-07-02 14:31:03 +00:00
|
|
|
do_right(TRUE);
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|