From 172a9fbeb6e4da5e99e89b71df6f0de60702aac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Fri, 23 Nov 2018 13:29:04 -0800 Subject: [PATCH] Change `x`-and-alikes to work consistently Issue #2590 --- src/context.hh | 15 +++++++++++++++ src/input_handler.cc | 2 ++ src/selectors.cc | 19 +++++++++++++------ src/selectors.hh | 6 +++--- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/context.hh b/src/context.hh index 728c4cadd9..54b41497bd 100644 --- a/src/context.hh +++ b/src/context.hh @@ -130,6 +130,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); } @@ -141,6 +154,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 85904e7f01..3245c06fa2 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -324,6 +324,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 b0aa83b0b4..35977506cf 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}}; } @@ -822,8 +824,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(); @@ -837,7 +841,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(); @@ -845,6 +849,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 8d85a600a0..c054c77f66 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;