Commit Graph

184 Commits

Author SHA1 Message Date
Benno Schulenberg 49fb755cfc moving: get <Up> unstuck when trying to pass over a sprawling tab
This is a temporary fix.  The resultant movement is erratic and
not what is desired (which is: to stay in the same screen column
as much as possible).
2017-08-20 20:26:05 +02:00
Benno Schulenberg 24a64d37dd softwrap: properly move up and down over tabs that are split over rows
Also, move home to the first character after the tab if the current
chunk starts with a partial tab.

This fixes https://savannah.gnu.org/bugs/?51800.
Original-idea-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-08-20 20:24:58 +02:00
Benno Schulenberg 54a92614b2 tweaks: group all movement routines in corresponding pairs 2017-08-18 22:20:32 +02:00
Benno Schulenberg 86e71fa09d tweaks: specify more directly in what manner to move the viewport 2017-08-18 21:46:55 +02:00
David Lawrence Ramsey 5237a42d65 weeding: remove the unused be_clever parameter from do_home()/do_end() 2017-08-18 20:44:46 +02:00
David Lawrence Ramsey 46ccc9ba6a softwrap: improve left/right navigation across line boundaries
Using do_up() and do_end() when the user types <Left> at the start of
a line, and do_down() and do_home() when typing <Right> at line's end
can be problematic when tabs are wider than the screen, because those
functions convert indexes to columns and back again twice, thus causing
inaccuracies.  Therefore, simply adjust current and current_x directly,
and then redraw the screen.

This fixes https://savannah.gnu.org/bugs/index.php?51778.
2017-08-18 20:04:23 +02:00
Benno Schulenberg 80686bb525 tweaks: remove includes that appear to be superfluous
Without them, nano still compiles for me, with everything enabled,
even when using --enable-debug, --enable-utf8, and --with-slang.
2017-08-06 09:08:30 +02:00
David Lawrence Ramsey 8b1f283a73 moving: fix the cursor jumping back and forth with non-smooth paging
Since commit 8490f4ac, get_edge_and_target() depends on an up-to-date
current_x.  So: make sure current_x is updated when we move to the
top left of the screen to start a non-smooth PageUp or PageDown.

This fixes https://savannah.gnu.org/bugs/?51480.
2017-07-17 11:45:57 +02:00
Benno Schulenberg fbbf501f8f tweaks: rename four functions, to be more distinct 2017-07-09 21:07:38 +02:00
Benno Schulenberg 8766e7bdcb tweaks: reshuffle some things to condense the code 2017-07-07 13:07:10 +02:00
David Lawrence Ramsey a4c2eaa2e6 moving: make vertical movement account for varying chunk width
Use actual_last_column() to properly adjust the cursor if placewewant
is past the end of a softwrapped chunk.
2017-07-07 13:07:10 +02:00
David Lawrence Ramsey 8490f4acab softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge.  get_chunk() now
uses the proper formula to implement varying chunk width.

Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.

Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.

The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.

Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly).  Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt().  Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().

The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.

This fixes https://savannah.gnu.org/bugs/?49440.
2017-07-07 13:07:10 +02:00
David Lawrence Ramsey e375995d98 softwrap: add new functions for chunks of varying width
get_chunk_row() replaces the formula "column / editwincols".

get_chunk_leftedge() replaces "(column / editwincols) * editwincols".

get_last_chunk_row() replaces "strlenpt() / editwincols".

get_last_chunk_leftedge() replaces "(strlenpt() / editwincols) * editwincols".

This prepares us for any changes in those formulas, and for more such
functions later.
2017-07-07 13:07:10 +02:00
Benno Schulenberg 6971db773b tweaks: swap a comparison, to be clearer 2017-05-11 10:28:43 +02:00
Benno Schulenberg 700c5c9399 tweaks: rename a parameter, to be more imperative 2017-04-17 12:01:03 +02:00
Benno Schulenberg 754c62c5cc copyright: update the years, use ranges, and explain this usage
The interval 2013-2017 for the Free Software Foundation is valid
because in those years there were releases with changes by either
Chris or David, and the GNU maintainers guide advises to mention
a new year in all files of a package, not just in the ones that
actually changed, and be done with it for the rest of the year.
2017-04-09 12:09:23 +02:00
Benno Schulenberg 9f2c80db24 moving: when determining where we are on the screen, use placewewant
To make dynamic Home and End work properly when double-width characters
straddle a chunk boundary, use the spot where the cursor is really shown
instead of the "actual x" position of the current character, because the
latter might be on the preceding row.

This fixes https://savannah.gnu.org/bugs/?50737.
2017-04-09 11:36:39 +02:00
Benno Schulenberg 4c987bc3e0 tweaks: adjust a couple of comments 2017-04-07 21:40:33 +02:00
Benno Schulenberg 582a624998 tweaks: frob some parentheses and other things, to be more consistent 2017-03-29 19:30:37 +02:00
Benno Schulenberg c7282e8821 tweaks: reshuffle two declarations for a more consistent order 2017-03-29 10:35:11 +02:00
Benno Schulenberg 1f9a6ab336 tweaks: factor out a bit of common code 2017-03-29 10:30:41 +02:00
David Lawrence Ramsey d01756bb69 moving: determine the correct leftedge when paging up/down too
The change in commit 244a503d for the <Up> and <Down> keys
needs to be done for <PageUp> and <PageDown> too.
2017-03-28 12:32:47 +02:00
Benno Schulenberg 644fedcb61 tweaks: reshuffle some more lines and improve four comments 2017-03-28 11:24:32 +02:00
Benno Schulenberg da3a015f7d tweaks: reshuffle some lines and adjust some comments 2017-03-28 10:38:08 +02:00
Benno Schulenberg bc876ca729 moving: /do/ redraw the prior line when the viewport hasn't changed
The complementary test on current_y should only be done when doing
a scroll-only, because only then the prior line can be offscreen.

This fixes https://savannah.gnu.org/bugs/?50658.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-03-28 10:31:45 +02:00
Benno Schulenberg 9cf980700c moving: don't try to redraw lines that have gone outside the viewport
When scrolling backward, it is not just the bottom line of the screen
that doesn't need to be redrawn: also the line /before/ the top line
doesn't need a redraw.  Mutatis mutandis for scrolling forward.

This fixes https://savannah.gnu.org/bugs/?50657.
2017-03-27 19:44:21 +02:00
Benno Schulenberg 244a503ddc moving: the current chunk cannot be beyond the last chunk of a line
When determining the leftedge of the current chunk, it is not simply
the leftedge that corresponds to the placewewant, but the leftedge that
corresponds to the minimum of the placewewant and the full line span.

This fixes https://savannah.gnu.org/bugs/?50653.
2017-03-27 17:45:39 +02:00
Benno Schulenberg c277cd6e5b tweaks: reshuffle some statements, to avoid double assignments 2017-03-27 11:38:52 +02:00
David Lawrence Ramsey 384332d08c display: make PageUp/PageDown use the correct beginning of the viewport
When typing PageUp or PageDOwn in non-smooth-scrolling mode, the cursor
should be placed at the start of the top line of the edit window.  This
means that, when the line at edittop is partially scrolled offscreen,
the cursor should be placed at openfile->firstcolumn, not at zero.

This fixes https://savannah.gnu.org/bugs/?50645.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-03-27 11:19:44 +02:00
David Lawrence Ramsey 93152d3258 softwrap: account for firstcolumn when scrolling up a line
In do_up() when scroll_only is TRUE, if we're at the top of the screen
in softwrap mode, it's not enough to check that edittop is on fileage.
We also need to check that firstcolumn is zero.

In do_up() when scroll_only is FALSE, if we're at the top of the screen
in softwrap mode, current_y should be zero.  This is equivalent to how,
in do_down() when scroll_only is FALSE, current_y is (editwinrows - 1)
at the bottom of the screen in softwrap mode.  Since edittop can now
be partially scrolled off the screen even when it takes up the entire
screen, checking for edittop's being equal to openfile->current->next
there no longer applies.
2017-03-22 10:44:06 +01:00
David Lawrence Ramsey 80b3a3011b weeding: remove ensure_line_is_visible()
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.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey d0c3084eb5 softwrap: improve PageUp and PageDown's behavior with softwrapped chunks
Use go_back_chunks() and go_forward_chunks() to move a screenful of
lines or chunks up or down, instead of using special computations in
the softwrap case.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey eb647dfb44 softwrap: improve Up and Down's behavior with softwrapped chunks
Use go_back_chunks() and go_forward_chunks() in do_up() and do_down()
(instead of using a special and complicated computation in do_down())
so that they now properly move vertically to the previous/next chunk
in softwrap mode.  This also means that do_left() and do_right() will
now properly move vertically at actual line boundaries.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey 56402e7589 softwrap: improve Left and Right's behavior with softwrapped chunks
Use the new "unclever" functionality of Home and End to make do_left()
and do_right() move properly to the end of the previous chunk or to the
start of the next chunk in softwrap mode when crossing a line boundary.
(Furthermore, doing Up plus End, or Down plus Home, does all needed
screen updates, which simplifies the code.)

The do_left() and do_right() functions don't yet properly move vertically
at line boundaries, but that will be fixed once do_up() and do_down() are
updated for softwrap mode, which is forthcoming.

This fixes https://savannah.gnu.org/bugs/?49384.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey a5e106d764 tweaks: add a parameter to do_home() and do_end()
Add the parameter be_clever to both functions.  When be_clever is FALSE,
smart home and dynamic home are disabled in do_home(), and dynamic end is
disabled in do_end(), so that these functions only move to the beginning
or end of the current line or chunk.

This simple home and end functionality is needed to improve do_left()
and do_right()'s horizontal behavior with softwrapped chunks, which is
forthcoming.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey e478682c55 softwrap: improve End's behavior with softwrapped chunks
Make do_end() more useful in softwrap mode: let it move to the end of the
current chunk instead of the end of the line; only when already at the end
of a chunk, let it move to the end of the line.  This is "dynamic end".
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey bd2d0863d6 softwrap: improve Home's behavior with softwrapped lines
Make do_home() more useful in softwrap mode: let it move to the beginning
of the current chunk instead of to the beginning of the whole line; only
when already at the beginning of a chunk, let it move to the beginning of
the line.  This is called "dynamic home'.

The above rules are ignored when --smarthome is in effect and the cursor
is somewhere in the leading whitespace of a line -- then the cursor is
moved to the first non-whitespace character of the line.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey d8189703b1 tweaks: prepare for improvements to do_home() and do_end()
These improvements will eventually make do_home() and do_end() take
parameters.  Since the global function lists can hold only functions
without parameters, preemptively add do_home_void() and do_end_void(),
and make the global function lists use them.
2017-03-22 10:44:04 +01:00
David Lawrence Ramsey eb369c0e00 tweaks: rename need_horizontal_scroll() to line_needs_update()
The old name made it sound as if it didn't apply in softwrap mode.  But
it does: in softwrap mode a line needs updating  when the mark is on.
2017-03-22 10:44:04 +01:00
Benno Schulenberg 83a841cd06 tweaks: chuck some debugging stuff and some useless asserts 2017-03-01 13:56:08 +01:00
David Lawrence Ramsey f2ac20114e tweaks: adjust and correct some comments 2017-02-05 12:29:43 +01:00
Benno Schulenberg 0208ae7149 tweaks: rename a variable -- lines refers to buffer, rows to screen 2017-01-12 17:33:46 +01:00
Benno Schulenberg 58c3dd6cd0 softwrap: when typing M-/, ensure the last line is fully visible 2017-01-09 15:21:15 +01:00
David Lawrence Ramsey b1c20629f5 weeding: remove unnecessary settings of openfile->current_y
Many of the adjustments of the value of openfile->current_y appear to be
a holdover from the days when certain functions had to account for what
is now called STATIONARY scrolling mode, which depends on the value of
current_y.  Remove these adjustement where they are superfluous.

do_para_begin(), do_para_end(), and do_bracket_match() update the screen
through edit_redraw(), which uses either CENTERING or FLOWING scrolling
mode, so their setting of current_y is redundant and useless, as it will
be ignored and then overridden by the next call to reset_cursor().

findnextstr() is called by go_looking() [which calls edit_redraw(), see
above], and by do_replace_loop() and do_int_spell_fix(), which both call
edit_refresh(), which in this case only uses CENTERING scrolling mode
since focusing is TRUE.

(Additionally, the adjustments of current_y in findnextstr() and
do_bracket_match() use incorrect values when in softwrap mode.)

find_paragraph() doesn't need to save or restore current_y, because it
doesn't do any screen updates.  do_justify() calls edit_refresh() with
focusing set to TRUE, so it uses the CENTERING scrolling mode.

do_alt_speller() and do_formatter() do not need to save and restore
current_y, because they don't modify it in any way.

This addresses https://savannah.gnu.org/patch/?9197.
2017-01-02 12:40:21 +01:00
Benno Schulenberg a4044a7e5d tweaks: remove some cluttering conditional compilation 2016-12-09 13:32:15 +01:00
David Lawrence Ramsey 6263416355 moving: always account for the margin when in line numbering mode
Like do_down() does already, do_pageup() and do_right() should use
editwincols instead of COLS.

This addresses https://savannah.gnu.org/bugs/?49796.
2016-12-09 12:23:23 +01:00
Benno Schulenberg 4c476bc872 scrolling: use a comparison that will work also in softwrap mode
This fixes https://savannah.gnu.org/bugs/?49467.
2016-10-28 11:38:58 +02:00
Benno Schulenberg 5416b9c09d tweaks: remove a band-aid condition that is no longer needed
Also, don't bother conditionalizing two booleans for the tiny version.
2016-10-27 20:00:01 +02:00
Benno Schulenberg 01bbf7e82f tweaks: rename a function to better describe what it does
It does not update anything -- it just picks a new point from
where to start displaying the buffer.  All actual updating of
the screen is done by edit_refresh() and edit_redraw() and such.
2016-10-23 17:26:19 +02:00
Faissal Bensefia de95ca68f7 new feature: the ability to show line numbers before the text
It can be activated with --linenumbers on the command line or with
'set linenumbers' in a nanorc file, and it can be toggled with M-#.

Signed-off-by: Faissal Bensefia <faissaloo@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-10-20 16:47:52 +02:00