Skip to content

Commit

Permalink
support spell check (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok authored May 9, 2021
1 parent 8955afa commit 6dbc688
Show file tree
Hide file tree
Showing 34 changed files with 50,154 additions and 151 deletions.
2 changes: 1 addition & 1 deletion libs/vtextedit
Submodule vtextedit updated 46 files
+6 −0 .gitmodules
+13 −0 demo/data/example_files/example.txt
+1 −0 demo/data/example_files/example_files.qrc
+5 −0 demo/helper.h
+44 −8 demo/main.cpp
+ src/editor/data/translations/vtextedit_zh_CN.qm
+43 −0 src/editor/data/translations/vtextedit_zh_CN.ts
+4 −22 src/editor/editor.pro
+3 −0 src/editor/include/include.pri
+22 −0 src/editor/include/vtextedit/blocksegment.h
+2 −2 src/editor/include/vtextedit/pegmarkdownhighlighter.h
+67 −0 src/editor/include/vtextedit/spellchecker.h
+7 −0 src/editor/include/vtextedit/textblockdata.h
+12 −3 src/editor/include/vtextedit/texteditorconfig.h
+1 −2 src/editor/include/vtextedit/texteditutils.h
+1 −3 src/editor/include/vtextedit/vmarkdowneditor.h
+38 −0 src/editor/include/vtextedit/vsyntaxhighlighter.h
+18 −5 src/editor/include/vtextedit/vtexteditor.h
+3 −3 src/editor/markdowneditor/editorpreviewmgr.cpp
+21 −2 src/editor/markdowneditor/pegmarkdownhighlighter.cpp
+8 −6 src/editor/markdowneditor/vmarkdowneditor.cpp
+6 −0 src/editor/spellcheck/spellcheck.pri
+107 −0 src/editor/spellcheck/spellchecker.cpp
+82 −0 src/editor/spellcheck/spellcheckhighlighthelper.cpp
+20 −0 src/editor/spellcheck/spellcheckhighlighthelper.h
+10 −0 src/editor/textedit/textblockdata.cpp
+39 −0 src/editor/texteditor/blockspellcheckdata.h
+29 −0 src/editor/texteditor/plaintexthighlighter.cpp
+21 −0 src/editor/texteditor/plaintexthighlighter.h
+90 −3 src/editor/texteditor/statusindicator.cpp
+18 −0 src/editor/texteditor/statusindicator.h
+20 −1 src/editor/texteditor/syntaxhighlighter.cpp
+7 −4 src/editor/texteditor/syntaxhighlighter.h
+4 −0 src/editor/texteditor/texteditor.pri
+75 −0 src/editor/texteditor/vsyntaxhighlighter.cpp
+131 −7 src/editor/texteditor/vtexteditor.cpp
+2 −3 src/editor/utils/texteditutils.cpp
+6 −0 src/editor/utils/utils.cpp
+4 −0 src/editor/utils/utils.h
+1 −0 src/libs/hunspell
+2 −0 src/libs/katevi/katevi_export.pri
+1 −1 src/libs/katevi/src/include/katevi/global.h
+2 −0 src/libs/katevi/src/viutils.cpp
+8 −1 src/libs/libs.pro
+1 −0 src/libs/sonnet
+1 −1 src/libs/syntax-highlighting
26 changes: 24 additions & 2 deletions src/core/configmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ void ConfigMgr::checkAppConfig()
FileUtils::copyDir(extraDataRoot + QStringLiteral("/web"),
appConfigDir.filePath(QStringLiteral("web")));

// Copy dicts.
qApp->processEvents();
splash->showMessage("Copying dicts");
FileUtils::copyDir(extraDataRoot + QStringLiteral("/dicts"),
appConfigDir.filePath(QStringLiteral("dicts")));

// Main config file.
FileUtils::copyFile(getConfigFilePath(Source::Default), appConfigDir.filePath(c_configFileName));

Expand Down Expand Up @@ -356,8 +362,24 @@ QString ConfigMgr::getAppSyntaxHighlightingFolder() const

QString ConfigMgr::getUserSyntaxHighlightingFolder() const
{
return PathUtils::concatenateFilePath(m_userConfigFolderPath,
QStringLiteral("syntax-highlighting"));
auto folderPath = PathUtils::concatenateFilePath(m_userConfigFolderPath,
QStringLiteral("syntax-highlighting"));
QDir().mkpath(folderPath);
return folderPath;
}

QString ConfigMgr::getAppDictsFolder() const
{
return PathUtils::concatenateFilePath(m_appConfigFolderPath,
QStringLiteral("dicts"));
}

QString ConfigMgr::getUserDictsFolder() const
{
auto folderPath = PathUtils::concatenateFilePath(m_userConfigFolderPath,
QStringLiteral("dicts"));
QDir().mkpath(folderPath);
return folderPath;
}

QString ConfigMgr::getUserOrAppFile(const QString &p_filePath) const
Expand Down
3 changes: 3 additions & 0 deletions src/core/configmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ namespace vnotex

QString getUserSyntaxHighlightingFolder() const;

QString getAppDictsFolder() const;
QString getUserDictsFolder() const;

// If @p_filePath is absolute, just return it.
// Otherwise, first try to find it in user folder, then in app folder.
QString getUserOrAppFile(const QString &p_filePath) const;
Expand Down
24 changes: 24 additions & 0 deletions src/core/editorconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using namespace vnotex;

#define READINT(key) readInt(appObj, userObj, (key))
#define READSTR(key) readString(appObj, userObj, (key))
#define READBOOL(key) readBool(appObj, userObj, (key))

EditorConfig::EditorConfig(ConfigMgr *p_mgr, IConfig *p_topConfig)
: IConfig(p_mgr, p_topConfig),
Expand Down Expand Up @@ -57,6 +58,12 @@ void EditorConfig::loadCore(const QJsonObject &p_app, const QJsonObject &p_user)
m_backupFileExtension = READSTR(QStringLiteral("backup_file_extension"));

loadShortcuts(appObj, userObj);

m_spellCheckAutoDetectLanguageEnabled = READBOOL(QStringLiteral("spell_check_auto_detect_language"));
m_spellCheckDefaultDictionary = READSTR(QStringLiteral("spell_check_default_dictionary"));
if (m_spellCheckDefaultDictionary.isEmpty()) {
m_spellCheckDefaultDictionary = QStringLiteral("en_US");
}
}

QJsonObject EditorConfig::saveCore() const
Expand All @@ -67,6 +74,8 @@ QJsonObject EditorConfig::saveCore() const
obj[QStringLiteral("backup_file_directory")] = m_backupFileDirectory;
obj[QStringLiteral("backup_file_extension")] = m_backupFileExtension;
obj[QStringLiteral("shortcuts")] = saveShortcuts();
obj[QStringLiteral("spell_check_auto_detect_language")] = m_spellCheckAutoDetectLanguageEnabled;
obj[QStringLiteral("spell_check_default_dictionary")] = m_spellCheckDefaultDictionary;
return obj;
}

Expand Down Expand Up @@ -188,3 +197,18 @@ const QString &EditorConfig::getBackupFileExtension() const
{
return m_backupFileExtension;
}

bool EditorConfig::isSpellCheckAutoDetectLanguageEnabled() const
{
return m_spellCheckAutoDetectLanguageEnabled;
}

const QString &EditorConfig::getSpellCheckDefaultDictionary() const
{
return m_spellCheckDefaultDictionary;
}

void EditorConfig::setSpellCheckDefaultDictionary(const QString &p_dict)
{
updateConfig(m_spellCheckDefaultDictionary, p_dict, this);
}
9 changes: 9 additions & 0 deletions src/core/editorconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ namespace vnotex

const QString &getShortcut(Shortcut p_shortcut) const;

bool isSpellCheckAutoDetectLanguageEnabled() const;

const QString &getSpellCheckDefaultDictionary() const;
void setSpellCheckDefaultDictionary(const QString &p_dict);

private:
void loadCore(const QJsonObject &p_app, const QJsonObject &p_user);

Expand Down Expand Up @@ -116,6 +121,10 @@ namespace vnotex
QSharedPointer<TextEditorConfig> m_textEditorConfig;

QScopedPointer<MarkdownEditorConfig> m_markdownEditorConfig;

bool m_spellCheckAutoDetectLanguageEnabled = false;

QString m_spellCheckDefaultDictionary;
};
}

Expand Down
12 changes: 12 additions & 0 deletions src/core/markdowneditorconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void MarkdownEditorConfig::init(const QJsonObject &p_app, const QJsonObject &p_u

m_smartTableEnabled = READBOOL(QStringLiteral("smart_table"));
m_smartTableInterval = READINT(QStringLiteral("smart_table_interval"));

m_spellCheckEnabled = READBOOL(QStringLiteral("spell_check"));
}

QJsonObject MarkdownEditorConfig::toJson() const
Expand Down Expand Up @@ -81,6 +83,7 @@ QJsonObject MarkdownEditorConfig::toJson() const
obj[QStringLiteral("indent_first_line")] = m_indentFirstLineEnabled;
obj[QStringLiteral("smart_table")] = m_smartTableEnabled;
obj[QStringLiteral("smart_table_interval")] = m_smartTableInterval;
obj[QStringLiteral("spell_check")] = m_spellCheckEnabled;
return obj;
}

Expand Down Expand Up @@ -373,3 +376,12 @@ int MarkdownEditorConfig::getSmartTableInterval() const
return m_smartTableInterval;
}

bool MarkdownEditorConfig::isSpellCheckEnabled() const
{
return m_spellCheckEnabled;
}

void MarkdownEditorConfig::setSpellCheckEnabled(bool p_enabled)
{
updateConfig(m_spellCheckEnabled, p_enabled, this);
}
6 changes: 6 additions & 0 deletions src/core/markdowneditorconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ namespace vnotex

int getSmartTableInterval() const;

bool isSpellCheckEnabled() const;
void setSpellCheckEnabled(bool p_enabled);

private:
QString sectionNumberModeToString(SectionNumberMode p_mode) const;
SectionNumberMode stringToSectionNumberMode(const QString &p_str) const;
Expand Down Expand Up @@ -171,6 +174,9 @@ namespace vnotex

// Interval time to do smart table format.
int m_smartTableInterval = 2000;

// Override the config in TextEditorConfig.
bool m_spellCheckEnabled = true;
};
}

Expand Down
13 changes: 13 additions & 0 deletions src/core/texteditorconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void TextEditorConfig::init(const QJsonObject &p_app,
m_tabStopWidth = READINT(QStringLiteral("tab_stop_width"));

m_zoomDelta = READINT(QStringLiteral("zoom_delta"));

m_spellCheckEnabled = READBOOL(QStringLiteral("spell_check"));
}

QJsonObject TextEditorConfig::toJson() const
Expand All @@ -58,6 +60,7 @@ QJsonObject TextEditorConfig::toJson() const
obj[QStringLiteral("expand_tab")] = m_expandTab;
obj[QStringLiteral("tab_stop_width")] = m_tabStopWidth;
obj[QStringLiteral("zoom_delta")] = m_zoomDelta;
obj[QStringLiteral("spell_check")] = m_spellCheckEnabled;
return obj;
}

Expand Down Expand Up @@ -244,3 +247,13 @@ void TextEditorConfig::setZoomDelta(int p_delta)
{
updateConfig(m_zoomDelta, p_delta, this);
}

bool TextEditorConfig::isSpellCheckEnabled() const
{
return m_spellCheckEnabled;
}

void TextEditorConfig::setSpellCheckEnabled(bool p_enabled)
{
updateConfig(m_spellCheckEnabled, p_enabled, this);
}
5 changes: 5 additions & 0 deletions src/core/texteditorconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace vnotex
int getZoomDelta() const;
void setZoomDelta(int p_delta);

bool isSpellCheckEnabled() const;
void setSpellCheckEnabled(bool p_enabled);

private:
QString lineNumberTypeToString(LineNumberType p_type) const;
LineNumberType stringToLineNumberType(const QString &p_str) const;
Expand Down Expand Up @@ -94,6 +97,8 @@ namespace vnotex
int m_tabStopWidth = 4;

int m_zoomDelta = 0;

bool m_spellCheckEnabled = false;
};
}

Expand Down
Binary file modified src/data/core/translations/vnote_zh_CN.qm
Binary file not shown.
Loading

0 comments on commit 6dbc688

Please sign in to comment.