2011-09-02 20:51:20 +04:00
|
|
|
#ifndef window_hh_INCLUDED
|
|
|
|
#define window_hh_INCLUDED
|
|
|
|
|
|
|
|
#include <functional>
|
2011-09-05 23:06:31 +04:00
|
|
|
|
2011-09-02 20:51:20 +04:00
|
|
|
#include "buffer.hh"
|
2011-10-24 18:26:21 +04:00
|
|
|
#include "dynamic_buffer_iterator.hh"
|
2011-09-02 20:51:20 +04:00
|
|
|
#include "display_buffer.hh"
|
2011-11-12 18:15:35 +04:00
|
|
|
#include "completion.hh"
|
2011-11-08 18:29:52 +04:00
|
|
|
#include "filter.hh"
|
2011-09-02 20:51:20 +04:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct Selection
|
|
|
|
{
|
2011-09-23 13:17:19 +04:00
|
|
|
Selection(const BufferIterator& first, const BufferIterator& last)
|
|
|
|
: m_first(first), m_last(last) {}
|
2011-09-17 18:57:35 +04:00
|
|
|
|
2011-09-23 13:17:19 +04:00
|
|
|
BufferIterator begin() const;
|
|
|
|
BufferIterator end() const;
|
2011-09-17 18:57:35 +04:00
|
|
|
|
2011-09-23 13:17:19 +04:00
|
|
|
const BufferIterator& first() const { return m_first; }
|
|
|
|
const BufferIterator& last() const { return m_last; }
|
2011-09-17 18:57:35 +04:00
|
|
|
|
2011-10-27 18:22:17 +04:00
|
|
|
void merge_with(const Selection& selection);
|
2011-09-17 18:57:35 +04:00
|
|
|
|
|
|
|
private:
|
2011-10-24 18:26:21 +04:00
|
|
|
DynamicBufferIterator m_first;
|
|
|
|
DynamicBufferIterator m_last;
|
2011-09-02 20:51:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Selection> SelectionList;
|
|
|
|
|
2011-09-20 01:56:29 +04:00
|
|
|
class IncrementalInserter;
|
|
|
|
|
2011-09-02 20:51:20 +04: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);
|
|
|
|
|
2011-09-05 23:06:31 +04:00
|
|
|
const BufferCoord& position() const { return m_position; }
|
2011-10-15 08:45:49 +04:00
|
|
|
DisplayCoord cursor_position() const;
|
|
|
|
BufferIterator cursor_iterator() const;
|
2011-09-05 22:54:17 +04:00
|
|
|
|
2011-09-08 04:13:19 +04:00
|
|
|
Buffer& buffer() const { return m_buffer; }
|
2011-09-05 22:54:17 +04:00
|
|
|
|
2011-10-14 18:29:53 +04:00
|
|
|
BufferIterator iterator_at(const DisplayCoord& window_pos) const;
|
|
|
|
DisplayCoord line_and_column_at(const BufferIterator& iterator) const;
|
2011-09-02 20:51:20 +04:00
|
|
|
|
2011-10-14 18:29:53 +04:00
|
|
|
void move_cursor(const DisplayCoord& offset, bool append = false);
|
2011-10-12 22:53:38 +04:00
|
|
|
void move_cursor_to(const BufferIterator& iterator);
|
2011-09-02 20:51:20 +04:00
|
|
|
|
2011-10-05 18:24:52 +04:00
|
|
|
void clear_selections();
|
2011-10-07 18:03:25 +04:00
|
|
|
void select(const Selector& selector, bool append = false);
|
2011-09-23 18:31:15 +04:00
|
|
|
BufferString selection_content() const;
|
2011-11-10 03:56:22 +04:00
|
|
|
const SelectionList selections() const { return m_selections; }
|
2011-09-05 22:54:17 +04:00
|
|
|
|
2011-10-14 18:29:53 +04:00
|
|
|
void set_dimensions(const DisplayCoord& dimensions);
|
2011-09-02 20:51:20 +04:00
|
|
|
|
|
|
|
const DisplayBuffer& display_buffer() const { return m_display_buffer; }
|
|
|
|
|
|
|
|
void update_display_buffer();
|
2011-09-05 22:54:17 +04:00
|
|
|
|
2011-09-06 22:52:52 +04:00
|
|
|
bool undo();
|
|
|
|
bool redo();
|
|
|
|
|
2011-10-04 22:49:41 +04:00
|
|
|
std::string status_line() const;
|
|
|
|
|
2011-11-08 18:29:52 +04:00
|
|
|
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-11-12 18:15:35 +04:00
|
|
|
CandidateList complete_filterid(const std::string& prefix,
|
|
|
|
size_t cursor_pos = std::string::npos);
|
|
|
|
|
2011-09-02 20:51:20 +04:00
|
|
|
private:
|
2011-09-08 18:30:36 +04:00
|
|
|
friend class Buffer;
|
|
|
|
|
|
|
|
Window(Buffer& buffer);
|
|
|
|
Window(const Window&) = delete;
|
|
|
|
|
2011-09-27 22:45:22 +04:00
|
|
|
void check_invariant() const;
|
2011-09-05 22:55:31 +04:00
|
|
|
void scroll_to_keep_cursor_visible_ifn();
|
2011-09-02 20:51:20 +04:00
|
|
|
|
2011-09-27 22:45:22 +04:00
|
|
|
void erase_noundo();
|
|
|
|
void insert_noundo(const String& string);
|
|
|
|
void append_noundo(const String& string);
|
|
|
|
|
2011-09-20 01:56:29 +04:00
|
|
|
friend class IncrementalInserter;
|
|
|
|
IncrementalInserter* m_current_inserter;
|
|
|
|
|
2011-09-08 04:13:19 +04:00
|
|
|
Buffer& m_buffer;
|
|
|
|
BufferCoord m_position;
|
2011-10-14 18:29:53 +04:00
|
|
|
DisplayCoord m_dimensions;
|
2011-09-08 04:13:19 +04:00
|
|
|
SelectionList m_selections;
|
|
|
|
DisplayBuffer m_display_buffer;
|
2011-09-29 00:54:11 +04:00
|
|
|
|
2011-11-08 18:29:52 +04:00
|
|
|
typedef std::vector<FilterAndId> FilterList;
|
2011-09-29 00:54:11 +04:00
|
|
|
FilterList m_filters;
|
2011-09-02 20:51:20 +04:00
|
|
|
};
|
|
|
|
|
2011-09-20 01:56:29 +04:00
|
|
|
class IncrementalInserter
|
|
|
|
{
|
|
|
|
public:
|
2011-09-28 23:14:39 +04:00
|
|
|
enum class Mode
|
|
|
|
{
|
|
|
|
Insert,
|
|
|
|
Append,
|
2011-10-07 01:12:55 +04:00
|
|
|
Change,
|
2011-11-03 00:03:41 +04:00
|
|
|
InsertAtLineBegin,
|
|
|
|
AppendAtLineEnd,
|
2011-10-07 01:12:55 +04:00
|
|
|
OpenLineBelow,
|
|
|
|
OpenLineAbove
|
2011-09-28 23:14:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
IncrementalInserter(Window& window, Mode mode = Mode::Insert);
|
2011-09-20 01:56:29 +04:00
|
|
|
~IncrementalInserter();
|
|
|
|
|
|
|
|
void insert(const Window::String& string);
|
|
|
|
void erase();
|
2011-10-14 18:29:53 +04:00
|
|
|
void move_cursor(const DisplayCoord& offset);
|
2011-09-20 01:56:29 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
Window& m_window;
|
|
|
|
};
|
|
|
|
|
2011-09-02 20:51:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // window_hh_INCLUDED
|