Skip to content

Commit

Permalink
Github Issue #29: previous method to extract the raw texts with all t…
Browse files Browse the repository at this point in the history
…he data and symbols on a QTextBlock level couldn't return QTextBlock with the shown format symbols so therefore returning QString as result. Also added another method to extract the formattings such as checkbox, link, bold, italic and strikethrough
  • Loading branch information
AngryFender committed Apr 5, 2024
1 parent 7dcf5d9 commit 272b0ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions mktextdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ void MkTextDocument::showSymbolsAtPos(QString &text, int pos, const QString &sym
text.insert(pos,symbol);
}

void MkTextDocument::extractSymbolsInBlock(QTextBlock &block)
void MkTextDocument::extractSymbolsInBlock(QTextBlock &block, QString &result)
{
QTextBlockUserData* data =block.userData();
if(data == nullptr){
Expand All @@ -692,12 +692,27 @@ void MkTextDocument::extractSymbolsInBlock(QTextBlock &block)
if(formatData){
if(formatData->isHidden()){
formatData->setHidden(false);
showAllFormatSymbolsInTextBlock(block, formatData);
showFormatSymbolsInTextBlock(block, formatData, result);
}
}
}
}

void MkTextDocument::showFormatSymbolsInTextBlock(QTextBlock &block, FormatData *formatData, QString &result)
{
QString textBlock = block.text();
for(QVector<PositionData*>::Iterator it = formatData->pos_begin(); it < formatData->pos_end(); it++)
{
showSymbolsAtPos(textBlock, (*it)->getPos(), (*it)->getSymbol());

if((*it)->getSymbol() == LINK_SYMBOL_URL_START){
int pos = (*it)->getPos();
textBlock.insert(pos+2,formatData->getLinkUrl(pos));
}
}
result = textBlock;
}

void MkTextDocument::autoCompleteCodeBlock(int blockNumber ,bool &success)
{
QTextCursor editCursor(this->findBlockByNumber(blockNumber));
Expand Down
3 changes: 2 additions & 1 deletion mktextdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public slots:
void showAllFormatSymbolsInTextBlock(QTextBlock &block, FormatData *formatData, SelectRange * selectRange = nullptr);
void showSymbolsAtPos(QString &text, int pos, const QString &symbol);

void extractSymbolsInBlock(QTextBlock &block);
void extractSymbolsInBlock(QTextBlock &block, QString &result);
void showFormatSymbolsInTextBlock(QTextBlock &block, FormatData *formatData, QString &result);

void autoCompleteCodeBlock(int blockNumber,bool &success);
BlockData* checkValidCodeBlock(QTextBlock &block);
Expand Down

0 comments on commit 272b0ec

Please sign in to comment.