speed out selection count calculation

This commit is contained in:
Roy Qu 2024-03-24 09:56:37 +08:00
parent 5e10d0b4db
commit 2cad9262c9
3 changed files with 24 additions and 2 deletions

View File

@ -1517,7 +1517,7 @@ void MainWindow::updateStatusbarForLineCol(const Editor* e, bool clear)
.arg(e->caretY()) .arg(e->caretY())
.arg(e->document()->count()) .arg(e->document()->count())
.arg(col) .arg(col)
.arg(e->selText().length()); .arg(e->selCount());
} else { } else {
msg = tr("Line: %1/%2 Col: %3") msg = tr("Line: %1/%2 Col: %3")
.arg(e->caretY()) .arg(e->caretY())
@ -1531,7 +1531,7 @@ void MainWindow::updateStatusbarForLineCol(const Editor* e, bool clear)
.arg(e->document()->count()) .arg(e->document()->count())
.arg(e->caretX()) .arg(e->caretX())
.arg(e->lineText().length()) .arg(e->lineText().length())
.arg(e->selText().length()); .arg(e->selCount());
} else { } else {
msg = tr("Line: %1/%2 Char: %3/%4") msg = tr("Line: %1/%2 Char: %3/%4")
.arg(e->caretY()) .arg(e->caretY())

View File

@ -4517,6 +4517,27 @@ QString QSynEdit::selText() const
return ""; return "";
} }
int QSynEdit::selCount() const
{
if (!selAvail())
return 0;
if (mActiveSelectionMode == SelectionMode::Column)
return selText().length();
BufferCoord begin=blockBegin();
BufferCoord end = blockEnd();
if (begin.line == end.line)
return (end.ch - begin.ch);
int count = mDocument->getLine(begin.line-1).length()+1-begin.ch;
int lineEndCount = lineBreak().length();
count += lineEndCount;
for (int i=begin.line;i<end.line-1;i++) {
count += mDocument->getLine(i).length();
count += lineEndCount;
}
count+= end.ch-1;
return count;
}
QStringList QSynEdit::getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const QStringList QSynEdit::getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const
{ {
QStringList result; QStringList result;

View File

@ -384,6 +384,7 @@ public:
bool empty(); bool empty();
QString selText() const; QString selText() const;
int selCount() const;
QStringList getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const; QStringList getContent(BufferCoord startPos, BufferCoord endPos, SelectionMode mode) const;