From 70019762522a8013192c226e419ce8ee02ec9d2f Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 12 Jun 2021 12:43:56 +0800 Subject: [PATCH] support auto indent --- libs/vtextedit | 2 +- src/core/configmgr.cpp | 1 - src/core/configmgr.h | 3 - src/core/editorconfig.h | 2 +- src/core/mainconfig.cpp | 10 +--- src/data/core/vnotex.json | 2 +- src/utils/textutils.cpp | 77 -------------------------- src/utils/textutils.h | 26 --------- src/utils/utils.pri | 2 - src/widgets/editors/markdowneditor.cpp | 1 - src/widgets/editors/previewhelper.cpp | 8 +-- 11 files changed, 8 insertions(+), 126 deletions(-) delete mode 100644 src/utils/textutils.cpp delete mode 100644 src/utils/textutils.h diff --git a/libs/vtextedit b/libs/vtextedit index c3889fc6..76501957 160000 --- a/libs/vtextedit +++ b/libs/vtextedit @@ -1 +1 @@ -Subproject commit c3889fc666816ae64d5a71b4c7bcd8fccb15b45f +Subproject commit 76501957e8ac4d138a1e3745d978432598450eed diff --git a/src/core/configmgr.cpp b/src/core/configmgr.cpp index a1d29019..f0684e97 100644 --- a/src/core/configmgr.cpp +++ b/src/core/configmgr.cpp @@ -71,7 +71,6 @@ ConfigMgr::ConfigMgr(QObject *p_parent) ConfigMgr::~ConfigMgr() { - } void ConfigMgr::locateConfigFolder() diff --git a/src/core/configmgr.h b/src/core/configmgr.h index 27a7d2e4..5c7c9377 100644 --- a/src/core/configmgr.h +++ b/src/core/configmgr.h @@ -56,9 +56,6 @@ namespace vnotex ~ConfigMgr(); - ConfigMgr(const ConfigMgr &) = delete; - void operator=(const ConfigMgr &) = delete; - MainConfig &getConfig(); SessionConfig &getSessionConfig(); diff --git a/src/core/editorconfig.h b/src/core/editorconfig.h index 32138fe8..28777d14 100644 --- a/src/core/editorconfig.h +++ b/src/core/editorconfig.h @@ -107,7 +107,7 @@ namespace vnotex AutoSavePolicy stringToAutoSavePolicy(const QString &p_str) const; // Icon size of editor tool bar. - int m_toolBarIconSize = 14; + int m_toolBarIconSize = 16; QString m_shortcuts[Shortcut::MaxShortcut]; diff --git a/src/core/mainconfig.cpp b/src/core/mainconfig.cpp index 0c88e1bf..8a705a1a 100644 --- a/src/core/mainconfig.cpp +++ b/src/core/mainconfig.cpp @@ -117,14 +117,6 @@ QString MainConfig::getVersion(const QJsonObject &p_jobj) void MainConfig::doVersionSpecificOverride() { // In a new version, we may want to change one value by force. - m_coreConfig->m_shortcuts[CoreConfig::Shortcut::NavigationDock] = "Ctrl+G, A"; - m_coreConfig->m_shortcuts[CoreConfig::Shortcut::OutlineDock] = "Ctrl+G, U"; - m_coreConfig->m_shortcuts[CoreConfig::Shortcut::SearchDock] = "Ctrl+G, S"; - m_coreConfig->m_shortcuts[CoreConfig::Shortcut::LocationListDock] = "Ctrl+G, L"; - m_coreConfig->m_shortcuts[CoreConfig::Shortcut::NewWorkspace] = "Ctrl+G, M"; - m_coreConfig->writeToSettings(); - - m_editorConfig->m_shortcuts[EditorConfig::Shortcut::TypeMath] = "Ctrl+."; - m_editorConfig->m_shortcuts[EditorConfig::Shortcut::TypeMathBlock] = "Ctrl+G, ."; + m_editorConfig->m_toolBarIconSize = 16; m_editorConfig->writeToSettings(); } diff --git a/src/data/core/vnotex.json b/src/data/core/vnotex.json index 7f836616..b00b4e9b 100644 --- a/src/data/core/vnotex.json +++ b/src/data/core/vnotex.json @@ -60,7 +60,7 @@ }, "editor" : { "core": { - "toolbar_icon_size" : 14, + "toolbar_icon_size" : 16, "//comment" : "none/autosave/backupfile", "auto_save_policy" : "autosave", "backup_file_extension" : "vswp", diff --git a/src/utils/textutils.cpp b/src/utils/textutils.cpp deleted file mode 100644 index 87b32123..00000000 --- a/src/utils/textutils.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "textutils.h" - -#include - -using namespace vnotex; - -QString TextUtils::removeCodeBlockFence(const QString &p_text) -{ - auto text = unindentTextMultiLines(p_text); - Q_ASSERT(text.startsWith(QStringLiteral("```")) || text.startsWith(QStringLiteral("~~~"))); - int idx = text.indexOf(QLatin1Char('\n')) + 1; - int lidx = text.size() - 1; - // Trim spaces at the end. - while (lidx >= 0 && text[lidx].isSpace()) { - --lidx; - } - - Q_ASSERT(text[lidx] == QLatin1Char('`') || text[lidx] == QLatin1Char('~')); - return text.mid(idx, lidx + 1 - idx - 3); -} - -int TextUtils::fetchIndentation(const QString &p_text) -{ - int idx = firstNonSpace(p_text); - return idx == -1 ? 0 : idx; -} - -QString TextUtils::unindentText(const QString &p_text, int p_spaces) -{ - if (p_spaces == 0) { - return p_text; - } - - int idx = 0; - while (idx < p_spaces && idx < p_text.size() && p_text[idx].isSpace()) { - ++idx; - } - return p_text.right(p_text.size() - idx); -} - -int TextUtils::firstNonSpace(const QString &p_text) -{ - for (int i = 0; i < p_text.size(); ++i) { - if (!p_text.at(i).isSpace()) { - return i; - } - } - - return -1; -} - -QString TextUtils::unindentTextMultiLines(const QString &p_text) -{ - if (p_text.isEmpty()) { - return p_text; - } - - auto lines = p_text.split(QLatin1Char('\n')); - Q_ASSERT(lines.size() > 0); - - const int indentation = fetchIndentation(lines[0]); - if (indentation == 0) { - return p_text; - } - - QString res = lines[0].right(lines[0].size() - indentation); - for (int i = 1; i < lines.size(); ++i) { - const auto &line = lines[i]; - int idx = 0; - while (idx < indentation && idx < line.size() && line[idx].isSpace()) { - ++idx; - } - res = res + QLatin1Char('\n') + line.right(line.size() - idx); - } - - return res; -} diff --git a/src/utils/textutils.h b/src/utils/textutils.h deleted file mode 100644 index a432205b..00000000 --- a/src/utils/textutils.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef TEXTUTILS_H -#define TEXTUTILS_H - -#include - -namespace vnotex -{ - class TextUtils - { - public: - TextUtils() = delete; - - static int firstNonSpace(const QString &p_text); - - static QString removeCodeBlockFence(const QString &p_text); - - static int fetchIndentation(const QString &p_text); - - static QString unindentText(const QString &p_text, int p_spaces); - - // Unindent multi-lines text according to the indentation of the first line. - static QString unindentTextMultiLines(const QString &p_text); - }; -} - -#endif // TEXTUTILS_H diff --git a/src/utils/utils.pri b/src/utils/utils.pri index a3dc991d..f9dd9429 100644 --- a/src/utils/utils.pri +++ b/src/utils/utils.pri @@ -7,7 +7,6 @@ SOURCES += \ $$PWD/imageutils.cpp \ $$PWD/pathutils.cpp \ $$PWD/processutils.cpp \ - $$PWD/textutils.cpp \ $$PWD/urldragdroputils.cpp \ $$PWD/utils.cpp \ $$PWD/fileutils.cpp \ @@ -23,7 +22,6 @@ HEADERS += \ $$PWD/imageutils.h \ $$PWD/pathutils.h \ $$PWD/processutils.h \ - $$PWD/textutils.h \ $$PWD/urldragdroputils.h \ $$PWD/utils.h \ $$PWD/fileutils.h \ diff --git a/src/widgets/editors/markdowneditor.cpp b/src/widgets/editors/markdowneditor.cpp index b001343c..f5be84a9 100644 --- a/src/widgets/editors/markdowneditor.cpp +++ b/src/widgets/editors/markdowneditor.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include diff --git a/src/widgets/editors/previewhelper.cpp b/src/widgets/editors/previewhelper.cpp index 3e7116b0..9c837794 100644 --- a/src/widgets/editors/previewhelper.cpp +++ b/src/widgets/editors/previewhelper.cpp @@ -7,8 +7,8 @@ #include #include #include +#include -#include #include #include "markdowneditor.h" @@ -231,7 +231,7 @@ void PreviewHelper::inplacePreviewCodeBlock(int p_blockPreviewIdx) emit graphPreviewRequested(p_blockPreviewIdx, m_codeBlockTimeStamp, blockData.m_lang, - TextUtils::removeCodeBlockFence(blockData.m_text)); + vte::TextUtils::removeCodeBlockFence(blockData.m_text)); return; } @@ -240,7 +240,7 @@ void PreviewHelper::inplacePreviewCodeBlock(int p_blockPreviewIdx) PlantUmlHelper::getInst().process(static_cast(p_blockPreviewIdx), m_codeBlockTimeStamp, QStringLiteral("svg"), - TextUtils::removeCodeBlockFence(blockData.m_text), + vte::TextUtils::removeCodeBlockFence(blockData.m_text), [this](quint64 id, TimeStamp timeStamp, const QString &format, const QString &data) { handleLocalData(id, timeStamp, format, data, true); }); @@ -252,7 +252,7 @@ void PreviewHelper::inplacePreviewCodeBlock(int p_blockPreviewIdx) GraphvizHelper::getInst().process(static_cast(p_blockPreviewIdx), m_codeBlockTimeStamp, QStringLiteral("svg"), - TextUtils::removeCodeBlockFence(blockData.m_text), + vte::TextUtils::removeCodeBlockFence(blockData.m_text), [this](quint64 id, TimeStamp timeStamp, const QString &format, const QString &data) { handleLocalData(id, timeStamp, format, data, false); });