diff --git a/src/context.hh b/src/context.hh index b71e654742..f895b1275a 100644 --- a/src/context.hh +++ b/src/context.hh @@ -129,6 +129,19 @@ public: m_jump_list.push(selections()); } + void enter_or_keep_line_editing() { + m_keep_line_mode = true; + } + + bool is_line_editing() { + return m_line_mode; + } + + void post_key_logic() { + m_line_mode = m_keep_line_mode; + m_keep_line_mode = false; + } + template void set_last_select(Func&& last_select) { m_last_select = std::forward(last_select); } @@ -139,6 +152,8 @@ private: void end_edition(); int m_edition_level = 0; size_t m_edition_timestamp = 0; + bool m_line_mode = false; + bool m_keep_line_mode = false; friend struct ScopedEdition; diff --git a/src/input_handler.cc b/src/input_handler.cc index 5bda3324e9..e24c534833 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -329,6 +329,8 @@ class Normal : public InputMode context().hooks().run_hook(Hook::NormalKey, key_to_str(key), context()); if (enabled() and not transient) // The hook might have changed mode m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context())); + + context().post_key_logic(); } DisplayLine mode_line() const override diff --git a/src/selectors.cc b/src/selectors.cc index 9649c6c19f..35a4987ee6 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -174,15 +174,17 @@ template Optional select_word(const Context&, const S template Optional select_word(const Context&, const Selection&, int, ObjectFlags); Optional -select_line(const Context& context, const Selection& selection) +select_line(Context& context, const Selection& selection) { auto& buffer = context.buffer(); auto line = selection.cursor().line; // Next line if line fully selected - if (selection.anchor() <= BufferCoord{line, 0_byte} and - selection.cursor() == BufferCoord{line, buffer[line].length() - 1} and - line != buffer.line_count() - 1) + if (context.is_line_editing()) { ++line; + } + + context.enter_or_keep_line_editing(); + return Selection{{line, 0_byte}, {line, buffer[line].length() - 1, max_column}}; } @@ -812,8 +814,10 @@ select_argument(const Context& context, const Selection& selection, } Optional -select_lines(const Context& context, const Selection& selection) +select_lines(Context& context, const Selection& selection) { + context.enter_or_keep_line_editing(); + auto& buffer = context.buffer(); BufferCoord anchor = selection.anchor(); BufferCoord cursor = selection.cursor(); @@ -827,7 +831,7 @@ select_lines(const Context& context, const Selection& selection) } Optional -trim_partial_lines(const Context& context, const Selection& selection) +trim_partial_lines(Context& context, const Selection& selection) { auto& buffer = context.buffer(); BufferCoord anchor = selection.anchor(); @@ -835,6 +839,9 @@ trim_partial_lines(const Context& context, const Selection& selection) BufferCoord& to_line_start = anchor <= cursor ? anchor : cursor; BufferCoord& to_line_end = anchor <= cursor ? cursor : anchor; + + context.enter_or_keep_line_editing(); + if (to_line_start.column != 0) to_line_start = to_line_start.line+1; if (to_line_end.column != buffer[to_line_end.line].length()-1) diff --git a/src/selectors.hh b/src/selectors.hh index 7ff06a6b21..15e5216a72 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -30,7 +30,7 @@ Optional select_to_previous_word(const Context& context, const Selection& selection); Optional -select_line(const Context& context, const Selection& selection); +select_line(Context& context, const Selection& selection); template Optional @@ -102,10 +102,10 @@ select_argument(const Context& context, const Selection& selection, int level, ObjectFlags flags); Optional -select_lines(const Context& context, const Selection& selection); +select_lines(Context& context, const Selection& selection); Optional -trim_partial_lines(const Context& context, const Selection& selection); +trim_partial_lines(Context& context, const Selection& selection); enum class RegexMode;