Skip to content

Commit 9d8453b

Browse files
authored
chore(spellcheck): add option to toggle suggestions (Chatterino#6751)
Reviewed-by: pajlada <rasmus.karlsson@pajlada.com> Parent-PR: Chatterino#6446
1 parent a57422b commit 9d8453b

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
- Dev: Unwrapped `LimitedQueueSnapshot` to `std::vector`. (#6606)
9696
- Dev: Simplified uses of `getMessageSnapshot`. (#6607)
9797
- Dev: Disabled `llvm-prefer-static-over-anonymous-namespace` in clang-tidy. (#6610)
98-
- Dev: Added experimental spell checker support. (#6446, #6703, #6722, #6730, #6731, #6779, #6780, #6822)
98+
- Dev: Added experimental spell checker support. (#6446, #6703, #6722, #6730, #6731, #6779, #6780, #6822, #6751)
9999
- Dev: Added Clazy linting in CI. (#6623)
100100
- Dev: Added custom clang-tidy module linting in CI. (#6626)
101101
- Dev: CMake option `USE_ALTERNATE_LINKER` now errors if the given linker can't be found. (#6692)

src/singletons/Settings.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ class Settings
388388
"/behaviour/spellChecking/defaultDictionary",
389389
"",
390390
};
391+
IntSetting nSpellCheckingSuggestions = {
392+
"/behaviour/spellChecking/suggestions/count",
393+
-1,
394+
};
391395

392396
FloatSetting pauseOnHoverDuration = {"/behaviour/pauseOnHoverDuration", 0};
393397
EnumSetting<Qt::KeyboardModifier> pauseChatModifier = {

src/widgets/settingspages/ExternalToolsPage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ void ExternalToolsPage::initLayout(GeneralPageView &layout)
256256
->setTooltip("Check the spelling of words in the input box of all "
257257
"splits by default.")
258258
->addTo(layout);
259+
SettingWidget::intInput("Number of suggestions in context menu",
260+
s.nSpellCheckingSuggestions,
261+
{
262+
.min = -1,
263+
.max = std::numeric_limits<int>::max(),
264+
})
265+
->setTooltip(
266+
"When right clicking any word, show this many suggestions. If "
267+
"this is 0, no suggestions will be shown and if it's -1, no "
268+
"limit is set.")
269+
->addTo(layout);
259270

260271
auto toItem =
261272
[](const DictionaryInfo &dict) -> std::pair<QString, QVariant> {

src/widgets/splits/SplitInput.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <QSignalBlocker>
4040

4141
#include <functional>
42+
#include <ranges>
4243

4344
using namespace Qt::Literals;
4445

@@ -801,7 +802,13 @@ void SplitInput::installTextEditEvents()
801802
});
802803
menu->addAction(spellcheckAction);
803804

804-
if (!this->inputHighlighter)
805+
int nSuggestions = getSettings()->nSpellCheckingSuggestions;
806+
if (nSuggestions < 0)
807+
{
808+
nSuggestions = std::numeric_limits<int>::max();
809+
}
810+
811+
if (!this->inputHighlighter || nSuggestions == 0)
805812
{
806813
return;
807814
}
@@ -822,7 +829,8 @@ void SplitInput::installTextEditEvents()
822829

823830
auto suggestions =
824831
getApp()->getSpellChecker()->suggestions(word.toString());
825-
for (const auto &sugg : suggestions)
832+
for (const auto &sugg :
833+
suggestions | std::views::take(nSuggestions))
826834
{
827835
auto qSugg = QString::fromStdString(sugg);
828836
menu->addAction(qSugg, [this, qSugg, cursor]() mutable {

0 commit comments

Comments
 (0)