forked from qt-creator/qt-creator
Fixed handling of text wrapping and a text layout corner case
Due to using QTextCursor::columnNumber() instead of QTextCursor::positionInBlock(), a lot of code would not work correctly when used with wrapped lines. In addition, there was an issue with columnNumber() returning 0 right after inserting a character before the last character of a line. Reviewed-by: mae
This commit is contained in:
@@ -107,7 +107,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
|
|||||||
QTextDocument *doc = tc.document();
|
QTextDocument *doc = tc.document();
|
||||||
QString text = textToProcess;
|
QString text = textToProcess;
|
||||||
|
|
||||||
const QString blockText = tc.block().text().mid(tc.columnNumber());
|
const QString blockText = tc.block().text().mid(tc.positionInBlock());
|
||||||
const int length = qMin(blockText.length(), textToProcess.length());
|
const int length = qMin(blockText.length(), textToProcess.length());
|
||||||
|
|
||||||
const QChar previousChar = doc->characterAt(tc.selectionEnd() - 1);
|
const QChar previousChar = doc->characterAt(tc.selectionEnd() - 1);
|
||||||
@@ -217,7 +217,7 @@ QString MatchingText::insertParagraphSeparator(const QTextCursor &tc) const
|
|||||||
if (tk[index - 1].isNot(T_LBRACE))
|
if (tk[index - 1].isNot(T_LBRACE))
|
||||||
return QString(); // nothing to do.
|
return QString(); // nothing to do.
|
||||||
|
|
||||||
const QString textBlock = tc.block().text().mid(tc.columnNumber()).trimmed();
|
const QString textBlock = tc.block().text().mid(tc.positionInBlock()).trimmed();
|
||||||
if (! textBlock.isEmpty())
|
if (! textBlock.isEmpty())
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ public:
|
|||||||
{
|
{
|
||||||
_nodes.clear();
|
_nodes.clear();
|
||||||
_line = cursor.blockNumber() + 1;
|
_line = cursor.blockNumber() + 1;
|
||||||
_column = cursor.columnNumber() + 1;
|
_column = cursor.positionInBlock() + 1;
|
||||||
accept(_doc->translationUnit()->ast());
|
accept(_doc->translationUnit()->ast());
|
||||||
return _nodes;
|
return _nodes;
|
||||||
}
|
}
|
||||||
|
@@ -747,11 +747,11 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
|||||||
// Fetch the expression's code.
|
// Fetch the expression's code.
|
||||||
CPlusPlus::ExpressionUnderCursor expressionUnderCursor;
|
CPlusPlus::ExpressionUnderCursor expressionUnderCursor;
|
||||||
expr = expressionUnderCursor(tc);
|
expr = expressionUnderCursor(tc);
|
||||||
*column = tc.columnNumber();
|
*column = tc.positionInBlock();
|
||||||
*line = tc.blockNumber();
|
*line = tc.blockNumber();
|
||||||
} else {
|
} else {
|
||||||
const QTextCursor tc = plaintext->textCursor();
|
const QTextCursor tc = plaintext->textCursor();
|
||||||
*column = tc.columnNumber();
|
*column = tc.positionInBlock();
|
||||||
*line = tc.blockNumber();
|
*line = tc.blockNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1464,8 +1464,8 @@ void FakeVimHandler::Private::updateSelection()
|
|||||||
} else if (isVisualBlockMode()) {
|
} else if (isVisualBlockMode()) {
|
||||||
QTextCursor tc = m_tc;
|
QTextCursor tc = m_tc;
|
||||||
tc.setPosition(anchorPos);
|
tc.setPosition(anchorPos);
|
||||||
int anchorColumn = tc.columnNumber();
|
int anchorColumn = tc.positionInBlock();
|
||||||
int cursorColumn = m_tc.columnNumber();
|
int cursorColumn = m_tc.positionInBlock();
|
||||||
int anchorRow = tc.blockNumber();
|
int anchorRow = tc.blockNumber();
|
||||||
int cursorRow = m_tc.blockNumber();
|
int cursorRow = m_tc.blockNumber();
|
||||||
int startColumn = qMin(anchorColumn, cursorColumn);
|
int startColumn = qMin(anchorColumn, cursorColumn);
|
||||||
|
@@ -283,7 +283,7 @@ bool ExpressionQueryWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
bool atLastLine = !(cursor.block().next().isValid());
|
bool atLastLine = !(cursor.block().next().isValid());
|
||||||
if (!atLastLine)
|
if (!atLastLine)
|
||||||
return true;
|
return true;
|
||||||
if (cursor.columnNumber() <= m_prompt.count())
|
if (cursor.positionInBlock() <= m_prompt.count())
|
||||||
return true;
|
return true;
|
||||||
cursor.deletePreviousChar();
|
cursor.deletePreviousChar();
|
||||||
m_expr = cursor.block().text().mid(m_prompt.count());
|
m_expr = cursor.block().text().mid(m_prompt.count());
|
||||||
|
@@ -102,7 +102,7 @@ public:
|
|||||||
_cursor = cursor;
|
_cursor = cursor;
|
||||||
|
|
||||||
QTextBlock block = _cursor.block();
|
QTextBlock block = _cursor.block();
|
||||||
const QString blockText = block.text().left(cursor.columnNumber());
|
const QString blockText = block.text().left(cursor.positionInBlock());
|
||||||
|
|
||||||
scanner.setScanComments(false);
|
scanner.setScanComments(false);
|
||||||
const QList<Token> tokens = scanner(blockText, startState(block));
|
const QList<Token> tokens = scanner(blockText, startState(block));
|
||||||
|
@@ -513,7 +513,7 @@ bool CodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
|
|||||||
|
|
||||||
QTextCursor tc = ed->textCursor();
|
QTextCursor tc = ed->textCursor();
|
||||||
QTextBlock block = tc.block();
|
QTextBlock block = tc.block();
|
||||||
const int column = tc.columnNumber();
|
const int column = tc.positionInBlock();
|
||||||
const int blockState = qMax(0, block.previous().userState()) & 0xff;
|
const int blockState = qMax(0, block.previous().userState()) & 0xff;
|
||||||
const QString blockText = block.text();
|
const QString blockText = block.text();
|
||||||
|
|
||||||
|
@@ -1130,7 +1130,7 @@ bool QmlJSTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, co
|
|||||||
|
|
||||||
Scanner tokenize;
|
Scanner tokenize;
|
||||||
const QList<Token> tokens = tokenize(blockText, blockState);
|
const QList<Token> tokens = tokenize(blockText, blockState);
|
||||||
const int pos = cursor.columnNumber();
|
const int pos = cursor.positionInBlock();
|
||||||
|
|
||||||
int tokenIndex = 0;
|
int tokenIndex = 0;
|
||||||
for (; tokenIndex < tokens.size(); ++tokenIndex) {
|
for (; tokenIndex < tokens.size(); ++tokenIndex) {
|
||||||
|
@@ -192,7 +192,7 @@ bool TabSettings::tabShouldIndent(const QTextDocument *document, QTextCursor cur
|
|||||||
return true;
|
return true;
|
||||||
if (document->characterAt(tc.position()).isSpace()) {
|
if (document->characterAt(tc.position()).isSpace()) {
|
||||||
tc.movePosition(QTextCursor::WordRight);
|
tc.movePosition(QTextCursor::WordRight);
|
||||||
if (tc.columnNumber() >= cursor.columnNumber()) {
|
if (tc.positionInBlock() >= cursor.positionInBlock()) {
|
||||||
if (suggestedPosition)
|
if (suggestedPosition)
|
||||||
*suggestedPosition = tc.position(); // Suggest position after whitespace
|
*suggestedPosition = tc.position(); // Suggest position after whitespace
|
||||||
if (m_tabKeyBehavior == TabLeadingWhitespaceIndents)
|
if (m_tabKeyBehavior == TabLeadingWhitespaceIndents)
|
||||||
|
Reference in New Issue
Block a user