Remove Editor::main_selection(|index), directly use the SelectionList method

This commit is contained in:
Maxime Coste 2013-12-14 14:17:02 +00:00
parent eced7d4c24
commit 6afef079b6
9 changed files with 18 additions and 23 deletions

View File

@ -41,7 +41,7 @@ void Client::print_status(DisplayLine status_line)
DisplayLine Client::generate_mode_line() const
{
auto pos = context().editor().main_selection().last();
auto pos = context().editor().selections().main().last();
auto col = context().buffer()[pos.line].char_count_to(pos.column);
std::ostringstream oss;
@ -76,7 +76,7 @@ void Client::redraw_ifn()
static void reload_buffer(Context& context, const String& filename)
{
DisplayCoord view_pos = context.window().position();
BufferCoord cursor_pos = context.editor().main_selection().last();
BufferCoord cursor_pos = context.editor().selections().main().last();
Buffer* buf = create_buffer_from_file(filename);
if (not buf)
return;

View File

@ -671,7 +671,7 @@ void info(CommandParameters params, Context& context)
if (parser.has_option("anchor"))
{
style = MenuStyle::Inline;
const auto& sel = context.editor().main_selection();
const auto& sel = context.editor().selections().main();
auto it = sel.last();
String anchor = parser.option_value("anchor");
if (anchor == "left")

View File

@ -67,8 +67,6 @@ public:
void rotate_selections(int count) { m_selections.rotate_main(count); }
const SelectionList& selections() const { return m_selections; }
const Selection& main_selection() const { return m_selections.main(); }
size_t main_selection_index() const { return m_selections.main_index(); }
std::vector<String> selections_content() const;
bool undo();
@ -106,9 +104,6 @@ private:
Editor& m_editor;
};
void avoid_eol(const Buffer& buffer, BufferCoord& coord);
void avoid_eol(const Buffer& buffer, Range& sel);
}
#endif // editor_hh_INCLUDED

View File

@ -382,7 +382,7 @@ void highlight_selections(const Window& window, DisplayBuffer& display_buffer)
BufferCoord begin = forward ? sel.first() : buffer.char_next(sel.last());
BufferCoord end = forward ? sel.last() : buffer.char_next(sel.first());
const bool primary = (i == window.main_selection_index());
const bool primary = (i == window.selections().main_index());
if (not only_cursor)
{
ColorPair sel_colors = get_color(primary ? "PrimarySelection" : "SecondarySelection");

View File

@ -590,7 +590,7 @@ public:
if (m_current_candidate < 0)
m_current_candidate += m_matching_candidates.size();
const String& candidate = m_matching_candidates[m_current_candidate];
const auto& cursor_pos = m_context.editor().main_selection().last();
const auto& cursor_pos = m_context.editor().selections().main().last();
const auto prefix_len = buffer.distance(m_completions.begin, cursor_pos);
const auto suffix_len = std::max(0_byte, buffer.distance(cursor_pos, m_completions.end));
const auto buffer_len = buffer.byte_count();
@ -628,7 +628,7 @@ public:
for (auto& candidate : m_completions.candidates)
longest_completion = std::max(longest_completion, candidate.length());
BufferCoord cursor = m_context.editor().main_selection().last();
BufferCoord cursor = m_context.editor().selections().main().last();
BufferCoord compl_beg = m_completions.begin;
if (cursor.line == compl_beg.line and
is_in_range(cursor.column - compl_beg.column,
@ -672,7 +672,7 @@ public:
bool try_complete()
{
auto& buffer = m_context.buffer();
BufferCoord cursor_pos = m_context.editor().main_selection().last();
BufferCoord cursor_pos = m_context.editor().selections().main().last();
m_completions = (this->*complete_func)(buffer, cursor_pos);
if (not m_completions.is_valid())
return false;

View File

@ -69,7 +69,7 @@ void register_env_vars()
}, {
"selection",
[](const String& name, const Context& context)
{ const Range& sel = context.editor().main_selection();
{ const Range& sel = context.editor().selections().main();
return content(context.buffer(), sel); }
}, {
"selections",
@ -106,20 +106,20 @@ void register_env_vars()
}, {
"cursor_line",
[](const String& name, const Context& context)
{ return to_string(context.editor().main_selection().last().line + 1); }
{ return to_string(context.editor().selections().main().last().line + 1); }
}, {
"cursor_column",
[](const String& name, const Context& context)
{ return to_string(context.editor().main_selection().last().column + 1); }
{ return to_string(context.editor().selections().main().last().column + 1); }
}, {
"cursor_char_column",
[](const String& name, const Context& context)
{ auto coord = context.editor().main_selection().last();
{ auto coord = context.editor().selections().main().last();
return to_string(context.buffer()[coord.line].char_count_to(coord.column) + 1); }
}, {
"selection_desc",
[](const String& name, const Context& context)
{ auto& sel = context.editor().main_selection();
{ auto& sel = context.editor().selections().main();
auto beg = sel.min();
return to_string(beg.line + 1) + ':' + to_string(beg.column + 1) + '+' +
to_string((int)context.buffer().distance(beg, sel.max())+1); }

View File

@ -189,7 +189,7 @@ void goto_commands(Context& context, int line)
}
case 'f':
{
const Range& sel = context.editor().main_selection();
const Range& sel = context.editor().selections().main();
const Buffer& buffer = context.buffer();
String filename = content(buffer, sel);
static constexpr char forbidden[] = { '\'', '\\', '\0' };
@ -958,7 +958,7 @@ void align_indent(Context& context, int selection)
if (selection > selections.size())
throw runtime_error("invalid selection index");
if (selection == 0)
selection = editor.main_selection_index() + 1;
selection = editor.selections().main_index() + 1;
const String& line = buffer[selections[selection-1].min().line];
auto it = line.begin();

View File

@ -89,7 +89,7 @@ void test_editor()
Selection sel{ 2_line, buffer.back_coord() };
editor.select(sel, SelectMode::Replace);
editor.insert("",InsertMode::Replace);
kak_assert(not buffer.is_end(editor.main_selection().first()));
kak_assert(not buffer.is_end(editor.selections().main().first()));
}
void test_utf8()

View File

@ -46,7 +46,7 @@ void Window::display_selection_at(LineCount line)
{
if (line >= 0 or line < m_dimensions.line)
{
auto cursor_line = main_selection().last().line;
auto cursor_line = selections().main().last().line;
m_position.line = std::max(0_line, cursor_line - line);
}
}
@ -147,8 +147,8 @@ static CharCount adapt_view_pos(const DisplayBuffer& display_buffer,
void Window::scroll_to_keep_cursor_visible_ifn()
{
const auto& first = main_selection().first();
const auto& last = main_selection().last();
const auto& first = selections().main().first();
const auto& last = selections().main().last();
const LineCount offset = std::min<LineCount>(options()["scrolloff"].get<int>(),
(m_dimensions.line - 1) / 2);