mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-29 01:24:52 +03:00
parent
17eef4a7dc
commit
c8d2417646
@ -239,19 +239,23 @@ void view_commands(Context& context, NormalParams params)
|
||||
if (not cp or not context.has_window())
|
||||
return;
|
||||
|
||||
LineCount cursor_line = context.selections().main().cursor().line;
|
||||
const ByteCoord cursor = context.selections().main().cursor();
|
||||
Window& window = context.window();
|
||||
switch (tolower(*cp))
|
||||
{
|
||||
case 'v':
|
||||
case 'c':
|
||||
context.window().center_line(cursor_line);
|
||||
context.window().center_line(cursor.line);
|
||||
break;
|
||||
case 'm':
|
||||
context.window().center_column(
|
||||
context.buffer()[cursor.line].char_count_to(cursor.column));
|
||||
break;
|
||||
case 't':
|
||||
context.window().display_line_at(cursor_line, 0);
|
||||
context.window().display_line_at(cursor.line, 0);
|
||||
break;
|
||||
case 'b':
|
||||
context.window().display_line_at(cursor_line, 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, params.count));
|
||||
@ -267,7 +271,8 @@ void view_commands(Context& context, NormalParams params)
|
||||
break;
|
||||
}
|
||||
}, "view",
|
||||
"v,c: center cursor \n"
|
||||
"v,c: center cursor (vertically)\n"
|
||||
"m: center cursor (horzontally)\n"
|
||||
"t: cursor on top \n"
|
||||
"b: cursor on bottom\n"
|
||||
"h: scroll left \n"
|
||||
|
@ -40,6 +40,11 @@ Window::~Window()
|
||||
options().unregister_watcher(*this);
|
||||
}
|
||||
|
||||
void Window::scroll(LineCount offset)
|
||||
{
|
||||
m_position.line = std::max(0_line, m_position.line + offset);
|
||||
}
|
||||
|
||||
void Window::display_line_at(LineCount buffer_line, LineCount display_line)
|
||||
{
|
||||
if (display_line >= 0 or display_line < m_dimensions.line)
|
||||
@ -51,16 +56,22 @@ void Window::center_line(LineCount buffer_line)
|
||||
display_line_at(buffer_line, m_dimensions.line/2_line);
|
||||
}
|
||||
|
||||
void Window::scroll(LineCount offset)
|
||||
{
|
||||
m_position.line = std::max(0_line, m_position.line + offset);
|
||||
}
|
||||
|
||||
void Window::scroll(CharCount offset)
|
||||
{
|
||||
m_position.column = std::max(0_char, m_position.column + offset);
|
||||
}
|
||||
|
||||
void Window::display_column_at(CharCount buffer_column, CharCount display_column)
|
||||
{
|
||||
if (display_column >= 0 or display_column < m_dimensions.column)
|
||||
m_position.column = std::max(0_char, buffer_column - display_column);
|
||||
}
|
||||
|
||||
void Window::center_column(CharCount buffer_column)
|
||||
{
|
||||
display_column_at(buffer_column, m_dimensions.column/2_char);
|
||||
}
|
||||
|
||||
size_t Window::compute_hash(const Context& context) const
|
||||
{
|
||||
size_t res = hash_values(m_position, context.ui().dimensions(), context.buffer().timestamp());
|
||||
|
@ -23,10 +23,13 @@ public:
|
||||
const CharCoord& dimensions() const { return m_dimensions; }
|
||||
void set_dimensions(CharCoord dimensions);
|
||||
|
||||
void scroll(LineCount offset);
|
||||
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 center_column(CharCount buffer_column);
|
||||
void display_column_at(CharCount buffer_column, CharCount display_column);
|
||||
|
||||
const DisplayBuffer& update_display_buffer(const Context& context);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user