mirror of
https://github.com/bobbimanners/emailler.git
synced 2024-07-06 03:28:59 +00:00
EDIT: Added OA-Z 'Undo' command - can undo cut/paste/block delete/insert file.
This commit is contained in:
parent
213780c5d1
commit
5b1176ed8c
49
apps/edit.c
49
apps/edit.c
@ -4,12 +4,13 @@
|
|||||||
// Bobbi July-Aug 2020
|
// Bobbi July-Aug 2020
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// TODO: File picker!!
|
// TODO: See GitHub issues!!!
|
||||||
// TODO: Search options - ignore case, complete word.
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Note: Use my fork of cc65 to get a flashing cursor!!
|
// Note: Use my fork of cc65 to get a flashing cursor!!
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#define AUXMEM // Still somewhat experimental
|
#define AUXMEM
|
||||||
|
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -49,14 +50,17 @@ char padding = 0; // To null terminate for strstr()
|
|||||||
|
|
||||||
// The following fields, plus the gap buffer, represent the state of
|
// The following fields, plus the gap buffer, represent the state of
|
||||||
// the current buffer. These are stashed in each aux page from 0x200 up.
|
// the current buffer. These are stashed in each aux page from 0x200 up.
|
||||||
// Total 80 + 3 + 2 + 2 = 87 bytes
|
// Total 80 + 3 + 2 + 2 + 1 + 2 + 2 = 92 bytes
|
||||||
#define BUFINFOSZ 87
|
#define BUFINFOSZ 92
|
||||||
char filename[80] = "";
|
char filename[80] = "";
|
||||||
uint8_t status[3] = {0, 0, 0}; // status[0] is 1 if file has been modified
|
uint8_t status[3] = {0, 0, 0}; // status[0] is 1 if file has been modified
|
||||||
// status[1] is 1 if should warn for overwrite
|
// status[1] is 1 if should warn for overwrite
|
||||||
// status[2] is part # for multi-part files
|
// status[2] is part # for multi-part files
|
||||||
uint16_t gapbegin = 0;
|
uint16_t gapbegin = 0;
|
||||||
uint16_t gapend = BUFSZ - 1;
|
uint16_t gapend = BUFSZ - 1;
|
||||||
|
uint8_t canundo = 0; // For OA-Z "Undo"
|
||||||
|
uint16_t oldgapbegin = 0; // ditto
|
||||||
|
uint16_t oldgapend = BUFSZ - 1; // ditto
|
||||||
|
|
||||||
char userentry[82] = ""; // Couple extra chars so we can store 80 col line
|
char userentry[82] = ""; // Couple extra chars so we can store 80 col line
|
||||||
char search[80] = "";
|
char search[80] = "";
|
||||||
@ -1955,6 +1959,15 @@ void order_selection(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remember current gapbuf settings to support undo
|
||||||
|
*/
|
||||||
|
void mark_undo(void) {
|
||||||
|
oldgapbegin = gapbegin;
|
||||||
|
oldgapend = gapend;
|
||||||
|
canundo = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main editor routine
|
* Main editor routine
|
||||||
* fname - filename to open or ""
|
* fname - filename to open or ""
|
||||||
@ -2098,6 +2111,7 @@ int edit(char *fname) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (tmp == 0) { // Cut
|
if (tmp == 0) { // Cut
|
||||||
|
mark_undo();
|
||||||
jump_pos(startsel);
|
jump_pos(startsel);
|
||||||
gapend += (endsel - startsel);
|
gapend += (endsel - startsel);
|
||||||
set_modified(1);
|
set_modified(1);
|
||||||
@ -2110,6 +2124,7 @@ int edit(char *fname) {
|
|||||||
case 0x80 + 'v': // OA-v
|
case 0x80 + 'v': // OA-v
|
||||||
case 0x16: // ^V "Paste"
|
case 0x16: // ^V "Paste"
|
||||||
mode = SEL_NONE;
|
mode = SEL_NONE;
|
||||||
|
mark_undo();
|
||||||
if (cutbuflen > 0) {
|
if (cutbuflen > 0) {
|
||||||
__asm__("lda %v", auxbank);
|
__asm__("lda %v", auxbank);
|
||||||
__asm__("sta $c073"); // Set aux bank
|
__asm__("sta $c073"); // Set aux bank
|
||||||
@ -2149,6 +2164,7 @@ int edit(char *fname) {
|
|||||||
ask = 0;
|
ask = 0;
|
||||||
if (prompt_okay("Ask for each") == 0)
|
if (prompt_okay("Ask for each") == 0)
|
||||||
ask = 1;
|
ask = 1;
|
||||||
|
canundo = 0;
|
||||||
}
|
}
|
||||||
do_search_replace(tmp, ask);
|
do_search_replace(tmp, ask);
|
||||||
update_status_line();
|
update_status_line();
|
||||||
@ -2159,6 +2175,7 @@ int edit(char *fname) {
|
|||||||
break; // ESC pressed
|
break; // ESC pressed
|
||||||
if (strlen(userentry) == 0)
|
if (strlen(userentry) == 0)
|
||||||
break;
|
break;
|
||||||
|
mark_undo();
|
||||||
if (load_file(userentry, 0, 0)) {
|
if (load_file(userentry, 0, 0)) {
|
||||||
snprintf(iobuf, 80, "Can't open '%s'", userentry);
|
snprintf(iobuf, 80, "Can't open '%s'", userentry);
|
||||||
show_error(iobuf);
|
show_error(iobuf);
|
||||||
@ -2179,6 +2196,7 @@ int edit(char *fname) {
|
|||||||
show_error(userentry);
|
show_error(userentry);
|
||||||
strcpy(filename, "");
|
strcpy(filename, "");
|
||||||
}
|
}
|
||||||
|
canundo = 0;
|
||||||
draw_screen();
|
draw_screen();
|
||||||
break;
|
break;
|
||||||
case 0x80 + 'N': // OA-N "Name"
|
case 0x80 + 'N': // OA-N "Name"
|
||||||
@ -2204,11 +2222,13 @@ int edit(char *fname) {
|
|||||||
break;
|
break;
|
||||||
case 0x80 + 'U': // OA-U "Unwrap"
|
case 0x80 + 'U': // OA-U "Unwrap"
|
||||||
case 0x80 + 'u': // OA-w
|
case 0x80 + 'u': // OA-w
|
||||||
|
canundo = 0;
|
||||||
word_wrap_para(0);
|
word_wrap_para(0);
|
||||||
draw_screen();
|
draw_screen();
|
||||||
break;
|
break;
|
||||||
case 0x80 + 'W': // OA-W "Wrap"
|
case 0x80 + 'W': // OA-W "Wrap"
|
||||||
case 0x80 + 'w': // OA-w
|
case 0x80 + 'w': // OA-w
|
||||||
|
canundo = 0;
|
||||||
word_wrap_para(1);
|
word_wrap_para(1);
|
||||||
draw_screen();
|
draw_screen();
|
||||||
break;
|
break;
|
||||||
@ -2217,12 +2237,24 @@ int edit(char *fname) {
|
|||||||
save();
|
save();
|
||||||
draw_screen();
|
draw_screen();
|
||||||
break;
|
break;
|
||||||
|
case 0x80 + 'Z': // OA-Z "Undo"
|
||||||
|
case 0x80 + 'z': // OA-z
|
||||||
|
case 0x1a: // Ctrl-Z
|
||||||
|
if (canundo) {
|
||||||
|
gapbegin = oldgapbegin;
|
||||||
|
gapend = oldgapend;
|
||||||
|
canundo = 0;
|
||||||
|
draw_screen();
|
||||||
|
} else
|
||||||
|
beep();
|
||||||
|
break;
|
||||||
case 0x80 + DELETE: // OA-Backspace
|
case 0x80 + DELETE: // OA-Backspace
|
||||||
case 0x04: // Ctrl-D "DELETE"
|
case 0x04: // Ctrl-D "DELETE"
|
||||||
if (mode == SEL_NONE) {
|
if (mode == SEL_NONE) {
|
||||||
delete_char_right();
|
delete_char_right();
|
||||||
update_after_delete_char_right();
|
update_after_delete_char_right();
|
||||||
set_modified(1);
|
set_modified(1);
|
||||||
|
canundo = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x80 + '?': // OA-? "Help"
|
case 0x80 + '?': // OA-? "Help"
|
||||||
@ -2254,6 +2286,7 @@ donehelp:
|
|||||||
delete_char();
|
delete_char();
|
||||||
update_after_delete_char();
|
update_after_delete_char();
|
||||||
set_modified(1);
|
set_modified(1);
|
||||||
|
canundo = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snprintf(userentry, 80,
|
snprintf(userentry, 80,
|
||||||
@ -2262,6 +2295,7 @@ donehelp:
|
|||||||
break;
|
break;
|
||||||
order_selection();
|
order_selection();
|
||||||
mode = SEL_NONE;
|
mode = SEL_NONE;
|
||||||
|
mark_undo();
|
||||||
jump_pos(startsel);
|
jump_pos(startsel);
|
||||||
gapend += (endsel - startsel);
|
gapend += (endsel - startsel);
|
||||||
set_modified(1);
|
set_modified(1);
|
||||||
@ -2278,6 +2312,7 @@ donehelp:
|
|||||||
update_after_insert_char();
|
update_after_insert_char();
|
||||||
}
|
}
|
||||||
set_modified(1);
|
set_modified(1);
|
||||||
|
canundo = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x08: // Left
|
case 0x08: // Left
|
||||||
@ -2297,6 +2332,7 @@ donehelp:
|
|||||||
insert_char(c);
|
insert_char(c);
|
||||||
update_after_insert_char();
|
update_after_insert_char();
|
||||||
set_modified(1);
|
set_modified(1);
|
||||||
|
canundo = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -2361,6 +2397,8 @@ donehelp:
|
|||||||
change_aux_bank(tmp);
|
change_aux_bank(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
set_modified(1);
|
||||||
|
canundo = 0;
|
||||||
} else if ((c =='S') || (c == 's')) { // CA-S "Save all"
|
} else if ((c =='S') || (c == 's')) { // CA-S "Save all"
|
||||||
save_all();
|
save_all();
|
||||||
draw_screen();
|
draw_screen();
|
||||||
@ -2373,6 +2411,7 @@ donehelp:
|
|||||||
insert_char(c);
|
insert_char(c);
|
||||||
update_after_insert_char();
|
update_after_insert_char();
|
||||||
set_modified(1);
|
set_modified(1);
|
||||||
|
canundo = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
v1.21 }}} EDIT.SYSTEM HELP }}} Page One
|
v1.22 }}} EDIT.SYSTEM HELP }}} Page One
|
||||||
--------------------------------------+-----------------------------------------
|
--------------------------------------+-----------------------------------------
|
||||||
Navigation: | Editing:
|
Navigation: | Editing:
|
||||||
Cursor keys Move the cursor | [Return] Split line
|
Cursor keys Move the cursor | [Return] Split line
|
||||||
@ -19,6 +19,6 @@
|
|||||||
{-S Save file | {-V Paste previous cut or copy
|
{-S Save file | {-V Paste previous cut or copy
|
||||||
{-Q Quit | [Delete] Delete selected text
|
{-Q Quit | [Delete] Delete selected text
|
||||||
| ESC Clear selection
|
| ESC Clear selection
|
||||||
--------------------------------------+-----------------------------------------
|
--------------+-----------------------| {-Z Undo block operation
|
||||||
[Q]uit help | [Any Other Key] Next Page
|
[Q]uit help | [Any Other Key] next |
|
||||||
--------------------------------------+----------------------------------------
|
--------------+-----------------------+----------------------------------------
|
||||||
|
@ -19,6 +19,6 @@ Buffer Management:
|
|||||||
Paragraph Formatting | Miscellaneous:
|
Paragraph Formatting | Miscellaneous:
|
||||||
{-W Word-wrap paragraph | {-? This help
|
{-W Word-wrap paragraph | {-? This help
|
||||||
{-U Unwrap paragraph | [CTRL]-L Refresh screen
|
{-U Unwrap paragraph | [CTRL]-L Refresh screen
|
||||||
---------------------------------------+----------------------------------------
|
--------------+-----------+------------+----------------------------------------
|
||||||
[Cursor Up] Previous Page | [Q]uit
|
[Q]uit help | [Cursor Up] Previous |
|
||||||
---------------------------------------+---------------------------------------
|
--------------+------------------------+---------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user