2011-09-02 18:51:20 +02:00
|
|
|
#include "window.hh"
|
|
|
|
|
2011-09-19 23:56:29 +02:00
|
|
|
#include "assert.hh"
|
2016-07-20 09:49:04 +02:00
|
|
|
#include "clock.hh"
|
2013-04-09 20:05:40 +02:00
|
|
|
#include "context.hh"
|
2012-11-23 13:40:20 +01:00
|
|
|
#include "highlighter.hh"
|
2012-04-03 14:01:01 +02:00
|
|
|
#include "hook_manager.hh"
|
2015-06-21 20:56:23 +02:00
|
|
|
#include "input_handler.hh"
|
2016-02-27 18:23:13 +01:00
|
|
|
#include "client.hh"
|
2016-05-06 01:24:54 +02:00
|
|
|
#include "buffer_utils.hh"
|
2011-09-19 23:56:29 +02:00
|
|
|
|
2011-09-02 18:51:20 +02:00
|
|
|
#include <algorithm>
|
2011-10-04 20:49:41 +02:00
|
|
|
#include <sstream>
|
2011-09-02 18:51:20 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2013-03-01 19:15:05 +01:00
|
|
|
// Implementation in highlighters.cc
|
2014-12-02 20:56:17 +01:00
|
|
|
void highlight_selections(const Context& context, HighlightFlags flags, DisplayBuffer& display_buffer, BufferRange range);
|
|
|
|
void expand_tabulations(const Context& context, HighlightFlags flags, DisplayBuffer& display_buffer, BufferRange range);
|
|
|
|
void expand_unprintable(const Context& context, HighlightFlags flags, DisplayBuffer& display_buffer, BufferRange range);
|
2013-03-01 19:15:05 +01:00
|
|
|
|
2011-09-08 02:13:19 +02:00
|
|
|
Window::Window(Buffer& buffer)
|
2014-10-30 15:00:42 +01:00
|
|
|
: Scope(buffer),
|
|
|
|
m_buffer(&buffer)
|
2011-09-02 18:51:20 +02:00
|
|
|
{
|
2014-12-19 00:12:58 +01:00
|
|
|
run_hook_in_own_context("WinCreate", buffer.name());
|
|
|
|
|
2014-10-30 15:00:42 +01:00
|
|
|
options().register_watcher(*this);
|
2011-11-26 19:39:59 +01:00
|
|
|
|
2014-10-22 01:20:09 +02:00
|
|
|
m_builtin_highlighters.add_child({"tabulations"_str, make_simple_highlighter(expand_tabulations)});
|
|
|
|
m_builtin_highlighters.add_child({"unprintable"_str, make_simple_highlighter(expand_unprintable)});
|
|
|
|
m_builtin_highlighters.add_child({"selections"_str, make_simple_highlighter(highlight_selections)});
|
2012-06-14 15:19:38 +02:00
|
|
|
|
2014-10-30 15:00:42 +01:00
|
|
|
for (auto& option : options().flatten_options())
|
2013-03-03 17:25:40 +01:00
|
|
|
on_option_changed(*option);
|
2012-06-14 15:19:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window()
|
|
|
|
{
|
2014-12-19 00:12:58 +01:00
|
|
|
run_hook_in_own_context("WinClose", buffer().name());
|
2014-10-30 15:00:42 +01:00
|
|
|
options().unregister_watcher(*this);
|
2011-09-27 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2015-11-02 20:49:58 +01:00
|
|
|
void Window::scroll(LineCount offset)
|
|
|
|
{
|
|
|
|
m_position.line = std::max(0_line, m_position.line + offset);
|
|
|
|
}
|
|
|
|
|
2013-12-16 15:01:40 +01:00
|
|
|
void Window::display_line_at(LineCount buffer_line, LineCount display_line)
|
2013-04-11 21:01:00 +02:00
|
|
|
{
|
2013-12-16 15:01:40 +01:00
|
|
|
if (display_line >= 0 or display_line < m_dimensions.line)
|
|
|
|
m_position.line = std::max(0_line, buffer_line - display_line);
|
2013-04-11 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
2013-12-16 15:01:40 +01:00
|
|
|
void Window::center_line(LineCount buffer_line)
|
2012-08-21 20:05:56 +02:00
|
|
|
{
|
2013-12-16 15:01:40 +01:00
|
|
|
display_line_at(buffer_line, m_dimensions.line/2_line);
|
2012-08-21 20:05:56 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
void Window::scroll(ColumnCount offset)
|
2013-04-12 01:31:21 +02:00
|
|
|
{
|
2016-09-22 21:36:26 +02:00
|
|
|
m_position.column = std::max(0_col, m_position.column + offset);
|
2013-04-12 01:31:21 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
void Window::display_column_at(ColumnCount buffer_column, ColumnCount display_column)
|
2013-07-24 01:38:30 +02:00
|
|
|
{
|
2015-11-02 20:49:58 +01:00
|
|
|
if (display_column >= 0 or display_column < m_dimensions.column)
|
2016-09-22 21:36:26 +02:00
|
|
|
m_position.column = std::max(0_col, buffer_column - display_column);
|
2015-11-02 20:49:58 +01:00
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
void Window::center_column(ColumnCount buffer_column)
|
2015-11-02 20:49:58 +01:00
|
|
|
{
|
2016-09-22 21:36:26 +02:00
|
|
|
display_column_at(buffer_column, m_dimensions.column/2_col);
|
2013-07-24 01:38:30 +02:00
|
|
|
}
|
|
|
|
|
2016-02-03 10:51:56 +01:00
|
|
|
Window::Setup Window::build_setup(const Context& context) const
|
2011-09-22 16:00:04 +02:00
|
|
|
{
|
2016-02-03 10:51:56 +01:00
|
|
|
Vector<BufferRange> selections;
|
|
|
|
for (auto& sel : context.selections())
|
|
|
|
selections.push_back({sel.cursor(), sel.anchor()});
|
2015-06-21 20:56:23 +02:00
|
|
|
|
2016-05-13 21:32:53 +02:00
|
|
|
return { m_position, m_dimensions,
|
2016-02-03 10:51:56 +01:00
|
|
|
context.buffer().timestamp(),
|
|
|
|
context.selections().main_index(),
|
|
|
|
std::move(selections) };
|
2015-06-21 20:56:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::needs_redraw(const Context& context) const
|
|
|
|
{
|
2016-02-03 10:51:56 +01:00
|
|
|
auto& selections = context.selections();
|
|
|
|
|
|
|
|
if (m_position != m_last_setup.position or
|
2016-05-13 21:32:53 +02:00
|
|
|
m_dimensions != m_last_setup.dimensions or
|
2016-02-03 10:51:56 +01:00
|
|
|
context.buffer().timestamp() != m_last_setup.timestamp or
|
|
|
|
selections.main_index() != m_last_setup.main_selection or
|
|
|
|
selections.size() != m_last_setup.selections.size())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (int i = 0; i < selections.size(); ++i)
|
|
|
|
{
|
|
|
|
if (selections[i].cursor() != m_last_setup.selections[i].begin or
|
|
|
|
selections[i].anchor() != m_last_setup.selections[i].end)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-06-21 20:56:23 +02:00
|
|
|
}
|
|
|
|
|
2015-06-22 14:34:22 +02:00
|
|
|
const DisplayBuffer& Window::update_display_buffer(const Context& context)
|
2015-06-21 20:56:23 +02:00
|
|
|
{
|
2016-05-06 01:24:54 +02:00
|
|
|
const bool profile = context.options()["debug"].get<DebugFlags>() &
|
|
|
|
DebugFlags::Profile;
|
|
|
|
|
2016-07-20 09:49:04 +02:00
|
|
|
auto start_time = profile ? Clock::now() : Clock::time_point{};
|
2016-05-06 01:24:54 +02:00
|
|
|
|
2012-07-12 23:19:10 +02:00
|
|
|
DisplayBuffer::LineList& lines = m_display_buffer.lines();
|
|
|
|
lines.clear();
|
2011-09-02 18:51:20 +02:00
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
if (m_dimensions == DisplayCoord{0,0})
|
2015-06-22 14:34:22 +02:00
|
|
|
return m_display_buffer;
|
2015-06-21 20:56:23 +02:00
|
|
|
|
|
|
|
kak_assert(&buffer() == &context.buffer());
|
|
|
|
scroll_to_keep_selection_visible_ifn(context);
|
|
|
|
|
2012-08-22 23:33:52 +02:00
|
|
|
for (LineCount line = 0; line < m_dimensions.line; ++line)
|
2012-07-03 23:23:07 +02:00
|
|
|
{
|
2012-08-22 23:33:52 +02:00
|
|
|
LineCount buffer_line = m_position.line + line;
|
2012-07-03 23:23:07 +02:00
|
|
|
if (buffer_line >= buffer().line_count())
|
|
|
|
break;
|
2013-07-24 14:55:57 +02:00
|
|
|
lines.emplace_back(AtomList{ {buffer(), buffer_line, buffer_line+1} });
|
2012-07-03 23:23:07 +02:00
|
|
|
}
|
2011-09-02 18:51:20 +02:00
|
|
|
|
2012-07-12 23:51:13 +02:00
|
|
|
m_display_buffer.compute_range();
|
2014-12-02 20:56:17 +01:00
|
|
|
BufferRange range{{0,0}, buffer().end_coord()};
|
|
|
|
m_highlighters.highlight(context, HighlightFlags::Highlight, m_display_buffer, range);
|
|
|
|
m_builtin_highlighters.highlight(context, HighlightFlags::Highlight, m_display_buffer, range);
|
2013-06-28 00:03:11 +02:00
|
|
|
|
|
|
|
// cut the start of the line before m_position.column
|
|
|
|
for (auto& line : lines)
|
2015-04-23 22:11:50 +02:00
|
|
|
line.trim(m_position.column, m_dimensions.column, true);
|
2012-10-22 13:20:02 +02:00
|
|
|
m_display_buffer.optimize();
|
2012-11-05 19:54:09 +01:00
|
|
|
|
2016-02-03 10:51:56 +01:00
|
|
|
m_last_setup = build_setup(context);
|
2015-06-22 14:34:22 +02:00
|
|
|
|
2016-05-06 01:24:54 +02:00
|
|
|
if (profile and not (buffer().flags() & Buffer::Flags::Debug))
|
|
|
|
{
|
2016-07-20 09:49:04 +02:00
|
|
|
using namespace std::chrono;
|
|
|
|
auto duration = duration_cast<milliseconds>(Clock::now() - start_time);
|
2016-05-06 01:24:54 +02:00
|
|
|
write_to_debug_buffer(format("window display update for '{}' took {} ms",
|
|
|
|
buffer().display_name(), (size_t)duration.count()));
|
|
|
|
}
|
|
|
|
|
2015-06-22 14:34:22 +02:00
|
|
|
return m_display_buffer;
|
2011-09-02 18:51:20 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
void Window::set_position(DisplayCoord position)
|
2012-10-31 14:28:47 +01:00
|
|
|
{
|
|
|
|
m_position.line = std::max(0_line, position.line);
|
2016-09-22 21:36:26 +02:00
|
|
|
m_position.column = std::max(0_col, position.column);
|
2012-10-31 14:28:47 +01:00
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
void Window::set_dimensions(DisplayCoord dimensions)
|
2011-09-05 20:54:17 +02:00
|
|
|
{
|
2016-05-05 00:26:15 +02:00
|
|
|
if (m_dimensions != dimensions)
|
|
|
|
{
|
|
|
|
m_dimensions = dimensions;
|
|
|
|
run_hook_in_own_context("WinResize", format("{}.{}", dimensions.line,
|
|
|
|
dimensions.column));
|
|
|
|
}
|
2011-09-05 20:54:17 +02:00
|
|
|
}
|
|
|
|
|
2013-05-16 19:22:44 +02:00
|
|
|
static LineCount adapt_view_pos(LineCount line, LineCount offset,
|
|
|
|
LineCount view_pos, LineCount view_size,
|
|
|
|
LineCount buffer_size)
|
|
|
|
{
|
2015-07-07 23:36:27 +02:00
|
|
|
offset = std::min(offset, (view_size + 1) / 2);
|
2013-05-16 19:22:44 +02:00
|
|
|
if (line - offset < view_pos)
|
|
|
|
return std::max(0_line, line - offset);
|
|
|
|
else if (line + offset >= view_pos + view_size)
|
2015-07-08 14:43:32 +02:00
|
|
|
return std::max(0_line, line + offset - view_size + 1);
|
2013-05-16 19:22:44 +02:00
|
|
|
return view_pos;
|
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
static ColumnCount adapt_view_pos(const DisplayBuffer& display_buffer, ColumnCount offset,
|
|
|
|
BufferCoord pos, ColumnCount view_pos, ColumnCount view_size)
|
2013-07-24 01:34:00 +02:00
|
|
|
{
|
2015-07-07 23:36:27 +02:00
|
|
|
offset = std::min(offset, (view_size + 1) / 2);
|
2016-09-22 21:36:26 +02:00
|
|
|
ColumnCount buffer_column = 0;
|
|
|
|
ColumnCount non_buffer_column = 0;
|
2013-09-27 20:14:39 +02:00
|
|
|
for (auto& line : display_buffer.lines())
|
2013-07-24 01:34:00 +02:00
|
|
|
{
|
2013-09-27 20:14:39 +02:00
|
|
|
for (auto& atom : line)
|
2013-07-24 01:34:00 +02:00
|
|
|
{
|
2013-09-27 20:14:39 +02:00
|
|
|
if (atom.has_buffer_range())
|
2013-07-24 01:34:00 +02:00
|
|
|
{
|
2013-09-27 20:14:39 +02:00
|
|
|
if (atom.begin() <= pos and atom.end() > pos)
|
|
|
|
{
|
2016-09-22 21:36:26 +02:00
|
|
|
ColumnCount pos_beg, pos_end;
|
2016-10-13 20:55:15 +02:00
|
|
|
if (atom.type() == DisplayAtom::Range)
|
2014-01-21 19:52:51 +01:00
|
|
|
{
|
|
|
|
auto& buf = atom.buffer();
|
2016-07-28 10:41:47 +02:00
|
|
|
pos_beg = buffer_column +
|
2016-09-22 21:36:26 +02:00
|
|
|
column_length(buf, atom.begin(), pos);
|
2014-01-21 19:52:51 +01:00
|
|
|
pos_end = pos_beg+1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos_beg = buffer_column;
|
|
|
|
pos_end = pos_beg + atom.length();
|
|
|
|
}
|
|
|
|
|
2014-10-06 20:21:32 +02:00
|
|
|
if (pos_beg - offset < view_pos)
|
2016-09-22 21:36:26 +02:00
|
|
|
return std::max(0_col, pos_beg - offset);
|
2014-01-21 19:52:51 +01:00
|
|
|
|
2014-10-06 20:21:32 +02:00
|
|
|
if (pos_end + offset >= view_pos + view_size - non_buffer_column)
|
|
|
|
return pos_end + offset - view_size + non_buffer_column;
|
2013-09-27 20:14:39 +02:00
|
|
|
}
|
|
|
|
buffer_column += atom.length();
|
2013-07-24 01:34:00 +02:00
|
|
|
}
|
2013-09-27 20:14:39 +02:00
|
|
|
else
|
|
|
|
non_buffer_column += atom.length();
|
2013-07-24 01:34:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return view_pos;
|
|
|
|
}
|
|
|
|
|
2013-12-20 21:10:08 +01:00
|
|
|
void Window::scroll_to_keep_selection_visible_ifn(const Context& context)
|
2011-09-05 20:55:31 +02:00
|
|
|
{
|
2013-12-20 21:10:08 +01:00
|
|
|
auto& selection = context.selections().main();
|
2014-01-28 20:05:49 +01:00
|
|
|
const auto& anchor = selection.anchor();
|
|
|
|
const auto& cursor = selection.cursor();
|
2012-07-15 01:48:50 +02:00
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
const DisplayCoord offset = options()["scrolloff"].get<DisplayCoord>();
|
2013-02-12 19:01:25 +01:00
|
|
|
|
2013-05-16 19:22:44 +02:00
|
|
|
// scroll lines if needed, try to get as much of the selection visible as possible
|
2014-10-06 20:21:32 +02:00
|
|
|
m_position.line = adapt_view_pos(anchor.line, offset.line, m_position.line,
|
2013-05-16 19:22:44 +02:00
|
|
|
m_dimensions.line, buffer().line_count());
|
2014-10-06 20:21:32 +02:00
|
|
|
m_position.line = adapt_view_pos(cursor.line, offset.line, m_position.line,
|
2013-05-16 19:22:44 +02:00
|
|
|
m_dimensions.line, buffer().line_count());
|
2012-07-15 01:48:50 +02:00
|
|
|
|
|
|
|
// highlight only the line containing the cursor
|
|
|
|
DisplayBuffer display_buffer;
|
|
|
|
DisplayBuffer::LineList& lines = display_buffer.lines();
|
2014-01-28 20:05:49 +01:00
|
|
|
lines.emplace_back(AtomList{ {buffer(), cursor.line, cursor.line+1} });
|
2012-07-15 01:48:50 +02:00
|
|
|
|
|
|
|
display_buffer.compute_range();
|
2014-12-02 20:56:17 +01:00
|
|
|
BufferRange range{cursor.line, cursor.line + 1};
|
|
|
|
m_highlighters.highlight(context, HighlightFlags::MoveOnly, display_buffer, range);
|
|
|
|
m_builtin_highlighters.highlight(context, HighlightFlags::MoveOnly, display_buffer, range);
|
2012-07-15 01:48:50 +02:00
|
|
|
|
|
|
|
// now we can compute where the cursor is in display columns
|
|
|
|
// (this is only valid if highlighting one line and multiple lines put
|
|
|
|
// the cursor in the same position, however I do not find any sane example
|
|
|
|
// of highlighters not doing that)
|
2014-10-06 20:21:32 +02:00
|
|
|
m_position.column = adapt_view_pos(display_buffer, offset.column,
|
2014-01-28 20:05:49 +01:00
|
|
|
anchor.line == cursor.line ? anchor : cursor.line,
|
2013-09-27 20:14:39 +02:00
|
|
|
m_position.column, m_dimensions.column);
|
2014-10-06 20:21:32 +02:00
|
|
|
m_position.column = adapt_view_pos(display_buffer, offset.column, cursor,
|
2013-09-27 20:14:39 +02:00
|
|
|
m_position.column, m_dimensions.column);
|
2011-09-05 20:55:31 +02:00
|
|
|
}
|
|
|
|
|
2013-07-17 21:17:32 +02:00
|
|
|
namespace
|
|
|
|
{
|
2016-09-22 21:36:26 +02:00
|
|
|
ColumnCount find_display_column(const DisplayLine& line, const Buffer& buffer,
|
|
|
|
BufferCoord coord)
|
2013-07-17 21:17:32 +02:00
|
|
|
{
|
2016-09-22 21:36:26 +02:00
|
|
|
ColumnCount column = 0;
|
2013-07-17 21:17:32 +02:00
|
|
|
for (auto& atom : line)
|
|
|
|
{
|
2013-07-24 14:55:57 +02:00
|
|
|
if (atom.has_buffer_range() and
|
|
|
|
coord >= atom.begin() and coord < atom.end())
|
2013-07-17 21:17:32 +02:00
|
|
|
{
|
2016-10-13 20:55:15 +02:00
|
|
|
if (atom.type() == DisplayAtom::Range)
|
2016-09-22 21:36:26 +02:00
|
|
|
column += column_length(buffer, atom.begin(), coord);
|
2013-07-17 21:17:32 +02:00
|
|
|
return column;
|
|
|
|
}
|
2013-07-24 14:55:57 +02:00
|
|
|
column += atom.length();
|
2013-07-17 21:17:32 +02:00
|
|
|
}
|
|
|
|
return column;
|
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
BufferCoord find_buffer_coord(const DisplayLine& line, const Buffer& buffer,
|
|
|
|
ColumnCount column)
|
2013-07-17 21:17:32 +02:00
|
|
|
{
|
2013-07-23 20:11:26 +02:00
|
|
|
auto& range = line.range();
|
2013-07-17 21:17:32 +02:00
|
|
|
for (auto& atom : line)
|
|
|
|
{
|
2016-09-22 21:36:26 +02:00
|
|
|
ColumnCount len = atom.length();
|
2013-07-24 14:55:57 +02:00
|
|
|
if (atom.has_buffer_range() and column < len)
|
2013-07-17 21:17:32 +02:00
|
|
|
{
|
2016-10-13 20:55:15 +02:00
|
|
|
if (atom.type() == DisplayAtom::Range)
|
2015-08-10 00:18:26 +02:00
|
|
|
return buffer.clamp(
|
|
|
|
utf8::advance(buffer.iterator_at(atom.begin()),
|
|
|
|
buffer.iterator_at(range.end),
|
2016-09-22 21:36:26 +02:00
|
|
|
std::max(0_col, column)).coord());
|
2015-08-10 00:18:26 +02:00
|
|
|
return buffer.clamp(atom.begin());
|
2014-10-27 14:22:42 +01:00
|
|
|
}
|
2013-07-17 21:17:32 +02:00
|
|
|
column -= len;
|
|
|
|
}
|
2015-04-23 22:38:45 +02:00
|
|
|
return buffer.clamp(buffer.prev(range.end));
|
2013-07-17 21:17:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
DisplayCoord Window::display_position(BufferCoord coord) const
|
2012-09-30 16:22:03 +02:00
|
|
|
{
|
2013-07-17 21:17:32 +02:00
|
|
|
LineCount l = 0;
|
2012-09-30 16:22:03 +02:00
|
|
|
for (auto& line : m_display_buffer.lines())
|
|
|
|
{
|
2013-07-23 20:11:26 +02:00
|
|
|
auto& range = line.range();
|
2015-04-23 22:38:45 +02:00
|
|
|
if (range.begin <= coord and coord < range.end)
|
2013-07-17 21:17:32 +02:00
|
|
|
return {l, find_display_column(line, buffer(), coord)};
|
|
|
|
++l;
|
2012-09-30 16:22:03 +02:00
|
|
|
}
|
|
|
|
return { 0, 0 };
|
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
BufferCoord Window::buffer_coord(DisplayCoord coord) const
|
2015-03-19 00:40:26 +01:00
|
|
|
{
|
2015-07-22 19:38:44 +02:00
|
|
|
if (m_display_buffer.lines().empty())
|
|
|
|
return {0,0};
|
2015-03-22 11:07:26 +01:00
|
|
|
if (coord <= 0_line)
|
|
|
|
coord = {0,0};
|
|
|
|
if ((int)coord.line >= m_display_buffer.lines().size())
|
2016-09-22 21:36:26 +02:00
|
|
|
coord = DisplayCoord{(int)m_display_buffer.lines().size()-1, INT_MAX};
|
2015-03-22 11:07:26 +01:00
|
|
|
|
|
|
|
return find_buffer_coord(m_display_buffer.lines()[(int)coord.line],
|
|
|
|
buffer(), coord.column);
|
2015-03-19 00:40:26 +01:00
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
BufferCoord Window::offset_coord(BufferCoord coord, CharCount offset)
|
2013-12-15 15:14:52 +01:00
|
|
|
{
|
|
|
|
return buffer().offset_coord(coord, offset);
|
|
|
|
}
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
BufferCoordAndTarget Window::offset_coord(BufferCoordAndTarget coord, LineCount offset)
|
2013-07-17 21:17:32 +02:00
|
|
|
{
|
|
|
|
auto line = clamp(coord.line + offset, 0_line, buffer().line_count()-1);
|
|
|
|
DisplayBuffer display_buffer;
|
|
|
|
DisplayBuffer::LineList& lines = display_buffer.lines();
|
2013-07-24 14:55:57 +02:00
|
|
|
lines.emplace_back(AtomList{ {buffer(), coord.line, coord.line+1} });
|
|
|
|
lines.emplace_back(AtomList{ {buffer(), line, line+1} });
|
2013-07-17 21:17:32 +02:00
|
|
|
display_buffer.compute_range();
|
2013-12-17 00:24:08 +01:00
|
|
|
|
2014-12-02 20:56:17 +01:00
|
|
|
BufferRange range{ std::min(line, coord.line), std::max(line,coord.line)+1};
|
|
|
|
|
2014-12-19 00:12:58 +01:00
|
|
|
InputHandler input_handler{{ *m_buffer, Selection{} }, Context::Flags::Transient};
|
|
|
|
input_handler.context().set_window(*this);
|
|
|
|
m_highlighters.highlight(input_handler.context(), HighlightFlags::MoveOnly, display_buffer, range);
|
|
|
|
m_builtin_highlighters.highlight(input_handler.context(), HighlightFlags::MoveOnly, display_buffer, range);
|
2013-07-17 21:17:32 +02:00
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
ColumnCount column = coord.target == -1 ? find_display_column(lines[0], buffer(), coord) : coord.target;
|
2014-09-09 20:35:54 +02:00
|
|
|
return { find_buffer_coord(lines[1], buffer(), column), column };
|
2013-07-17 21:17:32 +02:00
|
|
|
}
|
|
|
|
|
2015-06-04 14:49:28 +02:00
|
|
|
void Window::clear_display_buffer()
|
|
|
|
{
|
|
|
|
m_display_buffer = DisplayBuffer{};
|
|
|
|
}
|
|
|
|
|
2013-03-03 17:25:40 +01:00
|
|
|
void Window::on_option_changed(const Option& option)
|
2012-06-14 15:19:38 +02:00
|
|
|
{
|
2016-05-13 21:32:53 +02:00
|
|
|
run_hook_in_own_context("WinSetOption", format("{}={}", option.name(),
|
|
|
|
option.get_as_string()));
|
2013-11-18 23:43:37 +01:00
|
|
|
// an highlighter might depend on the option, so we need to redraw
|
2015-06-21 20:56:23 +02:00
|
|
|
force_redraw();
|
2012-06-14 15:19:38 +02:00
|
|
|
}
|
|
|
|
|
2014-12-19 00:12:58 +01:00
|
|
|
|
2015-03-05 15:59:27 +01:00
|
|
|
void Window::run_hook_in_own_context(StringView hook_name, StringView param)
|
2014-12-19 00:12:58 +01:00
|
|
|
{
|
|
|
|
InputHandler hook_handler({ *m_buffer, Selection{} }, Context::Flags::Transient);
|
|
|
|
hook_handler.context().set_window(*this);
|
2016-05-09 14:48:48 +02:00
|
|
|
if (m_client)
|
|
|
|
hook_handler.context().set_client(*m_client);
|
|
|
|
|
2014-12-19 00:12:58 +01:00
|
|
|
hooks().run_hook(hook_name, param, hook_handler.context());
|
|
|
|
}
|
2011-09-02 18:51:20 +02:00
|
|
|
}
|