when doing marked spell-check, properly handle the case where the mark

ends in the middle of a word and that word is spell-checked; also move
the logic to detect an upside-down mark to mark_order() instead of using
the same logic in three different places, and rename a few variables for
consistency


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2070 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-11-05 23:03:03 +00:00
parent 93eb293fbb
commit 90e59c1a18
8 changed files with 57 additions and 21 deletions

View File

@ -279,6 +279,10 @@ CVS code -
(DLR)
mallocstrcpy()
- Refactor to be a wrapper for mallocstrncpy(). (DLR)
mark_order()
- Add new parameter right_side_up. Set it to TRUE If the mark
begins with (mark_beginbuf, mark_beginx) and ends with
(current, current_x), or FALSE otherwise. (DLR)
- winio.c:
unget_kbinput()
- New function used as a wrapper for ungetch(). (DLR)

View File

@ -105,7 +105,7 @@ void cut_marked_segment(void)
/* Set up the top and bottom lines and coordinates of the marked
* text. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x);
(const filestruct **)&bot, &bot_x, NULL);
/* Make the first cut line manually. Move the cut part of the top
* line into tmp, and set newsize to that partial line's length. */

View File

@ -1760,7 +1760,7 @@ int write_marked(const char *name, int tmp, int append)
/* Partition the filestruct so that it contains only the marked
* text. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x);
(const filestruct **)&bot, &bot_x, NULL);
filepart = partition_filestruct(top, top_x, bot, bot_x);
/* If the line at filebot is blank, treat it as the magicline and

View File

@ -1537,8 +1537,11 @@ bool do_int_spell_fix(const char *word)
#endif
#ifndef NANO_SMALL
bool old_mark_set = ISSET(MARK_ISSET);
bool right_side_up = FALSE;
/* TRUE if (mark_beginbuf, mark_beginx) is the top of the mark,
* FALSE if (current, current_x) is. */
filestruct *top, *bot;
size_t top_x, bot_x;
size_t top_x, bot_x, bot_data_len;
#endif
/* Make sure spell-check is case sensitive. */
@ -1567,7 +1570,7 @@ bool do_int_spell_fix(const char *word)
/* If the mark is on, partition the filestruct so that it
* contains only the marked text, and turn the mark off. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x);
(const filestruct **)&bot, &bot_x, &right_side_up);
filepart = partition_filestruct(top, top_x, bot, bot_x);
UNSET(MARK_ISSET);
}
@ -1614,6 +1617,16 @@ bool do_int_spell_fix(const char *word)
}
}
/* If the mark ended in the middle of a word and that word was
* spell-checked, put either current_x_save or mark_beginx,
* depending on the value of right_side_up, at the end of the
* spell-checked word. */
bot_data_len = strlen(filebot->data);
if (right_side_up)
current_x_save = bot_data_len;
else
mark_beginx = bot_data_len;
/* Restore the search/replace strings. */
free(last_search);
last_search = save_search;
@ -1843,9 +1856,9 @@ const char *do_int_speller(const char *tempfile_name)
* otherwise the error string. */
const char *do_alt_speller(char *tempfile_name)
{
int alt_spell_status, lineno_cur = current->lineno;
size_t x_cur = current_x, pww_cur = placewewant;
int y_cur = current_y;
int alt_spell_status, lineno_save = current->lineno;
size_t current_x_save = current_x, pww_save = placewewant;
int current_y_save = current_y;
pid_t pid_spell;
char *ptr;
static int arglen = 3;
@ -1855,7 +1868,10 @@ const char *do_alt_speller(char *tempfile_name)
bool old_mark_set = ISSET(MARK_ISSET);
bool added_magicline = FALSE;
/* Whether we added a magicline after filebot. */
int mbb_lineno_cur = 0;
bool right_side_up = FALSE;
/* TRUE if (mark_beginbuf, mark_beginx) is the top of the mark,
* FALSE if (current, current_x) is. */
int mbb_lineno_save = 0;
/* We're going to close the current file, and open the output of
* the alternate spell command. The line that mark_beginbuf
* points to will be freed, so we save the line number and
@ -1870,7 +1886,7 @@ const char *do_alt_speller(char *tempfile_name)
if (old_mark_set) {
/* If the mark is on, save the number of the line it starts on,
* and then turn the mark off. */
mbb_lineno_cur = mark_beginbuf->lineno;
mbb_lineno_save = mark_beginbuf->lineno;
UNSET(MARK_ISSET);
}
#endif
@ -1934,7 +1950,7 @@ const char *do_alt_speller(char *tempfile_name)
* temp file (which should contain the spell-checked marked
* text) will have a magicline added when it's reloaded. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x);
(const filestruct **)&bot, &bot_x, &right_side_up);
filepart = partition_filestruct(top, top_x, bot, bot_x);
added_magicline = (filebot->data[0] != '\0');
@ -1961,11 +1977,22 @@ const char *do_alt_speller(char *tempfile_name)
#ifndef NANO_SMALL
if (old_mark_set) {
filestruct *top_save = fileage;
size_t bot_data_len;
/* If we added a magicline, remove it now. */
if (added_magicline)
remove_magicline();
/* If the mark ended in the middle of a word and that word was
* spell-checked, put either current_x_save or mark_beginx,
* depending on the value of right_side_up, at the end of the
* spell-checked word. */
bot_data_len = strlen(filebot->data);
if (right_side_up)
current_x_save = bot_data_len;
else
mark_beginx = bot_data_len;
/* If the mark was on, unpartition the filestruct so that it
* contains all the text again. Note that we've replaced the
* marked text originally in the partition with the
@ -1985,7 +2012,7 @@ const char *do_alt_speller(char *tempfile_name)
/* Assign mark_beginbuf to the line where the mark began
* before. */
do_gotopos(mbb_lineno_cur, mark_beginx, y_cur, 0);
do_gotopos(mbb_lineno_save, mark_beginx, current_y_save, 0);
mark_beginbuf = current;
/* Assign mark_beginx to the location in mark_beginbuf where the
@ -2000,7 +2027,7 @@ const char *do_alt_speller(char *tempfile_name)
/* Go back to the old position, mark the file as modified, and make
* sure that the titlebar is refreshed. */
do_gotopos(lineno_cur, x_cur, y_cur, pww_cur);
do_gotopos(lineno_save, current_x_save, current_y_save, pww_save);
set_modified();
clearok(topwin, FALSE);
titlebar(NULL);

View File

@ -504,7 +504,7 @@ void remove_magicline(void);
void get_totals(const filestruct *begin, const filestruct *end, int
*lines, long *size);
void mark_order(const filestruct **top, size_t *top_x, const filestruct
**bot, size_t *bot_x);
**bot, size_t *bot_x, bool *right_side_up);
#endif
#ifndef DISABLE_TABCOMP
int check_wildcard_match(const char *text, const char *pattern);

View File

@ -686,12 +686,10 @@ ssize_t do_replace_loop(const char *needle, const filestruct
if (old_mark_set) {
/* If the mark is on, partition the filestruct so that it
* contains only the marked text, set right_side_up properly,
* set edittop to the top of the partition, turn the mark off,
* and refresh the screen. */
* contains only the marked text, set edittop to the top of the
* partition, turn the mark off, and refresh the screen. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x);
right_side_up = (bot == current && bot_x == current_x);
(const filestruct **)&bot, &bot_x, &right_side_up);
filepart = partition_filestruct(top, top_x, bot, bot_x);
edittop = fileage;
UNSET(MARK_ISSET);

View File

@ -493,9 +493,12 @@ void get_totals(const filestruct *begin, const filestruct *end, int
}
/* Set top_x and bot_x to the top and bottom x-coordinates of the mark,
* respectively, based on the locations of top and bot. */
* respectively, based on the locations of top and bot. If
* right_side_up isn't NULL, set it to TRUE If the mark begins with
* (mark_beginbuf, mark_beginx) and ends with (current, current_x), or
* FALSE otherwise. */
void mark_order(const filestruct **top, size_t *top_x, const filestruct
**bot, size_t *bot_x)
**bot, size_t *bot_x, bool *right_side_up)
{
assert(top != NULL && top_x != NULL && bot != NULL && bot_x != NULL);
@ -505,11 +508,15 @@ void mark_order(const filestruct **top, size_t *top_x, const filestruct
*top_x = mark_beginx;
*bot = current;
*bot_x = current_x;
if (right_side_up != NULL)
*right_side_up = TRUE;
} else {
*bot = mark_beginbuf;
*bot_x = mark_beginx;
*top = current;
*top_x = current_x;
if (right_side_up != NULL)
*right_side_up = FALSE;
}
}
#endif

View File

@ -2862,7 +2862,7 @@ void edit_add(const filestruct *fileptr, const char *converted, int
/* Number of chars to paint on this line. There are COLS
* characters on a whole line. */
mark_order(&top, &top_x, &bot, &bot_x);
mark_order(&top, &top_x, &bot, &bot_x, NULL);
if (top->lineno < fileptr->lineno || top_x < startpos)
top_x = startpos;