2011-09-02 18:51:20 +02:00
|
|
|
#ifndef window_hh_INCLUDED
|
|
|
|
#define window_hh_INCLUDED
|
|
|
|
|
|
|
|
#include <functional>
|
2011-09-05 21:06:31 +02:00
|
|
|
|
2011-09-02 18:51:20 +02:00
|
|
|
#include "buffer.hh"
|
2011-10-24 16:26:21 +02:00
|
|
|
#include "dynamic_buffer_iterator.hh"
|
2011-09-02 18:51:20 +02:00
|
|
|
#include "display_buffer.hh"
|
2011-11-12 15:15:35 +01:00
|
|
|
#include "completion.hh"
|
2011-11-29 23:37:20 +01:00
|
|
|
#include "highlighter.hh"
|
2012-01-19 21:37:29 +01:00
|
|
|
#include "highlighter_group.hh"
|
2011-12-07 15:29:10 +01:00
|
|
|
#include "filter.hh"
|
2011-12-02 15:20:11 +01:00
|
|
|
#include "idvaluemap.hh"
|
2012-01-23 14:57:24 +01:00
|
|
|
#include "hooks_manager.hh"
|
2011-09-02 18:51:20 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct Selection
|
|
|
|
{
|
2011-11-16 20:23:09 +01:00
|
|
|
typedef std::vector<BufferString> CaptureList;
|
|
|
|
|
|
|
|
Selection(const BufferIterator& first, const BufferIterator& last,
|
|
|
|
const CaptureList& captures = CaptureList())
|
|
|
|
: m_first(first), m_last(last), m_captures(captures) {}
|
|
|
|
|
|
|
|
Selection(const BufferIterator& first, const BufferIterator& last,
|
|
|
|
CaptureList&& captures)
|
|
|
|
: m_first(first), m_last(last), m_captures(captures) {}
|
2011-09-17 16:57:35 +02:00
|
|
|
|
2011-09-23 11:17:19 +02:00
|
|
|
BufferIterator begin() const;
|
|
|
|
BufferIterator end() const;
|
2011-09-17 16:57:35 +02:00
|
|
|
|
2011-09-23 11:17:19 +02:00
|
|
|
const BufferIterator& first() const { return m_first; }
|
|
|
|
const BufferIterator& last() const { return m_last; }
|
2011-09-17 16:57:35 +02:00
|
|
|
|
2011-10-27 16:22:17 +02:00
|
|
|
void merge_with(const Selection& selection);
|
2011-09-17 16:57:35 +02:00
|
|
|
|
2011-11-16 20:23:09 +01:00
|
|
|
BufferString capture(size_t index) const;
|
|
|
|
const CaptureList& captures() const { return m_captures; }
|
|
|
|
|
2011-09-17 16:57:35 +02:00
|
|
|
private:
|
2011-10-24 16:26:21 +02:00
|
|
|
DynamicBufferIterator m_first;
|
|
|
|
DynamicBufferIterator m_last;
|
2011-11-16 20:23:09 +01:00
|
|
|
|
|
|
|
CaptureList m_captures;
|
2011-09-02 18:51:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Selection> SelectionList;
|
|
|
|
|
2011-09-19 23:56:29 +02:00
|
|
|
class IncrementalInserter;
|
2012-01-15 14:46:12 +01:00
|
|
|
class HighlighterGroup;
|
2011-09-19 23:56:29 +02:00
|
|
|
|
2012-01-11 15:21:58 +01:00
|
|
|
// A Window is an editing view onto a Buffer
|
|
|
|
//
|
|
|
|
// The Window class manage a set of selections and provides means to modify
|
|
|
|
// both the selections and the buffer. It also handle the display of the
|
|
|
|
// buffer with it's highlighters.
|
2011-09-02 18:51:20 +02:00
|
|
|
class Window
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef BufferString String;
|
|
|
|
typedef std::function<Selection (const BufferIterator&)> Selector;
|
2011-11-16 15:04:45 +01:00
|
|
|
typedef std::function<SelectionList (const Selection&)> MultiSelector;
|
2011-09-02 18:51:20 +02:00
|
|
|
|
|
|
|
void erase();
|
|
|
|
void insert(const String& string);
|
|
|
|
void append(const String& string);
|
2011-11-22 15:23:46 +01:00
|
|
|
void replace(const String& string);
|
2011-09-02 18:51:20 +02:00
|
|
|
|
2011-09-05 21:06:31 +02:00
|
|
|
const BufferCoord& position() const { return m_position; }
|
2011-10-15 06:45:49 +02:00
|
|
|
DisplayCoord cursor_position() const;
|
|
|
|
BufferIterator cursor_iterator() const;
|
2011-09-05 20:54:17 +02:00
|
|
|
|
2011-09-08 02:13:19 +02:00
|
|
|
Buffer& buffer() const { return m_buffer; }
|
2011-09-05 20:54:17 +02:00
|
|
|
|
2011-10-14 16:29:53 +02:00
|
|
|
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
|
|
|
|
2011-10-14 16:29:53 +02:00
|
|
|
void move_cursor(const DisplayCoord& offset, bool append = false);
|
2011-10-12 20:53:38 +02:00
|
|
|
void move_cursor_to(const BufferIterator& iterator);
|
2011-09-02 18:51:20 +02:00
|
|
|
|
2011-10-05 16:24:52 +02:00
|
|
|
void clear_selections();
|
2012-01-09 15:28:01 +01:00
|
|
|
void keep_selection(int index);
|
2011-10-07 16:03:25 +02:00
|
|
|
void select(const Selector& selector, bool append = false);
|
2011-11-16 15:04:45 +01:00
|
|
|
void multi_select(const MultiSelector& selector);
|
2011-09-23 16:31:15 +02:00
|
|
|
BufferString selection_content() const;
|
2011-12-21 20:06:26 +01:00
|
|
|
const SelectionList& selections() const { return m_selections.back(); }
|
2011-09-05 20:54:17 +02:00
|
|
|
|
2011-10-14 16:29:53 +02:00
|
|
|
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();
|
2011-09-05 20:54:17 +02:00
|
|
|
|
2011-09-06 20:52:52 +02:00
|
|
|
bool undo();
|
|
|
|
bool redo();
|
|
|
|
|
2011-10-04 20:49:41 +02:00
|
|
|
std::string status_line() const;
|
|
|
|
|
2011-12-07 15:29:10 +01:00
|
|
|
struct id_not_unique : public runtime_error
|
2011-11-08 15:29:52 +01:00
|
|
|
{
|
2011-12-07 15:29:10 +01:00
|
|
|
id_not_unique(const std::string& id)
|
|
|
|
: runtime_error("id not unique: " + id) {}
|
2011-11-08 15:29:52 +01:00
|
|
|
};
|
|
|
|
|
2012-01-19 21:37:29 +01:00
|
|
|
HighlighterGroup& highlighters() { return m_highlighters; }
|
2011-11-12 15:15:35 +01:00
|
|
|
|
2011-12-07 15:29:10 +01:00
|
|
|
void add_filter(FilterAndId&& filter);
|
|
|
|
void remove_filter(const std::string& id);
|
|
|
|
|
|
|
|
CandidateList complete_filterid(const std::string& prefix,
|
|
|
|
size_t cursor_pos = std::string::npos);
|
|
|
|
|
2011-12-21 20:06:26 +01:00
|
|
|
void push_selections();
|
|
|
|
void pop_selections();
|
2011-12-07 15:29:10 +01:00
|
|
|
|
2012-01-23 14:57:24 +01:00
|
|
|
HooksManager& hooks_manager() { return m_hooks_manager; }
|
|
|
|
|
2011-09-02 18:51:20 +02:00
|
|
|
private:
|
2011-09-08 16:30:36 +02:00
|
|
|
friend class Buffer;
|
|
|
|
|
|
|
|
Window(Buffer& buffer);
|
|
|
|
Window(const Window&) = delete;
|
|
|
|
|
2011-09-27 20:45:22 +02:00
|
|
|
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
|
|
|
|
2011-09-27 20:45:22 +02:00
|
|
|
void erase_noundo();
|
|
|
|
void insert_noundo(const String& string);
|
|
|
|
void append_noundo(const String& string);
|
|
|
|
|
2011-12-21 20:06:26 +01:00
|
|
|
SelectionList& selections() { return m_selections.back(); }
|
|
|
|
|
2011-09-19 23:56:29 +02:00
|
|
|
friend class IncrementalInserter;
|
|
|
|
IncrementalInserter* m_current_inserter;
|
|
|
|
|
2011-09-08 02:13:19 +02:00
|
|
|
Buffer& m_buffer;
|
|
|
|
BufferCoord m_position;
|
2011-10-14 16:29:53 +02:00
|
|
|
DisplayCoord m_dimensions;
|
2011-12-21 20:06:26 +01:00
|
|
|
std::vector<SelectionList> m_selections;
|
2011-09-08 02:13:19 +02:00
|
|
|
DisplayBuffer m_display_buffer;
|
2011-09-28 22:54:11 +02:00
|
|
|
|
2012-01-19 21:37:29 +01:00
|
|
|
HighlighterGroup m_highlighters;
|
2011-12-07 15:29:10 +01:00
|
|
|
idvaluemap<std::string, FilterFunc> m_filters;
|
2012-01-23 14:57:24 +01:00
|
|
|
|
|
|
|
HooksManager m_hooks_manager;
|
2011-09-02 18:51:20 +02:00
|
|
|
};
|
|
|
|
|
2011-09-19 23:56:29 +02:00
|
|
|
class IncrementalInserter
|
|
|
|
{
|
|
|
|
public:
|
2011-09-28 21:14:39 +02:00
|
|
|
enum class Mode
|
|
|
|
{
|
|
|
|
Insert,
|
|
|
|
Append,
|
2011-10-06 23:12:55 +02:00
|
|
|
Change,
|
2011-11-02 21:03:41 +01:00
|
|
|
InsertAtLineBegin,
|
|
|
|
AppendAtLineEnd,
|
2011-10-06 23:12:55 +02:00
|
|
|
OpenLineBelow,
|
|
|
|
OpenLineAbove
|
2011-09-28 21:14:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
IncrementalInserter(Window& window, Mode mode = Mode::Insert);
|
2011-09-19 23:56:29 +02:00
|
|
|
~IncrementalInserter();
|
|
|
|
|
|
|
|
void insert(const Window::String& string);
|
2011-11-16 20:24:37 +01:00
|
|
|
void insert_capture(size_t index);
|
2011-09-19 23:56:29 +02:00
|
|
|
void erase();
|
2011-10-14 16:29:53 +02:00
|
|
|
void move_cursor(const DisplayCoord& offset);
|
2011-09-19 23:56:29 +02:00
|
|
|
|
|
|
|
private:
|
2011-12-07 15:29:10 +01:00
|
|
|
void apply(Modification&& modification) const;
|
|
|
|
|
|
|
|
Window& m_window;
|
2011-09-19 23:56:29 +02:00
|
|
|
};
|
|
|
|
|
2011-09-02 18:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // window_hh_INCLUDED
|