forked from qt-creator/qt-creator
TextEditor: Add methods to query the first, last and center line
... that are currently visible on the screen. Change-Id: I6c56f376f1a34a7314584df057cf03a8e5387a08 Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -7084,6 +7084,27 @@ void TextEditorWidget::inSnippetMode(bool *active)
|
|||||||
*active = d->m_snippetOverlay->isVisible();
|
*active = d->m_snippetOverlay->isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTextBlock TextEditorWidget::blockForVisibleRow(int row) const
|
||||||
|
{
|
||||||
|
const int count = rowCount();
|
||||||
|
if (row < 0 && row >= count)
|
||||||
|
return QTextBlock();
|
||||||
|
|
||||||
|
QTextBlock block = firstVisibleBlock();
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
if (!block.isValid() || i == row)
|
||||||
|
return block;
|
||||||
|
|
||||||
|
while (block.isValid()) {
|
||||||
|
block = block.next();
|
||||||
|
if (block.isVisible())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QTextBlock();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorWidget::invokeAssist(AssistKind kind, IAssistProvider *provider)
|
void TextEditorWidget::invokeAssist(AssistKind kind, IAssistProvider *provider)
|
||||||
{
|
{
|
||||||
if (kind == QuickFix && d->m_snippetOverlay->isVisible()) {
|
if (kind == QuickFix && d->m_snippetOverlay->isVisible()) {
|
||||||
@@ -7213,6 +7234,33 @@ void TextEditorWidget::configureGenericHighlighter()
|
|||||||
updateEditorInfoBar(this);
|
updateEditorInfoBar(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TextEditorWidget::lineForVisibleRow(int row) const
|
||||||
|
{
|
||||||
|
QTextBlock block = blockForVisibleRow(row);
|
||||||
|
return block.isValid() ? block.blockNumber() : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TextEditorWidget::firstVisibleLine() const
|
||||||
|
{
|
||||||
|
return lineForVisibleRow(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TextEditorWidget::lastVisibleLine() const
|
||||||
|
{
|
||||||
|
QTextBlock block = blockForVisibleRow(rowCount() - 1);
|
||||||
|
if (!block.isValid())
|
||||||
|
block.previous();
|
||||||
|
return block.isValid() ? block.blockNumber() : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TextEditorWidget::centerVisibleLine() const
|
||||||
|
{
|
||||||
|
QTextBlock block = blockForVisibleRow(rowCount() / 2);
|
||||||
|
if (!block.isValid())
|
||||||
|
block.previous();
|
||||||
|
return block.isValid() ? block.blockNumber() : -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool TextEditorWidget::isMissingSyntaxDefinition() const
|
bool TextEditorWidget::isMissingSyntaxDefinition() const
|
||||||
{
|
{
|
||||||
return d->m_isMissingSyntaxDefinition;
|
return d->m_isMissingSyntaxDefinition;
|
||||||
|
|||||||
@@ -466,6 +466,21 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim.
|
Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim.
|
||||||
|
|
||||||
|
/*! Returns the document line number for the visible \a row.
|
||||||
|
*
|
||||||
|
* The first visible row is 0, the last visible row is rowCount() - 1.
|
||||||
|
*
|
||||||
|
* Any invalid row will return -1 as line number.
|
||||||
|
*/
|
||||||
|
int lineForVisibleRow(int row) const;
|
||||||
|
|
||||||
|
/*! Returns the first visible line of the document. */
|
||||||
|
int firstVisibleLine() const;
|
||||||
|
/*! Returns the last visible line of the document. */
|
||||||
|
int lastVisibleLine() const;
|
||||||
|
/*! Returns the line visible closest to the vertical center of the editor. */
|
||||||
|
int centerVisibleLine() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void assistFinished(); // Used in tests.
|
void assistFinished(); // Used in tests.
|
||||||
void readOnlyChanged();
|
void readOnlyChanged();
|
||||||
@@ -475,6 +490,7 @@ signals:
|
|||||||
void requestBlockUpdate(const QTextBlock &);
|
void requestBlockUpdate(const QTextBlock &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QTextBlock blockForVisibleRow(int row) const;
|
||||||
bool event(QEvent *e);
|
bool event(QEvent *e);
|
||||||
void inputMethodEvent(QInputMethodEvent *e);
|
void inputMethodEvent(QInputMethodEvent *e);
|
||||||
void keyPressEvent(QKeyEvent *e);
|
void keyPressEvent(QKeyEvent *e);
|
||||||
|
|||||||
Reference in New Issue
Block a user