Window: refactor center_selection/display_selection_at

Take the line we are intersted in as a parameter rather than getting
the main selection last char line.
This commit is contained in:
Maxime Coste 2013-12-16 14:01:40 +00:00
parent 94c9e4e99b
commit ae75594d25
4 changed files with 13 additions and 15 deletions

View File

@ -129,7 +129,7 @@ void edit(CommandParameters params, Context& context)
context.selections() = context.buffer().clamp({ line, column });
if (context.has_window())
context.window().center_selection();
context.window().center_line(context.selections().main().last().line);
}
}

View File

@ -224,7 +224,7 @@ void goto_commands(Context& context, int line)
context.push_jump();
select_coord<mode>(context.buffer(), LineCount{line - 1}, context.selections());
if (context.has_window())
context.window().center_selection();
context.window().center_line(LineCount{line-1});
}
else
{
@ -331,18 +331,19 @@ void view_commands(Context& context, int param)
if (key.modifiers != Key::Modifiers::None or not context.has_window())
return;
LineCount cursor_line = context.selections().main().last().line;
Window& window = context.window();
switch (tolower(key.key))
{
case 'v':
case 'c':
context.window().center_selection();
context.window().center_line(cursor_line);
break;
case 't':
context.window().display_selection_at(0);
context.window().display_line_at(cursor_line, 0);
break;
case 'b':
context.window().display_selection_at(window.dimensions().line-1);
context.window().display_line_at(cursor_line, window.dimensions().line-1);
break;
case 'h':
context.window().scroll(-std::max<CharCount>(1, param));

View File

@ -42,18 +42,15 @@ Window::~Window()
m_options.unregister_watcher(*this);
}
void Window::display_selection_at(LineCount line)
void Window::display_line_at(LineCount buffer_line, LineCount display_line)
{
if (line >= 0 or line < m_dimensions.line)
{
auto cursor_line = selections().main().last().line;
m_position.line = std::max(0_line, cursor_line - line);
}
if (display_line >= 0 or display_line < m_dimensions.line)
m_position.line = std::max(0_line, buffer_line - display_line);
}
void Window::center_selection()
void Window::center_line(LineCount buffer_line)
{
display_selection_at(m_dimensions.line/2_line);
display_line_at(buffer_line, m_dimensions.line/2_line);
}
void Window::scroll(LineCount offset)

View File

@ -33,8 +33,8 @@ public:
const DisplayBuffer& display_buffer() const { return m_display_buffer; }
void center_selection();
void display_selection_at(LineCount line);
void center_line(LineCount buffer_line);
void display_line_at(LineCount buffer_line, LineCount display_line);
void scroll(LineCount offset);
void scroll(CharCount offset);
void update_display_buffer();