Skip to content

Commit

Permalink
Change x-and-alikes to work consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
dpc committed May 25, 2019
1 parent 9ffde03 commit f4c8efa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename Func>
void set_last_select(Func&& last_select) { m_last_select = std::forward<Func>(last_select); }

Expand All @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/input_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions src/selectors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ template Optional<Selection> select_word<WordType::Word>(const Context&, const S
template Optional<Selection> select_word<WordType::WORD>(const Context&, const Selection&, int, ObjectFlags);

Optional<Selection>
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}};
}

Expand Down Expand Up @@ -812,8 +814,10 @@ select_argument(const Context& context, const Selection& selection,
}

Optional<Selection>
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();
Expand All @@ -827,14 +831,17 @@ select_lines(const Context& context, const Selection& selection)
}

Optional<Selection>
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();
BufferCoord cursor = selection.cursor();
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)
Expand Down
6 changes: 3 additions & 3 deletions src/selectors.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Optional<Selection>
select_to_previous_word(const Context& context, const Selection& selection);

Optional<Selection>
select_line(const Context& context, const Selection& selection);
select_line(Context& context, const Selection& selection);

template<bool forward>
Optional<Selection>
Expand Down Expand Up @@ -102,10 +102,10 @@ select_argument(const Context& context, const Selection& selection,
int level, ObjectFlags flags);

Optional<Selection>
select_lines(const Context& context, const Selection& selection);
select_lines(Context& context, const Selection& selection);

Optional<Selection>
trim_partial_lines(const Context& context, const Selection& selection);
trim_partial_lines(Context& context, const Selection& selection);

enum class RegexMode;

Expand Down

0 comments on commit f4c8efa

Please sign in to comment.