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

View File

@ -4517,6 +4517,27 @@ QString QSynEdit::selText() const
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 result;

View File

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