Fix hooks triggering on unset-option even if parent has same value
This commit is contained in:
parent
a7336f8663
commit
16908bf091
|
@ -80,10 +80,14 @@ const Option& OptionManager::operator[](StringView name) const
|
||||||
void OptionManager::unset_option(StringView name)
|
void OptionManager::unset_option(StringView name)
|
||||||
{
|
{
|
||||||
kak_assert(m_parent); // cannot unset option on global manager
|
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);
|
m_options.erase(name);
|
||||||
on_option_changed((*m_parent)[name]);
|
if (changed)
|
||||||
|
on_option_changed(parent_option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,8 @@ public:
|
||||||
virtual void add_from_strings(ConstArrayView<String> strs) = 0;
|
virtual void add_from_strings(ConstArrayView<String> strs) = 0;
|
||||||
virtual void update(const Context& context) = 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;
|
virtual Option* clone(OptionManager& manager) const = 0;
|
||||||
OptionManager& manager() const { return m_manager; }
|
OptionManager& manager() const { return m_manager; }
|
||||||
|
|
||||||
|
@ -167,6 +169,11 @@ public:
|
||||||
{
|
{
|
||||||
option_update(m_value, context);
|
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:
|
private:
|
||||||
virtual void validate(const T& value) const {}
|
virtual void validate(const T& value) const {}
|
||||||
T m_value;
|
T m_value;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
|
1
test/compose/no-hook-on-unset-option-with-same-parent/in
Normal file
1
test/compose/no-hook-on-unset-option-with-same-parent/in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
foo
|
5
test/compose/no-hook-on-unset-option-with-same-parent/rc
Normal file
5
test/compose/no-hook-on-unset-option-with-same-parent/rc
Normal 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
|
Loading…
Reference in New Issue
Block a user