From 838ceb59588fec559b88476c6e3b89c0150ccc36 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 23 Sep 2011 14:31:15 +0000 Subject: [PATCH] Window: add selection_content method it returns the content of the last selection, or the character under the cursor if there are no selections. --- src/window.cc | 12 ++++++++++++ src/window.hh | 1 + 2 files changed, 13 insertions(+) diff --git a/src/window.cc b/src/window.cc index 4c3b87d9..d3cb630b 100644 --- a/src/window.cc +++ b/src/window.cc @@ -155,6 +155,18 @@ void Window::select(bool append, const Selector& selector) scroll_to_keep_cursor_visible_ifn(); } +BufferString Window::selection_content() const +{ + if (m_selections.empty()) + { + BufferIterator it = iterator_at(m_cursor); + return m_buffer.string(it, it+1); + } + else + return m_buffer.string(m_selections.back().begin(), + m_selections.back().end()); +} + void Window::move_cursor(const WindowCoord& offset) { move_cursor_to(m_cursor + offset); diff --git a/src/window.hh b/src/window.hh index 9dafed25..4314da8e 100644 --- a/src/window.hh +++ b/src/window.hh @@ -65,6 +65,7 @@ public: void empty_selections(); void select(bool append, const Selector& selector); + BufferString selection_content() const; void set_dimensions(const WindowCoord& dimensions);