If the number of columns in the edit window changes (which currently
only happens in two places: in regenerate_screen(), called when the
window is resized; and in main(), when line numbering mode is toggled),
the display will break if we're in softwrap mode and firstcolumn is
nonzero. This is because the column width of softwrapped chunks has
changed, and firstcolumn is no longer the starting column of a chunk,
an assumption that all code using firstcolumn relies on.
To fix this problem, add a new function, ensure_firstcolumn_is_aligned(),
to adjust firstcolumn to the starting column of the chunk it's on, and
use it when the number of columns in the edit window changes.
(Note that this function uses the simplest possible fix, and could
probably be made more sophisticated.)
Now that we can add text to the bottom right corner of the screen
without scrolling the full line onscreen, do_output() needs to refresh
the screen in that case, since it would put the cursor offscreen
otherwise. Accomplish this by borrowing logic from do_right().
We want to be able to scroll the line at edittop partially off the
screen. For this to be possible, the new variable firstcolumn stores
the starting column of the viewport -- the starting column in the line
that edittop points to.
Since firstcolumn is used by go_back_chunks() and go_forward_chunks(),
it can't be completely #ifdefed out when NANO_TINY is set, but outside
of softwrap mode it should always be zero.
Currently firstcolumn is initialized to zero, reset to zero when
toggling softwrap mode off, and reset to zero when switching buffers
while softwrap mode is off. It's otherwise unused, but its uses are
forthcoming.
Since all lines can be partially scrolled off the screen now
(except for the top line of the edit window, which is forthcoming),
ensure_line_is_visible() is no longer needed.
Use go_back_chunks() and go_forward_chunks() to move from the row
current_y is on to the row mouse_row is on. Now softwrap mode and
non-softwrap mode will behave the same way when we can scroll edittop
partially off the screen, which is forthcoming. Accordingly, remove
the call to ensure_line_is_visible(), as it no longer applies.
The old code did work, but it behaved differently between softwrap mode
(which counted down from edittop) and non-softwrap mode (which counted
up or down from current_y to take less time, and used a double loop to
keep current from going to NULL).
The new code counts up or down from current_y in both softwrap mode and
non-softwrap mode. In non-softwrap mode, it also avoids the double loop,
since go_back_chunks() and go_forward_chunks() keep the filestructs they
operate on from going to NULL.
Add its explanation as a separate paragraph.
Also: improve the argument of the --syntax option, as this is a <name>
and not merely a bundle of characters like the other <str> arguments.
The previous code only directly refreshed the screen when the margin
changed due to toggling line numbering on. When the margin changed
due to toggling it off, it would indirectly refresh via do_toggle().
When replacements are made, nothing needs to be reset any more
(it was done insufficiently anyway). Just make sure the screen
is refreshed when all is done -- this may be superfluous when
doing interactive replacements, but not when replacing all.
The setting of current_y in copy_from_filestruct() also appears to be
a holdover from the days of a more-common STATIONARY scrolling mode.
do_cut_text() uses the above function when copying text (uncutting
text again right after cutting it). Since the text is effectively
the same afterward, current_y doesn't need to change.
do_uncut_text(), however, does need current_y up to date in one case:
when uncutting a full screen or less' worth of lines, focusing will be
FALSE, and it uses edit_refresh(), so it will use STATIONARY scrolling
mode then. Take a cue from do_insertfile() and call reset_cursor() to
get an updated current_y.
(Note that the check for a full screen or less' worth of lines uses
incorrect values when in softwrap mode, but that's a separate problem.)
undo_cut(), do_redo(), and backup_lines() do not need set current_y
because they all result in edit_refresh() with focusing = TRUE, so
they do a CENTERING scroll which does not need current_y.
Since do_mouse() uses edit_redraw(), openfile->current_y will be
immediately recalculated, so there's no point in changing it now.
Use a temporary variable instead.
The value of sameline doesn't change, so it can be initialized to that.
Since i holds openfile->current_y, it should be ssize_t, not size_t.
And it's better to do the most significant part of a calculation first.
This disallows entering a verbatim ^J (0x0A) when typing text or
search terms, and disallows a verbatim ^@ (0x00) when typing a
filename. Nano beeps when the disallowed code is attempted.
This addresses https://savannah.gnu.org/bugs/?49897.
In path names and file names, 0x0A means an embedded newline and
should be shown as ^J, but in anything related to the file's data,
0x0A is an encoded NUL and should be displayed as ^@.
So... switch mode at the two main entry points into the "file system"
(reading in a file, and writing out a file), and also when drawing the
titlebar. Switch back to the default mode in the main loop.
This fixes https://savannah.gnu.org/bugs/?49893.
Most full paths are needed only temporarily and will be freed within
milliseconds. Only 'full_operating_dir' and 'backup_dir' continue to
exist for the whole current session. Any partition, too, will soon be
unpartitioned, so the extra reallocation is just a waste of time.
When wanting to debug something, it is far more useful
to temporarily insert lines like:
statusline(ALERT, "name = %i", variable);
It provides instant feedback, and it slows things down,
so you can kind of see what happens.
(The variable 'pletion_line' is not conditionalized with this option, as
it would become messy. The compiler will probably be able to elide it.)
When using --enable-tiny, it is not possible to use --enable-wordcomp,
because the word completion function uses the undo system.
Executing the 'complete_a_word' function will search from the start
of the current buffer for entire words that begin with the fragment
that is before the cursor, and will complete this fragment to the
first word that is found. Each consecutive call of 'complete_a_word'
will search for the next matching word and will complete the fragment
to that. By default the function is bound to the ^] keystroke.
Signed-off-by: Sumedh Pendurkar <sumedh.pendurkar@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>