Fix hooks triggering on unset-option even if parent has same value

This commit is contained in:
Maxime Coste 2018-11-28 21:45:40 +11:00
parent a7336f8663
commit 16908bf091
6 changed files with 21 additions and 2 deletions

View File

@ -80,10 +80,14 @@ const Option& OptionManager::operator[](StringView name) const
void OptionManager::unset_option(StringView name)
{
kak_assert(m_parent); // cannot unset option on global manager
if (m_options.contains(name))
auto it = m_options.find(name);
if (it != m_options.end())
{
auto& parent_option = (*m_parent)[name];
const bool changed = not parent_option.has_same_value(*it->value);
m_options.erase(name);
on_option_changed((*m_parent)[name]);
if (changed)
on_option_changed(parent_option);
}
}

View File

@ -59,6 +59,8 @@ public:
virtual void add_from_strings(ConstArrayView<String> strs) = 0;
virtual void update(const Context& context) = 0;
virtual bool has_same_value(const Option& other) const = 0;
virtual Option* clone(OptionManager& manager) const = 0;
OptionManager& manager() const { return m_manager; }
@ -167,6 +169,11 @@ public:
{
option_update(m_value, context);
}
bool has_same_value(const Option& other) const override
{
return other.is_of_type<T>() and other.get<T>() == m_value;
}
private:
virtual void validate(const T& value) const {}
T m_value;

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1,5 @@
decl str foo
hook global BufSetOption foo=.* %{ exec ifoo<esc> }
set-option buffer foo value # triggers hook
set-option global foo value # does not trigger hook
unset-option buffer foo # does not trigger hook