2000-08-07 01:13:45 +04:00
|
|
|
/* $Id$ */
|
2000-06-19 08:22:15 +04:00
|
|
|
/**************************************************************************
|
|
|
|
* move.c *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 1999 Chris Allegretta *
|
|
|
|
* 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 *
|
|
|
|
* the Free Software Foundation; either version 1, or (at your option) *
|
|
|
|
* 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>
|
|
|
|
#include "proto.h"
|
|
|
|
#include "nano.h"
|
2000-06-21 07:00:43 +04:00
|
|
|
|
2000-06-19 08:22:15 +04:00
|
|
|
#ifndef NANO_SMALL
|
|
|
|
#include <libintl.h>
|
|
|
|
#define _(string) gettext(string)
|
|
|
|
#else
|
|
|
|
#define _(string) (string)
|
|
|
|
#endif
|
|
|
|
|
2001-09-22 23:02:04 +04:00
|
|
|
void page_down(void)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
2001-09-27 04:44:58 +04:00
|
|
|
if (!ISSET(SMOOTHSCROLL)) {
|
|
|
|
if (editbot != filebot) {
|
2001-09-22 23:02:04 +04:00
|
|
|
edit_update(editbot->next, CENTER);
|
|
|
|
center_cursor();
|
|
|
|
} else {
|
|
|
|
while (current != filebot)
|
|
|
|
current = current->next;
|
|
|
|
edit_update(current, CENTER);
|
|
|
|
}
|
2001-09-27 04:44:58 +04:00
|
|
|
} else {
|
|
|
|
edit_update(editbot, NONE);
|
2000-06-19 08:22:15 +04:00
|
|
|
}
|
|
|
|
update_cursor();
|
|
|
|
}
|
|
|
|
|
2001-09-22 23:02:04 +04:00
|
|
|
int do_page_down(void)
|
2000-06-19 08:22:15 +04:00
|
|
|
{
|
|
|
|
wrap_reset();
|
|
|
|
current_x = 0;
|
|
|
|
placewewant = 0;
|
|
|
|
|
|
|
|
if (current == filebot)
|
|
|
|
return 0;
|
|
|
|
|
2001-05-05 21:45:54 +04:00
|
|
|
/* AHEM, if we only have a screen or less of text, DON'T do an
|
2001-01-08 04:32:58 +03:00
|
|
|
edit_update, just move the cursor to editbot! */
|
2001-03-16 00:14:32 +03:00
|
|
|
if (edittop == fileage && editbot == filebot && totlines < editwinrows) {
|
2001-01-08 04:32:58 +03:00
|
|
|
current = editbot;
|
|
|
|
reset_cursor();
|
|
|
|
} else if (editbot != filebot || edittop == fileage) {
|
2000-06-19 08:22:15 +04:00
|
|
|
current_y = 0;
|
2000-10-26 05:44:42 +04:00
|
|
|
current = editbot;
|
2000-07-29 08:33:38 +04:00
|
|
|
|
|
|
|
if (current->prev != NULL)
|
|
|
|
current = current->prev;
|
|
|
|
if (current->prev != NULL)
|
|
|
|
current = current->prev;
|
|
|
|
edit_update(current, TOP);
|
|
|
|
} else {
|
2000-06-19 08:22:15 +04:00
|
|
|
while (current != filebot) {
|
|
|
|
current = current->next;
|
|
|
|
current_y++;
|
|
|
|
}
|
2000-07-29 08:33:38 +04:00
|
|
|
edit_update(edittop, TOP);
|
|
|
|
}
|
2000-06-19 08:22:15 +04:00
|
|
|
|
|
|
|
update_cursor();
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* What happens when we want to go past the bottom of the buffer */
|
|
|
|
int do_down(void)
|
|
|
|
{
|
|
|
|
wrap_reset();
|
|
|
|
if (current->next != NULL) {
|
|
|
|
update_line(current->prev, 0);
|
|
|
|
|
|
|
|
if (placewewant > 0)
|
|
|
|
current_x = actual_x(current->next, placewewant);
|
|
|
|
|
|
|
|
if (current_x > strlen(current->next->data))
|
|
|
|
current_x = strlen(current->next->data);
|
|
|
|
} else {
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 0;
|
|
|
|
}
|
2000-06-21 07:00:43 +04:00
|
|
|
|
|
|
|
if (current_y < editwinrows - 1 && current != editbot)
|
2000-06-19 08:22:15 +04:00
|
|
|
current_y++;
|
|
|
|
else
|
2001-09-22 23:02:04 +04:00
|
|
|
page_down();
|
2000-06-19 08:22:15 +04:00
|
|
|
|
|
|
|
update_cursor();
|
|
|
|
update_line(current->prev, 0);
|
|
|
|
update_line(current, current_x);
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
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) {
|
2001-09-22 23:02:04 +04:00
|
|
|
if (!ISSET(SMOOTHSCROLL)) {
|
|
|
|
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();
|
|
|
|
else {
|
|
|
|
current = current->prev;
|
|
|
|
reset_cursor();
|
|
|
|
}
|
2001-09-22 23:02:04 +04:00
|
|
|
} else {
|
|
|
|
edit_update(edittop->prev, NONE);
|
|
|
|
}
|
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
|
|
|
{
|
2001-04-29 06:26:17 +04:00
|
|
|
int i;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-19 08:22:15 +04:00
|
|
|
int do_up(void)
|
|
|
|
{
|
|
|
|
wrap_reset();
|
|
|
|
if (current->prev != NULL) {
|
|
|
|
if (placewewant > 0)
|
|
|
|
current_x = actual_x(current->prev, placewewant);
|
|
|
|
|
|
|
|
if (current_x > strlen(current->prev->data))
|
|
|
|
current_x = strlen(current->prev->data);
|
|
|
|
}
|
|
|
|
if (current_y > 0)
|
|
|
|
current_y--;
|
|
|
|
else
|
2001-09-22 23:02:04 +04:00
|
|
|
page_up();
|
2000-06-19 08:22:15 +04:00
|
|
|
|
|
|
|
update_cursor();
|
|
|
|
update_line(current->next, 0);
|
|
|
|
update_line(current, current_x);
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_right(void)
|
|
|
|
{
|
|
|
|
if (current_x < strlen(current->data)) {
|
|
|
|
current_x++;
|
|
|
|
} else {
|
|
|
|
if (do_down())
|
|
|
|
current_x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
placewewant = xplustabs();
|
|
|
|
update_cursor();
|
|
|
|
update_line(current, current_x);
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_left(void)
|
|
|
|
{
|
|
|
|
if (current_x > 0)
|
|
|
|
current_x--;
|
|
|
|
else if (current != fileage) {
|
|
|
|
placewewant = 0;
|
|
|
|
current_x = strlen(current->prev->data);
|
|
|
|
do_up();
|
|
|
|
}
|
|
|
|
placewewant = xplustabs();
|
|
|
|
|
|
|
|
update_cursor();
|
|
|
|
update_line(current, current_x);
|
|
|
|
UNSET(KEEP_CUTBUFFER);
|
|
|
|
check_statblank();
|
|
|
|
return 1;
|
|
|
|
}
|