fix tab order and TOC level in edit mode

1. Fix tab order of left and right corner widgets;
2. Insert [EMPTY] header when header level is not continuous in edit mode.
This commit is contained in:
Le Tan 2017-04-02 11:43:05 +08:00
parent b0d3e42647
commit 584472f902
3 changed files with 24 additions and 16 deletions

View File

@ -423,7 +423,7 @@ void VEditTab::parseTocLi(QXmlStreamReader &xml, QVector<VHeader> &headers, int
} }
} else if (xml.name() == "ul") { } else if (xml.name() == "ul") {
// Such as header 3 under header 1 directly // Such as header 3 under header 1 directly
VHeader header(level, "[Empty]", "#", -1); VHeader header(level, "[EMPTY]", "#", -1);
headers.append(header); headers.append(header);
parseTocUl(xml, headers, level + 1); parseTocUl(xml, headers, level + 1);
} else { } else {

View File

@ -61,6 +61,19 @@ void VEditWindow::initTabActions()
void VEditWindow::setupCornerWidget() void VEditWindow::setupCornerWidget()
{ {
// Left corner button
tabListAct = new QActionGroup(this);
connect(tabListAct, &QActionGroup::triggered,
this, &VEditWindow::tabListJump);
leftBtn = new QPushButton(QIcon(":/resources/icons/corner_tablist.svg"),
"", this);
leftBtn->setProperty("CornerBtn", true);
QMenu *leftMenu = new QMenu(this);
leftBtn->setMenu(leftMenu);
setCornerWidget(leftBtn, Qt::TopLeftCorner);
connect(leftMenu, &QMenu::aboutToShow,
this, &VEditWindow::updateTabListMenu);
// Right corner button // Right corner button
// Actions // Actions
splitAct = new QAction(QIcon(":/resources/icons/split_window.svg"), splitAct = new QAction(QIcon(":/resources/icons/split_window.svg"),
@ -85,19 +98,6 @@ void VEditWindow::setupCornerWidget()
setCornerWidget(rightBtn, Qt::TopRightCorner); setCornerWidget(rightBtn, Qt::TopRightCorner);
connect(rightMenu, &QMenu::aboutToShow, connect(rightMenu, &QMenu::aboutToShow,
this, &VEditWindow::updateSplitMenu); this, &VEditWindow::updateSplitMenu);
// Left corner button
tabListAct = new QActionGroup(this);
connect(tabListAct, &QActionGroup::triggered,
this, &VEditWindow::tabListJump);
leftBtn = new QPushButton(QIcon(":/resources/icons/corner_tablist.svg"),
"", this);
leftBtn->setProperty("CornerBtn", true);
QMenu *leftMenu = new QMenu(this);
leftBtn->setMenu(leftMenu);
setCornerWidget(leftBtn, Qt::TopLeftCorner);
connect(leftMenu, &QMenu::aboutToShow,
this, &VEditWindow::updateTabListMenu);
} }
void VEditWindow::splitWindow() void VEditWindow::splitWindow()

View File

@ -243,13 +243,21 @@ void VMdEdit::generateEditOutline()
// Assume that each block contains only one line // Assume that each block contains only one line
// Only support # syntax for now // Only support # syntax for now
QRegExp headerReg("(#{1,6})\\s*(\\S.*)"); // Need to trim the spaces QRegExp headerReg("(#{1,6})\\s*(\\S.*)"); // Need to trim the spaces
int lastLevel = 0;
for (QTextBlock block = doc->begin(); block != doc->end(); block = block.next()) { for (QTextBlock block = doc->begin(); block != doc->end(); block = block.next()) {
Q_ASSERT(block.lineCount() == 1); Q_ASSERT(block.lineCount() == 1);
if ((block.userState() == HighlightBlockState::Normal) && if ((block.userState() == HighlightBlockState::Normal) &&
headerReg.exactMatch(block.text())) { headerReg.exactMatch(block.text())) {
VHeader header(headerReg.cap(1).length(), int level = headerReg.cap(1).length();
headerReg.cap(2).trimmed(), "", block.firstLineNumber()); VHeader header(level, headerReg.cap(2).trimmed(),
"", block.firstLineNumber());
while (level > lastLevel + 1) {
// Insert empty level.
m_headers.append(VHeader(++lastLevel, "[EMPTY]",
"", block.firstLineNumber()));
}
m_headers.append(header); m_headers.append(header);
lastLevel = level;
} }
} }