2000-08-07 01:13:45 +04:00
|
|
|
/* $Id$ */
|
2000-06-19 08:22:15 +04:00
|
|
|
/**************************************************************************
|
|
|
|
* move.c *
|
|
|
|
* *
|
2003-01-15 22:33:27 +03:00
|
|
|
* Copyright (C) 1999-2003 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. *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2001-04-28 22:03:52 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-06-19 08:22:15 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2002-07-19 05:08:59 +04:00
|
|
|
#include <assert.h>
|
2000-06-19 08:22:15 +04:00
|
|
|
#include "proto.h"
|
|
|
|
#include "nano.h"
|
|
|
|
|
|
|
|
int do_home(void)
|
|
|
|
{
|
2001-06-11 10:56:10 +04:00
|
|
|
UNSET(KEEP_CUTBUFFER);
|
2000-06-19 08:22:15 +04:00
|
|
|
current_x = 0;
|
|
|
|
placewewant = 0;
|
|
|
|
update_line(current, current_x);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_end(void)
|
|
|
|
{
|
2001-06-11 10:56:10 +04:00
|
|
|
UNSET(KEEP_CUTBUFFER);
|
2000-06-19 08:22:15 +04:00
|
|
|
current_x = strlen(current->data);
|
|
|
|
placewewant = xplustabs();
|
|
|
|
update_line(current, current_x);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-09-22 23:02:04 +04:00
|
|
|
void page_up(void)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
|
|
|
if (edittop != fileage) {
|
2002-07-19 05:08:59 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (ISSET(SMOOTHSCROLL))
|
|
|
|
edit_update(edittop->prev, TOP);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2001-09-22 23:02:04 +04:00
|
|
|
edit_update(edittop, CENTER);
|
2001-10-02 04:38:56 +04:00
|
|
|
/* Now that we've updated the edit window, edittop might be
|
|
|
|
at the top of the file; if so, just move the cursor up one
|
|
|
|
line and don't center it. */
|
|
|
|
if (edittop != fileage)
|
|
|
|
center_cursor();
|
2002-08-21 20:10:37 +04:00
|
|
|
else
|
2001-10-02 04:38:56 +04:00
|
|
|
reset_cursor();
|
2001-09-22 23:02:04 +04:00
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
} else
|
|
|
|
current_y = 0;
|
|
|
|
|
|
|
|
update_cursor();
|
|
|
|
}
|
|
|
|
|
2001-09-22 23:02:04 +04:00
|
|
|
int do_page_up(void)
|
2000-07-03 08:24:39 +04:00
|
|
|
{
|
2002-06-13 04:40:19 +04:00
|
|
|
int i;
|
2001-04-29 06:26:17 +04:00
|
|
|
|
2000-07-03 08:24:39 +04:00
|
|
|
wrap_reset();
|
|
|
|
current_x = 0;
|
|
|
|
placewewant = 0;
|
|
|
|
|
|
|
|
if (current == fileage)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
current_y = 0;
|
2000-07-29 08:33:38 +04:00
|
|
|
current = edittop;
|
2001-04-29 06:26:17 +04:00
|
|
|
for (i = 0; i <= editwinrows - 3 && current->prev != NULL; i++)
|
|
|
|
current = current->prev;
|
|
|
|
|
|
|
|
edit_update(current, TOP);
|
2000-07-03 08:24:39 +04:00
|
|
|
update_cursor();
|
|
|
|
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
int do_page_down(void)
|
|
|
|
{
|
|
|
|
wrap_reset();
|
|
|
|
current_x = 0;
|
|
|
|
placewewant = 0;
|
|
|
|
|
|
|
|
if (current == filebot)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* AHEM, if we only have a screen or less of text, DON'T do an
|
2002-12-22 19:30:00 +03:00
|
|
|
edit_update(), just move the cursor to editbot! */
|
2002-09-07 00:35:28 +04:00
|
|
|
if (edittop == fileage && editbot == filebot && totlines < editwinrows) {
|
|
|
|
current = editbot;
|
|
|
|
reset_cursor();
|
2002-12-22 19:30:00 +03:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
/* ...unless marking is on, in which case we need it to update
|
|
|
|
the highlight. */
|
|
|
|
if (ISSET(MARK_ISSET))
|
|
|
|
edit_update(current, NONE);
|
|
|
|
#endif
|
2002-09-07 00:35:28 +04:00
|
|
|
} else if (editbot != filebot || edittop == fileage) {
|
|
|
|
current_y = 0;
|
|
|
|
current = editbot;
|
|
|
|
|
|
|
|
if (current->prev != NULL)
|
|
|
|
current = current->prev;
|
|
|
|
if (current->prev != NULL)
|
|
|
|
current = current->prev;
|
|
|
|
edit_update(current, TOP);
|
|
|
|
} else {
|
|
|
|
while (current != filebot) {
|
|
|
|
current = current->next;
|
|
|
|
current_y++;
|
|
|
|
}
|
|
|
|
edit_update(edittop, TOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
update_cursor();
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-06-19 08:22:15 +04:00
|
|
|
int do_up(void)
|
|
|
|
{
|
|
|
|
wrap_reset();
|
|
|
|
if (current->prev != NULL) {
|
2002-07-19 05:08:59 +04:00
|
|
|
current_x = actual_x(current->prev, placewewant);
|
|
|
|
current = current->prev;
|
|
|
|
if (current_y > 0) {
|
|
|
|
update_line(current->next, 0);
|
|
|
|
/* It is necessary to change current first, so the mark
|
|
|
|
display will change! */
|
|
|
|
current_y--;
|
|
|
|
update_line(current, current_x);
|
|
|
|
} else
|
|
|
|
page_up();
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
2002-07-19 05:08:59 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
|
2002-07-19 05:08:59 +04:00
|
|
|
/* Return value 1 means we moved down, 0 means we were already at the
|
|
|
|
* bottom. */
|
2002-12-22 19:30:00 +03:00
|
|
|
int do_down(void)
|
|
|
|
{
|
2002-07-19 05:08:59 +04:00
|
|
|
wrap_reset();
|
2000-06-19 08:22:15 +04:00
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
2002-07-19 05:08:59 +04:00
|
|
|
|
|
|
|
if (current->next == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
current_x = actual_x(current, placewewant);
|
|
|
|
|
2003-01-15 22:33:27 +03:00
|
|
|
/* Note current_y is zero-based. This test checks for the cursor's
|
2002-07-19 05:08:59 +04:00
|
|
|
* being on the last row of the edit window. */
|
|
|
|
if (current_y == editwinrows - 1) {
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
if (ISSET(SMOOTHSCROLL)) {
|
|
|
|
/* In this case current_y does not change. The cursor
|
|
|
|
* remains at the bottom of the edit window. */
|
|
|
|
edittop = edittop->next;
|
|
|
|
editbot = editbot->next;
|
|
|
|
edit_refresh();
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2002-08-21 20:10:37 +04:00
|
|
|
/* Set edittop so editbot->next (or else editbot) is
|
|
|
|
* centered, and set current_y = editwinrows / 2. */
|
|
|
|
edit_update(editbot->next != NULL ? editbot->next : editbot, CENTER);
|
2002-07-19 05:08:59 +04:00
|
|
|
center_cursor();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
update_line(current->prev, 0);
|
|
|
|
update_line(current, current_x);
|
|
|
|
current_y++;
|
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
int do_left(void)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
2002-09-07 00:35:28 +04:00
|
|
|
if (current_x > 0)
|
|
|
|
current_x--;
|
|
|
|
else if (current != fileage) {
|
|
|
|
do_up();
|
|
|
|
current_x = strlen(current->data);
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
|
|
|
placewewant = xplustabs();
|
|
|
|
update_line(current, current_x);
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-09-07 00:35:28 +04:00
|
|
|
int do_right(void)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
2002-09-07 00:35:28 +04:00
|
|
|
assert(current_x <= strlen(current->data));
|
|
|
|
|
|
|
|
if (current->data[current_x] != '\0')
|
|
|
|
current_x++;
|
2002-12-22 19:30:00 +03:00
|
|
|
else if (current->next != NULL) {
|
2002-09-07 00:35:28 +04:00
|
|
|
do_down();
|
|
|
|
current_x = 0;
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
|
|
|
placewewant = xplustabs();
|
|
|
|
update_line(current, current_x);
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 1;
|
|
|
|
}
|