summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-12-14 14:17:02 +0000
committerMaxime Coste <frrrwww@gmail.com>2013-12-14 14:38:17 +0000
commit6afef079b6104666e524dbae99592efc9c1b8136 (patch)
treed6e95356477f478403b0ba8603b53b705a22cb37 /src
parenteced7d4c246c007f9617d91edd5867e9e002bfc1 (diff)
Remove Editor::main_selection(|index), directly use the SelectionList method
Diffstat (limited to 'src')
-rw-r--r--src/client.cc4
-rw-r--r--src/commands.cc2
-rw-r--r--src/editor.hh5
-rw-r--r--src/highlighters.cc2
-rw-r--r--src/input_handler.cc6
-rw-r--r--src/main.cc10
-rw-r--r--src/normal.cc4
-rw-r--r--src/unit_tests.cc2
-rw-r--r--src/window.cc6
9 files changed, 18 insertions, 23 deletions
diff --git a/src/client.cc b/src/client.cc
index 09d5f89b..bdbcaf78 100644
--- a/src/client.cc
+++ b/src/client.cc
@@ -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;
diff --git a/src/commands.cc b/src/commands.cc
index bd4bd4ec..6518cc01 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -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")
diff --git a/src/editor.hh b/src/editor.hh
index f3076ad1..ac6382d8 100644
--- a/src/editor.hh
+++ b/src/editor.hh
@@ -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
diff --git a/src/highlighters.cc b/src/highlighters.cc
index a59535db..9c911ce1 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -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");
diff --git a/src/input_handler.cc b/src/input_handler.cc
index dea75944..79501e59 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -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;
diff --git a/src/main.cc b/src/main.cc
index b1feb55e..c11cd334 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -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); }
diff --git a/src/normal.cc b/src/normal.cc
index 219df354..e2bfbe03 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -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();
diff --git a/src/unit_tests.cc b/src/unit_tests.cc
index 8d7fb908..278e0501 100644
--- a/src/unit_tests.cc
+++ b/src/unit_tests.cc
@@ -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()
diff --git a/src/window.cc b/src/window.cc
index d63e6bf0..fc053bde 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -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);