commit becb03b13a927cddaec660cf29db3f79f52570c0
parent e642b71ca3dc3826b58338581c168725a4f8621a
Author: ukai <ukai>
Date: Tue, 10 Dec 2002 15:51:14 +0000
[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:
5 files changed, 100 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,5 +1,20 @@
2002-12-11 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+ * [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
+
+2002-12-11 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+
* [w3m-dev 03552] Re: link list
* menu.c (accesskey_menu): check hseq
(list_menu): check hseq
diff --git a/fm.h b/fm.h
@@ -460,8 +460,18 @@ typedef struct _Buffer {
char image_flag;
char need_reshape;
Anchor *submit;
+ struct _BufferPos *undo;
} Buffer;
+typedef struct _BufferPos {
+ long top_linenumber;
+ long cur_linenumber;
+ short currentColumn;
+ short pos;
+ struct _BufferPos *next;
+ struct _BufferPos *prev;
+} BufferPos;
+
typedef struct _TabBuffer {
struct _TabBuffer *nextTab;
struct _TabBuffer *prevTab;
diff --git a/funcname.tab b/funcname.tab
@@ -105,6 +105,7 @@ PREV_WORD movLW
PRINT svBuf
QUIT qquitfm
READ_SHELL readsh
+REDO redoPos
REDRAW rdrwSc
REG_MARK reMark
REINIT reinit
@@ -137,6 +138,7 @@ TAB_LINK tabA
TAB_MENU tabMn
TAB_MOUSE tabMs
TAB_RIGHT tabR
+UNDO undoPos
UP lup1
VERSION dispVer
VIEW vwSrc
diff --git a/main.c b/main.c
@@ -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 = ⊤
+ 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);
+}
diff --git a/proto.h b/proto.h
@@ -146,6 +146,8 @@ extern Anchor *list_menu(Buffer *buf);
#define listMn nulcmd
#define movlistMn nulcmd
#endif
+extern void undoPos(void);
+extern void redoPos(void);
extern int currentLn(Buffer *buf);
extern void tmpClearBuffer(Buffer *buf);