mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
editor: refine heading sequence
This commit is contained in:
parent
5eb8c4d224
commit
e048734414
@ -1903,10 +1903,13 @@ void VMainWindow::updateActionsStateFromTab(const VEditTab *p_tab)
|
|||||||
setActionsEnabled(m_editToolBar, file && editMode);
|
setActionsEnabled(m_editToolBar, file && editMode);
|
||||||
|
|
||||||
// Handle heading sequence act independently.
|
// Handle heading sequence act independently.
|
||||||
m_headingSequenceAct->setEnabled(editMode && file->isModifiable()
|
m_headingSequenceAct->setEnabled(editMode
|
||||||
|
&& file->isModifiable()
|
||||||
&& isHeadingSequenceApplicable());
|
&& isHeadingSequenceApplicable());
|
||||||
const VMdTab *mdTab = dynamic_cast<const VMdTab *>(p_tab);
|
const VMdTab *mdTab = dynamic_cast<const VMdTab *>(p_tab);
|
||||||
m_headingSequenceAct->setChecked(mdTab && editMode && file->isModifiable()
|
m_headingSequenceAct->setChecked(mdTab
|
||||||
|
&& editMode
|
||||||
|
&& file->isModifiable()
|
||||||
&& mdTab->isHeadingSequenceEnabled());
|
&& mdTab->isHeadingSequenceEnabled());
|
||||||
|
|
||||||
// Find/Replace
|
// Find/Replace
|
||||||
|
@ -426,7 +426,7 @@ static QString headerSequenceStr(const QVector<int> &p_sequence)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void insertSequenceToHeader(QTextCursor& p_cursor,
|
static void insertSequenceToHeader(QTextCursor& p_cursor,
|
||||||
QTextBlock p_block,
|
const QTextBlock &p_block,
|
||||||
QRegExp &p_reg,
|
QRegExp &p_reg,
|
||||||
QRegExp &p_preReg,
|
QRegExp &p_preReg,
|
||||||
const QString &p_seq)
|
const QString &p_seq)
|
||||||
@ -525,14 +525,11 @@ void VMdEditor::updateHeadersHelper(const QVector<VElementRegion> &p_headerRegio
|
|||||||
QVector<int> seqs(7, 0);
|
QVector<int> seqs(7, 0);
|
||||||
QRegExp preReg(VUtils::c_headerPrefixRegExp);
|
QRegExp preReg(VUtils::c_headerPrefixRegExp);
|
||||||
int curLevel = baseLevel - 1;
|
int curLevel = baseLevel - 1;
|
||||||
QTextCursor cursor = textCursorW();
|
QTextCursor cursor(doc);
|
||||||
|
|
||||||
int blockNo = cursor.block().blockNumber();
|
|
||||||
int posToBlockEnd = cursor.block().length() - cursor.positionInBlock();
|
|
||||||
|
|
||||||
if(autoSequence || p_configChanged) {
|
if(autoSequence || p_configChanged) {
|
||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < headers.size(); ++i) {
|
for (int i = 0; i < headers.size(); ++i) {
|
||||||
VTableOfContentItem &item = headers[i];
|
VTableOfContentItem &item = headers[i];
|
||||||
while (item.m_level > curLevel + 1) {
|
while (item.m_level > curLevel + 1) {
|
||||||
@ -565,11 +562,9 @@ void VMdEditor::updateHeadersHelper(const QVector<VElementRegion> &p_headerRegio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoSequence || p_configChanged) {
|
if (autoSequence || p_configChanged) {
|
||||||
QTextBlock block = doc->findBlockByNumber(blockNo);
|
|
||||||
cursor.setPosition(block.position() + block.length() - posToBlockEnd);
|
|
||||||
cursor.endEditBlock();
|
cursor.endEditBlock();
|
||||||
setTextCursorW(cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit headersChanged(m_headers);
|
emit headersChanged(m_headers);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user