1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-24 07:53:41 +03:00

Window: get rid of select_mode

This commit is contained in:
Maxime Coste 2011-10-07 14:03:25 +00:00
parent ca99a51bca
commit 12535e1099
3 changed files with 17 additions and 39 deletions

View File

@ -496,10 +496,15 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'k', [](Window& window, int count) { window.move_cursor(WindowCoord(-std::max(count,1), 0)); } },
{ 'l', [](Window& window, int count) { window.move_cursor(WindowCoord(0, std::max(count,1))); } },
{ 'H', [](Window& window, int count) { window.move_cursor(WindowCoord(0, -std::max(count,1)), true); } },
{ 'J', [](Window& window, int count) { window.move_cursor(WindowCoord( std::max(count,1), 0), true); } },
{ 'K', [](Window& window, int count) { window.move_cursor(WindowCoord(-std::max(count,1), 0), true); } },
{ 'L', [](Window& window, int count) { window.move_cursor(WindowCoord(0, std::max(count,1)), true); } },
{ 't', [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, false)); } },
{ 'f', [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, true)); } },
{ 'T', [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, false)); } },
{ 'F', [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, true)); } },
{ 'T', [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, false), true); } },
{ 'F', [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, true), true); } },
{ 'd', do_erase },
{ 'c', do_change },
@ -514,10 +519,6 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'p', do_paste<true> },
{ 'P', do_paste<false> },
{ 'v', [](Window& window, int count) { window.set_select_mode(window.select_mode() == Window::SelectMode::Append ?
Window::SelectMode::Normal : Window::SelectMode::Append); } },
{ 27, [](Window& window, int count) { window.set_select_mode(Window::SelectMode::Normal); } },
{ '%', [](Window& window, int count) { window.select([](const BufferIterator& cursor)
{ return Selection(cursor.buffer().begin(), cursor.buffer().end()-1); }); } },
@ -526,8 +527,12 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'w', [](Window& window, int count) { do { window.select(select_to_next_word); } while(--count > 0); } },
{ 'e', [](Window& window, int count) { do { window.select(select_to_next_word_end); } while(--count > 0); } },
{ 'b', [](Window& window, int count) { do { window.select(select_to_previous_word); } while(--count > 0); } },
{ 'W', [](Window& window, int count) { do { window.select(select_to_next_word, true); } while(--count > 0); } },
{ 'E', [](Window& window, int count) { do { window.select(select_to_next_word_end, true); } while(--count > 0); } },
{ 'B', [](Window& window, int count) { do { window.select(select_to_previous_word, true); } while(--count > 0); } },
{ '.', [](Window& window, int count) { do { window.select(select_line); } while(--count > 0); } },
{ 'm', [](Window& window, int count) { window.select(select_matching); } },
{ 'M', [](Window& window, int count) { window.select(select_matching, true); } },
{ '/', [](Window& window, int count) { do_search(window); } },
{ 'n', [](Window& window, int count) { do_search_next(window); } },
{ 'u', [](Window& window, int count) { do { if (not window.undo()) { print_status("nothing left to undo"); break; } } while(--count > 0); } },

View File

@ -112,7 +112,6 @@ Window::Window(Buffer& buffer)
: m_buffer(buffer),
m_position(0, 0),
m_dimensions(0, 0),
m_select_mode(SelectMode::Normal),
m_current_inserter(nullptr)
{
m_selections.push_back(Selection(buffer.begin(), buffer.begin()));
@ -229,14 +228,13 @@ void Window::clear_selections()
m_selections.back().last());
m_selections.clear();
m_selections.push_back(std::move(sel));
m_select_mode = SelectMode::Normal;
}
void Window::select(const Selector& selector)
void Window::select(const Selector& selector, bool append)
{
check_invariant();
if (m_select_mode == SelectMode::Normal)
if (not append)
{
Selection sel = selector(m_selections.back().last());
m_selections.clear();
@ -260,9 +258,9 @@ BufferString Window::selection_content() const
m_selections.back().end());
}
void Window::move_cursor(const WindowCoord& offset)
void Window::move_cursor(const WindowCoord& offset, bool append)
{
if (m_select_mode == SelectMode::Normal)
if (not append)
move_cursor_to(cursor_position() + offset);
else
{
@ -340,20 +338,6 @@ std::string Window::status_line() const
<< " -- " << m_selections.size() << " sel -- ";
if (m_current_inserter)
oss << "[Insert]";
else
{
switch (m_select_mode)
{
case SelectMode::Normal:
oss << "[Normal]";
break;
case SelectMode::Append:
oss << "[Append]";
break;
default:
assert(false);
}
}
return oss.str();
}

View File

@ -45,13 +45,6 @@ public:
typedef BufferString String;
typedef std::function<Selection (const BufferIterator&)> Selector;
enum class SelectMode
{
Normal,
Append,
LineAppend,
};
void erase();
void insert(const String& string);
void append(const String& string);
@ -67,11 +60,11 @@ public:
BufferIterator iterator_at(const WindowCoord& window_pos) const;
WindowCoord line_and_column_at(const BufferIterator& iterator) const;
void move_cursor(const WindowCoord& offset);
void move_cursor(const WindowCoord& offset, bool append = false);
void move_cursor_to(const WindowCoord& new_pos);
void clear_selections();
void select(const Selector& selector);
void select(const Selector& selector, bool append = false);
BufferString selection_content() const;
void set_dimensions(const WindowCoord& dimensions);
@ -83,9 +76,6 @@ public:
bool undo();
bool redo();
SelectMode select_mode() const { return m_select_mode; }
void set_select_mode(SelectMode select_mode) { m_select_mode = select_mode; }
std::string status_line() const;
private:
@ -106,7 +96,6 @@ private:
friend class HighlightSelections;
SelectMode m_select_mode;
Buffer& m_buffer;
BufferCoord m_position;
WindowCoord m_dimensions;