Prompt handles scrolling in the line being edited
This commit is contained in:
parent
209a4a3ddf
commit
d2a1c5ce46
|
@ -165,19 +165,25 @@ public:
|
||||||
const String& line() const { return m_line; }
|
const String& line() const { return m_line; }
|
||||||
CharCount cursor_pos() const { return m_cursor_pos; }
|
CharCount cursor_pos() const { return m_cursor_pos; }
|
||||||
|
|
||||||
DisplayLine build_display_line() const
|
DisplayLine build_display_line(CharCount width)
|
||||||
{
|
{
|
||||||
kak_assert(m_cursor_pos <= m_line.char_length());
|
kak_assert(m_cursor_pos <= m_line.char_length());
|
||||||
|
if (m_cursor_pos < m_display_pos)
|
||||||
|
m_display_pos = m_cursor_pos;
|
||||||
|
if (m_cursor_pos >= m_display_pos + width)
|
||||||
|
m_display_pos = m_cursor_pos + 1 - width;
|
||||||
|
|
||||||
if (m_cursor_pos == m_line.char_length())
|
if (m_cursor_pos == m_line.char_length())
|
||||||
return DisplayLine{{ {m_line, get_color("StatusLine")},
|
return DisplayLine{{ {m_line.substr(m_display_pos, width-1), get_color("StatusLine")},
|
||||||
{" "_str, get_color("StatusCursor")} }};
|
{" "_str, get_color("StatusCursor")} }};
|
||||||
else
|
else
|
||||||
return DisplayLine({ { m_line.substr(0, m_cursor_pos), get_color("StatusLine") },
|
return DisplayLine({ { m_line.substr(m_display_pos, m_cursor_pos - m_display_pos), get_color("StatusLine") },
|
||||||
{ m_line.substr(m_cursor_pos, 1), get_color("StatusCursor") },
|
{ m_line.substr(m_cursor_pos,1), get_color("StatusCursor") },
|
||||||
{ m_line.substr(m_cursor_pos+1), get_color("StatusLine") } });
|
{ m_line.substr(m_cursor_pos+1, width - m_cursor_pos + m_display_pos - 1), get_color("StatusLine") } });
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
CharCount m_cursor_pos = 0;
|
CharCount m_cursor_pos = 0;
|
||||||
|
CharCount m_display_pos = 0;
|
||||||
String m_line;
|
String m_line;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -265,10 +271,12 @@ public:
|
||||||
select(it);
|
select(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_edit_filter)
|
if (m_edit_filter and context().has_ui())
|
||||||
{
|
{
|
||||||
auto display_line = m_filter_editor.build_display_line();
|
auto prompt = "filter:"_str;
|
||||||
display_line.insert(display_line.begin(), { "filter:"_str, get_color("Prompt") });
|
auto width = context().ui().dimensions().column - prompt.char_length();
|
||||||
|
auto display_line = m_filter_editor.build_display_line(width);
|
||||||
|
display_line.insert(display_line.begin(), { prompt, get_color("Prompt") });
|
||||||
context().print_status(display_line);
|
context().print_status(display_line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -535,9 +543,13 @@ private:
|
||||||
context().ui().menu_hide();
|
context().ui().menu_hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void display() const
|
void display()
|
||||||
{
|
{
|
||||||
auto display_line = m_line_editor.build_display_line();
|
if (not context().has_ui())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto width = context().ui().dimensions().column - m_prompt.char_length();
|
||||||
|
auto display_line = m_line_editor.build_display_line(width);
|
||||||
display_line.insert(display_line.begin(), { m_prompt, m_prompt_colors });
|
display_line.insert(display_line.begin(), { m_prompt, m_prompt_colors });
|
||||||
context().print_status(display_line);
|
context().print_status(display_line);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user