mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
support auto indent
This commit is contained in:
parent
ed4e3c3d74
commit
7001976252
@ -1 +1 @@
|
|||||||
Subproject commit c3889fc666816ae64d5a71b4c7bcd8fccb15b45f
|
Subproject commit 76501957e8ac4d138a1e3745d978432598450eed
|
@ -71,7 +71,6 @@ ConfigMgr::ConfigMgr(QObject *p_parent)
|
|||||||
|
|
||||||
ConfigMgr::~ConfigMgr()
|
ConfigMgr::~ConfigMgr()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigMgr::locateConfigFolder()
|
void ConfigMgr::locateConfigFolder()
|
||||||
|
@ -56,9 +56,6 @@ namespace vnotex
|
|||||||
|
|
||||||
~ConfigMgr();
|
~ConfigMgr();
|
||||||
|
|
||||||
ConfigMgr(const ConfigMgr &) = delete;
|
|
||||||
void operator=(const ConfigMgr &) = delete;
|
|
||||||
|
|
||||||
MainConfig &getConfig();
|
MainConfig &getConfig();
|
||||||
|
|
||||||
SessionConfig &getSessionConfig();
|
SessionConfig &getSessionConfig();
|
||||||
|
@ -107,7 +107,7 @@ namespace vnotex
|
|||||||
AutoSavePolicy stringToAutoSavePolicy(const QString &p_str) const;
|
AutoSavePolicy stringToAutoSavePolicy(const QString &p_str) const;
|
||||||
|
|
||||||
// Icon size of editor tool bar.
|
// Icon size of editor tool bar.
|
||||||
int m_toolBarIconSize = 14;
|
int m_toolBarIconSize = 16;
|
||||||
|
|
||||||
QString m_shortcuts[Shortcut::MaxShortcut];
|
QString m_shortcuts[Shortcut::MaxShortcut];
|
||||||
|
|
||||||
|
@ -117,14 +117,6 @@ QString MainConfig::getVersion(const QJsonObject &p_jobj)
|
|||||||
void MainConfig::doVersionSpecificOverride()
|
void MainConfig::doVersionSpecificOverride()
|
||||||
{
|
{
|
||||||
// In a new version, we may want to change one value by force.
|
// In a new version, we may want to change one value by force.
|
||||||
m_coreConfig->m_shortcuts[CoreConfig::Shortcut::NavigationDock] = "Ctrl+G, A";
|
m_editorConfig->m_toolBarIconSize = 16;
|
||||||
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->writeToSettings();
|
m_editorConfig->writeToSettings();
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
},
|
},
|
||||||
"editor" : {
|
"editor" : {
|
||||||
"core": {
|
"core": {
|
||||||
"toolbar_icon_size" : 14,
|
"toolbar_icon_size" : 16,
|
||||||
"//comment" : "none/autosave/backupfile",
|
"//comment" : "none/autosave/backupfile",
|
||||||
"auto_save_policy" : "autosave",
|
"auto_save_policy" : "autosave",
|
||||||
"backup_file_extension" : "vswp",
|
"backup_file_extension" : "vswp",
|
||||||
|
@ -1,77 +0,0 @@
|
|||||||
#include "textutils.h"
|
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
#ifndef TEXTUTILS_H
|
|
||||||
#define TEXTUTILS_H
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
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
|
|
@ -7,7 +7,6 @@ SOURCES += \
|
|||||||
$$PWD/imageutils.cpp \
|
$$PWD/imageutils.cpp \
|
||||||
$$PWD/pathutils.cpp \
|
$$PWD/pathutils.cpp \
|
||||||
$$PWD/processutils.cpp \
|
$$PWD/processutils.cpp \
|
||||||
$$PWD/textutils.cpp \
|
|
||||||
$$PWD/urldragdroputils.cpp \
|
$$PWD/urldragdroputils.cpp \
|
||||||
$$PWD/utils.cpp \
|
$$PWD/utils.cpp \
|
||||||
$$PWD/fileutils.cpp \
|
$$PWD/fileutils.cpp \
|
||||||
@ -23,7 +22,6 @@ HEADERS += \
|
|||||||
$$PWD/imageutils.h \
|
$$PWD/imageutils.h \
|
||||||
$$PWD/pathutils.h \
|
$$PWD/pathutils.h \
|
||||||
$$PWD/processutils.h \
|
$$PWD/processutils.h \
|
||||||
$$PWD/textutils.h \
|
|
||||||
$$PWD/urldragdroputils.h \
|
$$PWD/urldragdroputils.h \
|
||||||
$$PWD/utils.h \
|
$$PWD/utils.h \
|
||||||
$$PWD/fileutils.h \
|
$$PWD/fileutils.h \
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include <utils/pathutils.h>
|
#include <utils/pathutils.h>
|
||||||
#include <utils/htmlutils.h>
|
#include <utils/htmlutils.h>
|
||||||
#include <utils/widgetutils.h>
|
#include <utils/widgetutils.h>
|
||||||
#include <utils/textutils.h>
|
|
||||||
#include <utils/webutils.h>
|
#include <utils/webutils.h>
|
||||||
#include <utils/imageutils.h>
|
#include <utils/imageutils.h>
|
||||||
#include <core/exception.h>
|
#include <core/exception.h>
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
#include <vtextedit/pegmarkdownhighlighterdata.h>
|
#include <vtextedit/pegmarkdownhighlighterdata.h>
|
||||||
#include <vtextedit/texteditorconfig.h>
|
#include <vtextedit/texteditorconfig.h>
|
||||||
#include <vtextedit/previewmgr.h>
|
#include <vtextedit/previewmgr.h>
|
||||||
|
#include <vtextedit/textutils.h>
|
||||||
|
|
||||||
#include <utils/textutils.h>
|
|
||||||
#include <utils/utils.h>
|
#include <utils/utils.h>
|
||||||
|
|
||||||
#include "markdowneditor.h"
|
#include "markdowneditor.h"
|
||||||
@ -231,7 +231,7 @@ void PreviewHelper::inplacePreviewCodeBlock(int p_blockPreviewIdx)
|
|||||||
emit graphPreviewRequested(p_blockPreviewIdx,
|
emit graphPreviewRequested(p_blockPreviewIdx,
|
||||||
m_codeBlockTimeStamp,
|
m_codeBlockTimeStamp,
|
||||||
blockData.m_lang,
|
blockData.m_lang,
|
||||||
TextUtils::removeCodeBlockFence(blockData.m_text));
|
vte::TextUtils::removeCodeBlockFence(blockData.m_text));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ void PreviewHelper::inplacePreviewCodeBlock(int p_blockPreviewIdx)
|
|||||||
PlantUmlHelper::getInst().process(static_cast<quint64>(p_blockPreviewIdx),
|
PlantUmlHelper::getInst().process(static_cast<quint64>(p_blockPreviewIdx),
|
||||||
m_codeBlockTimeStamp,
|
m_codeBlockTimeStamp,
|
||||||
QStringLiteral("svg"),
|
QStringLiteral("svg"),
|
||||||
TextUtils::removeCodeBlockFence(blockData.m_text),
|
vte::TextUtils::removeCodeBlockFence(blockData.m_text),
|
||||||
[this](quint64 id, TimeStamp timeStamp, const QString &format, const QString &data) {
|
[this](quint64 id, TimeStamp timeStamp, const QString &format, const QString &data) {
|
||||||
handleLocalData(id, timeStamp, format, data, true);
|
handleLocalData(id, timeStamp, format, data, true);
|
||||||
});
|
});
|
||||||
@ -252,7 +252,7 @@ void PreviewHelper::inplacePreviewCodeBlock(int p_blockPreviewIdx)
|
|||||||
GraphvizHelper::getInst().process(static_cast<quint64>(p_blockPreviewIdx),
|
GraphvizHelper::getInst().process(static_cast<quint64>(p_blockPreviewIdx),
|
||||||
m_codeBlockTimeStamp,
|
m_codeBlockTimeStamp,
|
||||||
QStringLiteral("svg"),
|
QStringLiteral("svg"),
|
||||||
TextUtils::removeCodeBlockFence(blockData.m_text),
|
vte::TextUtils::removeCodeBlockFence(blockData.m_text),
|
||||||
[this](quint64 id, TimeStamp timeStamp, const QString &format, const QString &data) {
|
[this](quint64 id, TimeStamp timeStamp, const QString &format, const QString &data) {
|
||||||
handleLocalData(id, timeStamp, format, data, false);
|
handleLocalData(id, timeStamp, format, data, false);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user