@@ -72,22 +72,38 @@ void Window::center_column(CharCount buffer_column)
72
72
display_column_at (buffer_column, m_dimensions.column /2_char);
73
73
}
74
74
75
- size_t Window::compute_hash (const Context& context) const
75
+ Window::Setup Window::build_setup (const Context& context) const
76
76
{
77
- size_t res = hash_values (m_position, context.ui ().dimensions (), context.buffer ().timestamp ());
78
-
79
- auto & selections = context.selections ();
80
- res = combine_hash (res, hash_value (selections.main_index ()));
81
- for (auto & sel : selections)
82
- res = combine_hash (res, hash_values ((const ByteCoord&)sel.cursor (), sel.anchor ()));
83
-
84
- return res;
77
+ Vector<BufferRange> selections;
78
+ for (auto & sel : context.selections ())
79
+ selections.push_back ({sel.cursor (), sel.anchor ()});
80
+
81
+ return { m_position,
82
+ context.ui ().dimensions (),
83
+ context.buffer ().timestamp (),
84
+ context.selections ().main_index (),
85
+ std::move (selections) };
85
86
}
86
87
87
88
bool Window::needs_redraw (const Context& context) const
88
89
{
89
- size_t hash = compute_hash (context);
90
- return hash != m_hash;
90
+ auto & selections = context.selections ();
91
+
92
+ if (m_position != m_last_setup.position or
93
+ context.ui ().dimensions () != m_last_setup.dimensions or
94
+ context.buffer ().timestamp () != m_last_setup.timestamp or
95
+ selections.main_index () != m_last_setup.main_selection or
96
+ selections.size () != m_last_setup.selections .size ())
97
+ return true ;
98
+
99
+ for (int i = 0 ; i < selections.size (); ++i)
100
+ {
101
+ if (selections[i].cursor () != m_last_setup.selections [i].begin or
102
+ selections[i].anchor () != m_last_setup.selections [i].end )
103
+ return true ;
104
+ }
105
+
106
+ return false ;
91
107
}
92
108
93
109
const DisplayBuffer& Window::update_display_buffer (const Context& context)
@@ -120,7 +136,7 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
120
136
line.trim (m_position.column , m_dimensions.column , true );
121
137
m_display_buffer.optimize ();
122
138
123
- m_hash = compute_hash (context);
139
+ m_last_setup = build_setup (context);
124
140
125
141
return m_display_buffer;
126
142
}
0 commit comments