mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
MdEidtOperations: support * as list bullet in auto list
This commit is contained in:
parent
8055f17d1f
commit
e2eb4efb45
@ -62,15 +62,15 @@ bool VEditUtils::insertListMarkAsPreviousBlock(QTextCursor &p_cursor)
|
||||
}
|
||||
|
||||
QString text = preBlock.text();
|
||||
QRegExp regExp("^\\s*(-|\\d+\\.)\\s");
|
||||
QRegExp regExp(VUtils::c_listRegExp);
|
||||
int regIdx = regExp.indexIn(text);
|
||||
if (regIdx != -1) {
|
||||
ret = true;
|
||||
V_ASSERT(regExp.captureCount() == 1);
|
||||
QString markText = regExp.capturedTexts()[1];
|
||||
if (markText == "-") {
|
||||
// Insert - in front.
|
||||
p_cursor.insertText("- ");
|
||||
if (isListBullet(markText)) {
|
||||
// Insert bullet in front.
|
||||
p_cursor.insertText(markText + " ");
|
||||
} else {
|
||||
// markText is like "123.".
|
||||
V_ASSERT(markText.endsWith('.'));
|
||||
@ -557,7 +557,7 @@ void VEditUtils::scrollBlockInPage(QPlainTextEdit *p_edit,
|
||||
bool VEditUtils::isListBlock(const QTextBlock &p_block, int *p_seq)
|
||||
{
|
||||
QString text = p_block.text();
|
||||
QRegExp regExp("^\\s*(-|\\d+\\.)\\s");
|
||||
QRegExp regExp(VUtils::c_listRegExp);
|
||||
|
||||
if (p_seq) {
|
||||
*p_seq = -1;
|
||||
@ -570,7 +570,7 @@ bool VEditUtils::isListBlock(const QTextBlock &p_block, int *p_seq)
|
||||
|
||||
V_ASSERT(regExp.captureCount() == 1);
|
||||
QString markText = regExp.capturedTexts()[1];
|
||||
if (markText != "-") {
|
||||
if (!isListBullet(markText)) {
|
||||
V_ASSERT(markText.endsWith('.'));
|
||||
bool ok = false;
|
||||
int num = markText.left(markText.size() - 1).toInt(&ok, 10);
|
||||
@ -583,6 +583,11 @@ bool VEditUtils::isListBlock(const QTextBlock &p_block, int *p_seq)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VEditUtils::isListBullet(const QString &p_str)
|
||||
{
|
||||
return p_str == "-" || p_str == "*";
|
||||
}
|
||||
|
||||
bool VEditUtils::isSpaceToBlockStart(const QTextBlock &p_block, int p_posInBlock)
|
||||
{
|
||||
if (p_posInBlock <= 0) {
|
||||
|
@ -139,6 +139,8 @@ public:
|
||||
// Returns true if it is an auto list block.
|
||||
static bool isListBlock(const QTextBlock &p_block, int *p_seq = NULL);
|
||||
|
||||
static bool isListBullet(const QString &p_str);
|
||||
|
||||
// If the start of @p_block to postition @p_posInBlock are spaces.
|
||||
static bool isSpaceToBlockStart(const QTextBlock &p_block, int p_posInBlock);
|
||||
|
||||
|
@ -59,6 +59,8 @@ const QString VUtils::c_headerRegExp = QString("^(#{1,6})\\s+(((\\d+\\.)+(?=\\s)
|
||||
|
||||
const QString VUtils::c_headerPrefixRegExp = QString("^(#{1,6}\\s+((\\d+\\.)+(?=\\s))?\\s*)($|(\\S.*)?$)");
|
||||
|
||||
const QString VUtils::c_listRegExp = QString("^\\s*(-|\\*|\\d+\\.)\\s");
|
||||
|
||||
void VUtils::initAvailableLanguage()
|
||||
{
|
||||
if (!s_availableLanguages.isEmpty()) {
|
||||
|
@ -399,6 +399,8 @@ public:
|
||||
// 1. prefix till the real header title content;
|
||||
static const QString c_headerPrefixRegExp;
|
||||
|
||||
static const QString c_listRegExp;
|
||||
|
||||
private:
|
||||
VUtils() {}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user