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();
|
||||
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 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))
|
||||
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())
|
||||
return QString();
|
||||
|
||||
|
@@ -74,7 +74,7 @@ public:
|
||||
{
|
||||
_nodes.clear();
|
||||
_line = cursor.blockNumber() + 1;
|
||||
_column = cursor.columnNumber() + 1;
|
||||
_column = cursor.positionInBlock() + 1;
|
||||
accept(_doc->translationUnit()->ast());
|
||||
return _nodes;
|
||||
}
|
||||
|
@@ -747,11 +747,11 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
||||
// Fetch the expression's code.
|
||||
CPlusPlus::ExpressionUnderCursor expressionUnderCursor;
|
||||
expr = expressionUnderCursor(tc);
|
||||
*column = tc.columnNumber();
|
||||
*column = tc.positionInBlock();
|
||||
*line = tc.blockNumber();
|
||||
} else {
|
||||
const QTextCursor tc = plaintext->textCursor();
|
||||
*column = tc.columnNumber();
|
||||
*column = tc.positionInBlock();
|
||||
*line = tc.blockNumber();
|
||||
}
|
||||
|
||||
|
@@ -1464,8 +1464,8 @@ void FakeVimHandler::Private::updateSelection()
|
||||
} else if (isVisualBlockMode()) {
|
||||
QTextCursor tc = m_tc;
|
||||
tc.setPosition(anchorPos);
|
||||
int anchorColumn = tc.columnNumber();
|
||||
int cursorColumn = m_tc.columnNumber();
|
||||
int anchorColumn = tc.positionInBlock();
|
||||
int cursorColumn = m_tc.positionInBlock();
|
||||
int anchorRow = tc.blockNumber();
|
||||
int cursorRow = m_tc.blockNumber();
|
||||
int startColumn = qMin(anchorColumn, cursorColumn);
|
||||
|
@@ -283,7 +283,7 @@ bool ExpressionQueryWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
bool atLastLine = !(cursor.block().next().isValid());
|
||||
if (!atLastLine)
|
||||
return true;
|
||||
if (cursor.columnNumber() <= m_prompt.count())
|
||||
if (cursor.positionInBlock() <= m_prompt.count())
|
||||
return true;
|
||||
cursor.deletePreviousChar();
|
||||
m_expr = cursor.block().text().mid(m_prompt.count());
|
||||
|
@@ -102,7 +102,7 @@ public:
|
||||
_cursor = cursor;
|
||||
|
||||
QTextBlock block = _cursor.block();
|
||||
const QString blockText = block.text().left(cursor.columnNumber());
|
||||
const QString blockText = block.text().left(cursor.positionInBlock());
|
||||
|
||||
scanner.setScanComments(false);
|
||||
const QList<Token> tokens = scanner(blockText, startState(block));
|
||||
|
@@ -513,7 +513,7 @@ bool CodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
|
||||
|
||||
QTextCursor tc = ed->textCursor();
|
||||
QTextBlock block = tc.block();
|
||||
const int column = tc.columnNumber();
|
||||
const int column = tc.positionInBlock();
|
||||
const int blockState = qMax(0, block.previous().userState()) & 0xff;
|
||||
const QString blockText = block.text();
|
||||
|
||||
|
@@ -1130,7 +1130,7 @@ bool QmlJSTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, co
|
||||
|
||||
Scanner tokenize;
|
||||
const QList<Token> tokens = tokenize(blockText, blockState);
|
||||
const int pos = cursor.columnNumber();
|
||||
const int pos = cursor.positionInBlock();
|
||||
|
||||
int tokenIndex = 0;
|
||||
for (; tokenIndex < tokens.size(); ++tokenIndex) {
|
||||
|
@@ -192,7 +192,7 @@ bool TabSettings::tabShouldIndent(const QTextDocument *document, QTextCursor cur
|
||||
return true;
|
||||
if (document->characterAt(tc.position()).isSpace()) {
|
||||
tc.movePosition(QTextCursor::WordRight);
|
||||
if (tc.columnNumber() >= cursor.columnNumber()) {
|
||||
if (tc.positionInBlock() >= cursor.positionInBlock()) {
|
||||
if (suggestedPosition)
|
||||
*suggestedPosition = tc.position(); // Suggest position after whitespace
|
||||
if (m_tabKeyBehavior == TabLeadingWhitespaceIndents)
|
||||
|
Reference in New Issue
Block a user