bug-fix: insert code block inline if it is at the end of a space block

This commit is contained in:
Le Tan 2017-10-23 21:41:34 +08:00
parent 73ee02d3b2
commit a265aed035
5 changed files with 10 additions and 5 deletions

View File

@ -458,6 +458,11 @@ bool VEditUtils::isSpaceToBlockStart(const QTextBlock &p_block, int p_posInBlock
return text.left(p_posInBlock).trimmed().isEmpty(); return text.left(p_posInBlock).trimmed().isEmpty();
} }
bool VEditUtils::isSpaceBlock(const QTextBlock &p_block)
{
return p_block.text().trimmed().isEmpty();
}
void VEditUtils::deleteIndentAndListMark(QTextCursor &p_cursor) void VEditUtils::deleteIndentAndListMark(QTextCursor &p_cursor)
{ {
V_ASSERT(!p_cursor.hasSelection()); V_ASSERT(!p_cursor.hasSelection());

View File

@ -121,6 +121,9 @@ public:
// If the start of @p_block to postition @p_posInBlock are spaces. // If the start of @p_block to postition @p_posInBlock are spaces.
static bool isSpaceToBlockStart(const QTextBlock &p_block, int p_posInBlock); static bool isSpaceToBlockStart(const QTextBlock &p_block, int p_posInBlock);
// If block @p_block only contains spaces.
static bool isSpaceBlock(const QTextBlock &p_block);
// @p_cursor is positioned right after auto indetn and auto list. // @p_cursor is positioned right after auto indetn and auto list.
// Need to call setTextCursor() to make it take effect. // Need to call setTextCursor() to make it take effect.
static void deleteIndentAndListMark(QTextCursor &p_cursor); static void deleteIndentAndListMark(QTextCursor &p_cursor);

View File

@ -14,9 +14,6 @@ extern VMainWindow *g_mainWin;
extern VConfigManager *g_config; extern VConfigManager *g_config;
// 3s pending time after the leader keys.
const int c_pendingTime = 3 * 1000;
VCaptain::VCaptain(QWidget *p_parent) VCaptain::VCaptain(QWidget *p_parent)
: QWidget(p_parent), : QWidget(p_parent),
m_mode(CaptainMode::Normal), m_mode(CaptainMode::Normal),

View File

@ -881,7 +881,7 @@ void VMdEditOperations::decorateCodeBlock()
if (!cursor.atBlockEnd()) { if (!cursor.atBlockEnd()) {
cursor.insertBlock(); cursor.insertBlock();
cursor.movePosition(QTextCursor::PreviousBlock); cursor.movePosition(QTextCursor::PreviousBlock);
} else if (cursor.atBlockStart()) { } else if (cursor.atBlockStart() || VEditUtils::isSpaceBlock(block)) {
insertInline = true; insertInline = true;
} }

View File

@ -26,7 +26,7 @@ public:
bool insertImageFromURL(const QUrl &p_imageUrl) Q_DECL_OVERRIDE; bool insertImageFromURL(const QUrl &p_imageUrl) Q_DECL_OVERRIDE;
bool insertLink(const QString &p_linkText, bool insertLink(const QString &p_linkText,
const QString &p_linkUrl); const QString &p_linkUrl) Q_DECL_OVERRIDE;
// Insert decoration markers or decorate selected text. // Insert decoration markers or decorate selected text.
// If it is Vim Normal mode, change to Insert mode first. // If it is Vim Normal mode, change to Insert mode first.