aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2002-12-10 15:51:14 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2002-12-10 15:51:14 +0000
commit4eb0a6fe3d36a162666f7ca5e6275a07f3f6affb (patch)
treec21477e45fd1b81032d792a2ab93a98a9e5f352f /main.c
parent[w3m-dev 03552] Re: link list (diff)
downloadw3m-4eb0a6fe3d36a162666f7ca5e6275a07f3f6affb.tar.gz
w3m-4eb0a6fe3d36a162666f7ca5e6275a07f3f6affb.zip
[w3m-dev 03553] Undo/Redo
* fm.h (Buffer): add undo (BufferPos): added * funcname.tab (REDO): added (UNDO): added * main.c (save_buffer_position): added (main): save_buffer_position (resetPos): added (undoPos): added (redoPos): added * proto.h (undoPos): added (redoPos): added From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat (limited to '')
-rw-r--r--main.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/main.c b/main.c
index 21c9aa9..88fc703 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.164 2002/12/10 15:36:11 ukai Exp $ */
+/* $Id: main.c,v 1.165 2002/12/10 15:51:15 ukai Exp $ */
#define MAINPROGRAM
#include "fm.h"
#include <signal.h>
@@ -98,6 +98,7 @@ int on_target = 1;
static int add_download_list = FALSE;
void set_buffer_environ(Buffer *);
+static void save_buffer_position(Buffer *buf);
static void _followForm(int);
static void _goLine(char *);
@@ -1066,6 +1067,7 @@ main(int argc, char **argv, char **envp)
}
else {
set_buffer_environ(Currentbuf);
+ save_buffer_position(Currentbuf);
keyPressEventProc((int)c);
prec_num = 0;
if (add_download_list) {
@@ -6367,3 +6369,72 @@ ldDL(void)
}
#endif
}
+
+static void
+save_buffer_position(Buffer *buf)
+{
+ BufferPos *b = buf->undo;
+
+ if (!buf->firstLine)
+ return;
+ if (b && b->top_linenumber == TOP_LINENUMBER(buf) &&
+ b->cur_linenumber == CUR_LINENUMBER(buf) &&
+ b->currentColumn == buf->currentColumn &&
+ b->pos == buf->pos)
+ return;
+ b = New(BufferPos);
+ b->top_linenumber = TOP_LINENUMBER(buf);
+ b->cur_linenumber = CUR_LINENUMBER(buf);
+ b->currentColumn = buf->currentColumn;
+ b->pos = buf->pos;
+ b->next = NULL;
+ b->prev = buf->undo;
+ if (buf->undo)
+ buf->undo->next = b;
+ buf->undo = b;
+}
+
+static void
+resetPos(BufferPos *b)
+{
+ Buffer buf;
+ Line top, cur;
+
+ top.linenumber = b->top_linenumber;
+ cur.linenumber = b->cur_linenumber;
+ buf.topLine = &top;
+ buf.currentLine = &cur;
+ buf.pos = b->pos;
+ buf.currentColumn = b->currentColumn;
+ restorePosition(Currentbuf, &buf);
+ Currentbuf->undo = b;
+ displayBuffer(Currentbuf, B_FORCE_REDRAW);
+}
+
+void
+undoPos(void)
+{
+ BufferPos *b = Currentbuf->undo;
+ int i;
+
+ if (!Currentbuf->firstLine)
+ return;
+ if (!b || !b->prev)
+ return;
+ for (i = 0; i < PREC_NUM && b->prev; i++, b = b->prev) ;
+ resetPos(b);
+}
+
+void
+redoPos(void)
+{
+ BufferPos *b = Currentbuf->undo;
+ int i;
+
+ if (!Currentbuf->firstLine)
+ return;
+ if (!b || !b->next)
+ return;
+ for (i = 0; i < PREC_NUM && b->next; i++, b = b->next) ;
+ resetPos(b);
+}