1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-19 09:21:30 +03:00
kakoune/src/window.hh

173 lines
4.5 KiB
C++
Raw Normal View History

2011-09-02 20:51:20 +04:00
#ifndef window_hh_INCLUDED
#define window_hh_INCLUDED
#include <functional>
2011-09-02 20:51:20 +04:00
#include "buffer.hh"
#include "dynamic_buffer_iterator.hh"
2011-09-02 20:51:20 +04:00
#include "display_buffer.hh"
#include "completion.hh"
#include "highlighter.hh"
2011-12-07 18:29:10 +04:00
#include "filter.hh"
#include "idvaluemap.hh"
2011-09-02 20:51:20 +04:00
namespace Kakoune
{
struct Selection
{
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) {}
BufferIterator begin() const;
BufferIterator end() const;
const BufferIterator& first() const { return m_first; }
const BufferIterator& last() const { return m_last; }
2011-10-27 18:22:17 +04:00
void merge_with(const Selection& selection);
BufferString capture(size_t index) const;
const CaptureList& captures() const { return m_captures; }
private:
DynamicBufferIterator m_first;
DynamicBufferIterator m_last;
CaptureList m_captures;
2011-09-02 20:51:20 +04:00
};
typedef std::vector<Selection> SelectionList;
class IncrementalInserter;
2011-09-02 20:51:20 +04:00
class Window
{
public:
typedef BufferString String;
typedef std::function<Selection (const BufferIterator&)> Selector;
typedef std::function<SelectionList (const Selection&)> MultiSelector;
2011-09-02 20:51:20 +04:00
void erase();
void insert(const String& string);
void append(const String& string);
void replace(const String& string);
2011-09-02 20:51:20 +04:00
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 20:51:20 +04:00
void move_cursor(const DisplayCoord& offset, bool append = false);
void move_cursor_to(const BufferIterator& iterator);
2011-09-02 20:51:20 +04:00
void clear_selections();
void keep_selection(int index);
2011-10-07 18:03:25 +04:00
void select(const Selector& selector, bool append = false);
void multi_select(const MultiSelector& selector);
BufferString selection_content() const;
2011-12-21 23:06:26 +04:00
const SelectionList& selections() const { return m_selections.back(); }
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();
bool undo();
bool redo();
2011-10-04 22:49:41 +04:00
std::string status_line() const;
2011-12-07 18:29:10 +04:00
struct id_not_unique : public runtime_error
{
2011-12-07 18:29:10 +04:00
id_not_unique(const std::string& id)
: runtime_error("id not unique: " + id) {}
};
void add_highlighter(HighlighterAndId&& highlighter);
void remove_highlighter(const std::string& id);
CandidateList complete_highlighterid(const std::string& prefix,
size_t cursor_pos = std::string::npos);
2011-12-07 18:29:10 +04: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 23:06:26 +04:00
void push_selections();
void pop_selections();
2011-12-07 18:29:10 +04:00
2011-09-02 20:51:20 +04:00
private:
friend class Buffer;
Window(Buffer& buffer);
Window(const Window&) = delete;
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
void erase_noundo();
void insert_noundo(const String& string);
void append_noundo(const String& string);
2011-12-21 23:06:26 +04:00
SelectionList& selections() { return m_selections.back(); }
friend class IncrementalInserter;
IncrementalInserter* m_current_inserter;
Buffer& m_buffer;
BufferCoord m_position;
DisplayCoord m_dimensions;
2011-12-21 23:06:26 +04:00
std::vector<SelectionList> m_selections;
DisplayBuffer m_display_buffer;
idvaluemap<std::string, HighlighterFunc> m_highlighters;
2011-12-07 18:29:10 +04:00
idvaluemap<std::string, FilterFunc> m_filters;
2011-09-02 20:51:20 +04: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 insert_capture(size_t index);
void erase();
void move_cursor(const DisplayCoord& offset);
private:
2011-12-07 18:29:10 +04:00
void apply(Modification&& modification) const;
Window& m_window;
};
2011-09-02 20:51:20 +04:00
}
#endif // window_hh_INCLUDED