summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-02-03 09:51:56 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-02-03 09:51:56 +0000
commitdc3c7d593c8aa2a2946e6a852426a2a3f6b88a3c (patch)
treec83533872b54f4090238b49c055ff7f9a0e56905 /src
parent3e0e32cfbb905704f9fc8d264ece79402adddef3 (diff)
Do not use a hash to determine if a window must be redrawn
Collision happens Fixes #569
Diffstat (limited to 'src')
-rw-r--r--src/window.cc40
-rw-r--r--src/window.hh16
2 files changed, 39 insertions, 17 deletions
diff --git a/src/window.cc b/src/window.cc
index d4429407..4ebd9e2c 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -72,22 +72,38 @@ void Window::center_column(CharCount buffer_column)
display_column_at(buffer_column, m_dimensions.column/2_char);
}
-size_t Window::compute_hash(const Context& context) const
+Window::Setup Window::build_setup(const Context& context) const
{
- size_t res = hash_values(m_position, context.ui().dimensions(), context.buffer().timestamp());
-
- auto& selections = context.selections();
- res = combine_hash(res, hash_value(selections.main_index()));
- for (auto& sel : selections)
- res = combine_hash(res, hash_values((const ByteCoord&)sel.cursor(), sel.anchor()));
-
- return res;
+ Vector<BufferRange> selections;
+ for (auto& sel : context.selections())
+ selections.push_back({sel.cursor(), sel.anchor()});
+
+ return { m_position,
+ context.ui().dimensions(),
+ context.buffer().timestamp(),
+ context.selections().main_index(),
+ std::move(selections) };
}
bool Window::needs_redraw(const Context& context) const
{
- size_t hash = compute_hash(context);
- return hash != m_hash;
+ auto& selections = context.selections();
+
+ if (m_position != m_last_setup.position or
+ context.ui().dimensions() != m_last_setup.dimensions or
+ 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;
}
const DisplayBuffer& Window::update_display_buffer(const Context& context)
@@ -120,7 +136,7 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
line.trim(m_position.column, m_dimensions.column, true);
m_display_buffer.optimize();
- m_hash = compute_hash(context);
+ m_last_setup = build_setup(context);
return m_display_buffer;
}
diff --git a/src/window.hh b/src/window.hh
index fd347c79..40e0fef8 100644
--- a/src/window.hh
+++ b/src/window.hh
@@ -41,7 +41,7 @@ public:
Buffer& buffer() const { return *m_buffer; }
bool needs_redraw(const Context& context) const;
- void force_redraw() { m_hash = -1; }
+ void force_redraw() { m_last_setup = Setup{}; }
ByteCoord offset_coord(ByteCoord coord, CharCount offset);
ByteCoordAndTarget offset_coord(ByteCoordAndTarget coord, LineCount offset);
@@ -55,8 +55,6 @@ private:
void run_hook_in_own_context(StringView hook_name, StringView param);
- size_t compute_hash(const Context& context) const;
-
SafePtr<Buffer> m_buffer;
CharCoord m_position;
@@ -66,8 +64,16 @@ private:
HighlighterGroup m_highlighters;
HighlighterGroup m_builtin_highlighters;
- // hash used to determine if a redraw is necessary
- size_t m_hash = -1;
+ struct Setup
+ {
+ CharCoord position;
+ CharCoord dimensions;
+ size_t timestamp;
+ size_t main_selection;
+ Vector<BufferRange> selections;
+ };
+ Setup build_setup(const Context& context) const;
+ Setup m_last_setup;
};
}