kakoune/src/window.hh

137 lines
3.2 KiB
C++
Raw Normal View History

2011-09-02 18:51:20 +02:00
#ifndef window_hh_INCLUDED
#define window_hh_INCLUDED
#include <functional>
2011-09-02 18:51:20 +02:00
#include "buffer.hh"
#include "dynamic_buffer_iterator.hh"
2011-09-02 18:51:20 +02:00
#include "display_buffer.hh"
#include "filter.hh"
2011-09-02 18:51:20 +02:00
namespace Kakoune
{
struct Selection
{
Selection(const BufferIterator& first, const BufferIterator& last)
: m_first(first), m_last(last) {}
BufferIterator begin() const;
BufferIterator end() const;
const BufferIterator& first() const { return m_first; }
const BufferIterator& last() const { return m_last; }
2011-10-27 16:22:17 +02:00
void merge_with(const Selection& selection);
private:
DynamicBufferIterator m_first;
DynamicBufferIterator m_last;
2011-09-02 18:51:20 +02:00
};
typedef std::vector<Selection> SelectionList;
class IncrementalInserter;
2011-09-02 18:51:20 +02:00
class Window
{
public:
typedef BufferString String;
typedef std::function<Selection (const BufferIterator&)> Selector;
void erase();
void insert(const String& string);
void append(const String& string);
const BufferCoord& position() const { return m_position; }
DisplayCoord cursor_position() const;
BufferIterator cursor_iterator() const;
Buffer& buffer() const { return m_buffer; }
BufferIterator iterator_at(const DisplayCoord& window_pos) const;
DisplayCoord line_and_column_at(const BufferIterator& iterator) const;
2011-09-02 18:51:20 +02:00
void move_cursor(const DisplayCoord& offset, bool append = false);
void move_cursor_to(const BufferIterator& iterator);
2011-09-02 18:51:20 +02:00
void clear_selections();
2011-10-07 16:03:25 +02:00
void select(const Selector& selector, bool append = false);
BufferString selection_content() const;
2011-11-10 00:56:22 +01:00
const SelectionList selections() const { return m_selections; }
void set_dimensions(const DisplayCoord& dimensions);
2011-09-02 18:51:20 +02:00
const DisplayBuffer& display_buffer() const { return m_display_buffer; }
void update_display_buffer();
bool undo();
bool redo();
2011-10-04 20:49:41 +02:00
std::string status_line() const;
struct filter_id_not_unique : public runtime_error
{
filter_id_not_unique(const std::string& id)
: runtime_error("filter id not unique: " + id) {}
};
void add_filter(FilterAndId&& filter);
void remove_filter(const std::string& id);
2011-09-02 18:51:20 +02:00
private:
friend class Buffer;
Window(Buffer& buffer);
Window(const Window&) = delete;
void check_invariant() const;
2011-09-05 20:55:31 +02:00
void scroll_to_keep_cursor_visible_ifn();
2011-09-02 18:51:20 +02:00
void erase_noundo();
void insert_noundo(const String& string);
void append_noundo(const String& string);
friend class IncrementalInserter;
IncrementalInserter* m_current_inserter;
Buffer& m_buffer;
BufferCoord m_position;
DisplayCoord m_dimensions;
SelectionList m_selections;
DisplayBuffer m_display_buffer;
typedef std::vector<FilterAndId> FilterList;
FilterList m_filters;
2011-09-02 18:51:20 +02:00
};
class IncrementalInserter
{
public:
enum class Mode
{
Insert,
Append,
Change,
InsertAtLineBegin,
AppendAtLineEnd,
OpenLineBelow,
OpenLineAbove
};
IncrementalInserter(Window& window, Mode mode = Mode::Insert);
~IncrementalInserter();
void insert(const Window::String& string);
void erase();
void move_cursor(const DisplayCoord& offset);
private:
Window& m_window;
};
2011-09-02 18:51:20 +02:00
}
#endif // window_hh_INCLUDED