Teach up-line to cross empty lines

The line offset of a trailing newline on the commandline was computed incorrectly.
As a result, up-arrow did not work for a commandline like the one inserted by:

	commandline -i echo '' ''

Note this and the previous commit in the changelog.
This commit is contained in:
Johannes Altmanninger 2020-08-29 11:07:12 +02:00
parent ac60522373
commit cf075b4179
3 changed files with 4 additions and 3 deletions

View file

@ -106,6 +106,7 @@ New or improved bindings
- As mentioned above, new readline commands ``undo`` (Ctrl+_ or Ctrl+Z) and ``redo`` (Alt-/) can be used to revert
changes to the command line or the pager search field (#6570).
- Vi mode bindings now support ``dh``, ``dl``, ``c0``, ``cf``, ``ct``, ``cF``, ``cT``, ``ch``, ``cl``, and ``y0`` (#6648).
- Functions ``up-or-search`` and ``down-or-search`` (up-arrow and down-arrow) can cross empty lines and don't activate search mode if the search fails which makes it easier to use them to move between lines in some situations.
- The readline command ``beginning-of-history`` (Page Up) now moves to the oldest search instead of the youngest - that's ``end-of-history`` (Page Down).
- New readline command ``forward-single-char`` to move one character to the right, and if an autosuggestion is available, only take a single char from it (#7217).
- New function ``__fish_preview_current_file`` (Alt+O) opens the

View file

@ -83,7 +83,7 @@ size_t parse_util_get_offset_from_line(const wcstring &str, int line) {
if (buff[i] == L'\n') {
count++;
if (count == line) {
return (i + 1) < str.size() ? i + 1 : i;
return i + 1;
}
}
}

View file

@ -3236,8 +3236,8 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
assert(base_pos_new != static_cast<size_t>(-1) &&
base_pos_old != static_cast<size_t>(-1));
int indent_old = indents.at(base_pos_old);
int indent_new = indents.at(base_pos_new);
int indent_old = indents.at(std::min(indents.size() - 1, base_pos_old));
int indent_new = indents.at(std::min(indents.size() - 1, base_pos_new));
size_t line_offset_old = el->position() - base_pos_old;
size_t total_offset_new = parse_util_get_offset(