Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change slightly how x/X works #2595

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ public:
m_jump_list.push(selections());
}

void enter_or_keep_line_editing() const {
m_keep_line_mode = true;
}

bool is_line_editing() const {
return m_line_mode;
}

void post_movement_logic() const {
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 @@ -135,6 +148,8 @@ private:
void end_edition();
int m_edition_level = 0;
size_t m_edition_timestamp = 0;
mutable bool m_line_mode = false;
mutable bool m_keep_line_mode = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using mutable really necessary here?

Copy link
Contributor Author

@dpc dpc Nov 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of a hack/workaround that mawww threw at me, when I didn't know what to do. You can revert Is it a hack, or is it a solution? :D to see the problem, or just see the error in this commit: dpc@b8d3f08

Basically: now some functions are taking Context& some consts Context& and this big hashmap is complaining, even though it it is storing Context& in intself, so I don't get why it can't promote.


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 @@ -311,12 +311,14 @@ class Normal : public InputMode
m_params = { 0, 0 };

command->func(context(), params);
context().post_movement_logic();
}
}

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()));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove this hunk

}

DisplayLine mode_line() const override
Expand Down
14 changes: 12 additions & 2 deletions src/normal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,12 @@ class Repeated
void operator() (Context& context, NormalParams params)
{
ScopedEdition edition(context);
do { m_func(context, {0, params.reg}); } while(--params.count > 0);
do {
m_func(context, {0, params.reg});
if (params.count > 1) {
context.post_movement_logic();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The braces could be removed here, to follow the style of the rest of the code, and reduce the size of the patch. Same for the subsequent hunks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gosh. I think it's a terrible idea, but not my project, not my rules. Fixing. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would need to be fixed in subsequent hunks as well, prior to merging.

} while(--params.count > 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after a keyword, applies to the subsequent hunks as well.

}
private:
T m_func;
Expand All @@ -2011,7 +2016,12 @@ template<void (*func)(Context&, NormalParams)>
void repeated(Context& context, NormalParams params)
{
ScopedEdition edition(context);
do { func(context, {0, params.reg}); } while(--params.count > 0);
do {
func(context, {0, params.reg});
if (params.count > 1) {
context.post_movement_logic();
}
} while(--params.count > 0);
}

template<typename Type, Direction direction, SelectMode mode = SelectMode::Replace>
Expand Down
18 changes: 14 additions & 4 deletions src/selectors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,16 @@ select_line(const 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();

if (line >= buffer.line_count()) {
return Optional<Selection>();
}
return target_eol({{line, 0_byte}, {line, buffer[line].length() - 1}});
}

Expand Down Expand Up @@ -811,6 +816,8 @@ select_argument(const Context& context, const Selection& selection,
Optional<Selection>
select_lines(const 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 @@ -832,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;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this new line is necessary, there's already one on line 841.

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