gui: Fix invalid config being written for hotkeys with multiple actions

This commit is contained in:
Dustin Lieu 2020-10-16 16:25:05 -07:00 committed by Povilas Kanapickas
parent 8fe1df8c28
commit adc49fa066
2 changed files with 15 additions and 3 deletions

View File

@ -68,8 +68,20 @@ void Hotkey::saveSettings(QSettings& settings) const
QTextStream& operator<<(QTextStream& outStream, const Hotkey& hotkey)
{
for (int i = 0; i < hotkey.actions().size(); i++)
outStream << "\t" << hotkey.text() << " = " << hotkey.actions()[i] << endl;
// Don't write config if there are no actions
if (hotkey.actions().size() == 0) {
return outStream;
}
outStream << "\t" << hotkey.text() << " = ";
for (int i = 0; i < hotkey.actions().size(); i++) {
outStream << hotkey.actions()[i];
if (i != hotkey.actions().size() - 1) {
outStream << ", ";
}
}
outStream << "\n";
return outStream;
}

View File

@ -316,5 +316,5 @@ TEST(HotkeyToTexStreamTests, KeysMultipleAction)
}
};
ASSERT_EQ(hotkeyToStringViaTextStream(createHotkey(hotkey)),
"\tkeystroke(a+b) = keyDown(z,*)\n\tkeystroke(a+b) = switchToScreen(test_screen)\n");
"\tkeystroke(a+b) = keyDown(z,*), switchToScreen(test_screen)\n");
}