void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index) { QModelIndex sourceIndex = m_filterModel->mapToSource(index); AST::SourceLocation location = m_editor->outlineModel()->sourceLocation(sourceIndex); if (!location.isValid()) return; const QTextBlock lastBlock = m_editor->document()->lastBlock(); const uint textLength = lastBlock.position() + lastBlock.length(); if (location.offset >= textLength) return; Core::EditorManager *editorManager = Core::EditorManager::instance(); editorManager->cutForwardNavigationHistory(); editorManager->addCurrentPositionToNavigationHistory(); QTextCursor textCursor = m_editor->textCursor(); m_blockCursorSync = true; textCursor.setPosition(location.offset); m_editor->setTextCursor(textCursor); m_editor->centerCursor(); m_editor->setFocus(); m_blockCursorSync = false; }
void FindTrCalls::processComments(quint32 offset, bool flush) { for (; !m_todo.isEmpty(); m_todo.removeFirst()) { AST::SourceLocation loc = m_todo.first(); if (! flush && (loc.begin() >= offset)) break; processComment(loc); } }
void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/) { QModelIndex index = m_outlineCombo->view()->currentIndex(); AST::SourceLocation location = m_qmlJsEditorDocument->outlineModel()->sourceLocation(index); if (!location.isValid()) return; EditorManager::cutForwardNavigationHistory(); EditorManager::addCurrentPositionToNavigationHistory(); QTextCursor cursor = textCursor(); cursor.setPosition(location.offset); setTextCursor(cursor); setFocus(); }
void FindTrCalls::processComment(const AST::SourceLocation &loc) { if (!loc.length) return; const QStringRef commentStr = engine->midRef(loc.begin(), loc.length); const QChar *chars = commentStr.constData(); const int length = commentStr.length(); // Try to match the logic of the C++ parser. if (*chars == QLatin1Char(':') && chars[1].isSpace()) { if (!extracomment.isEmpty()) extracomment += QLatin1Char(' '); extracomment += QString(chars+2, length-2); } else if (*chars == QLatin1Char('=') && chars[1].isSpace()) { msgid = QString(chars+2, length-2).simplified(); } else if (*chars == QLatin1Char('~') && chars[1].isSpace()) { QString text = QString(chars+2, length-2).trimmed(); int k = text.indexOf(QLatin1Char(' ')); if (k > -1) extra.insert(text.left(k), text.mid(k + 1).trimmed()); } else if (*chars == QLatin1Char('%') && chars[1].isSpace()) { sourcetext.reserve(sourcetext.length() + length-2); ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length(); int p = 2, c; forever { if (p >= length) break; c = chars[p++].unicode(); if (std::isspace(c)) continue; if (c != '"') { yyMsg(loc.startLine) << qPrintable(LU::tr("Unexpected character in meta string\n")); break; } forever { if (p >= length) { whoops: yyMsg(loc.startLine) << qPrintable(LU::tr("Unterminated meta string\n")); break; } c = chars[p++].unicode(); if (c == '"') break; if (c == '\\') { if (p >= length) goto whoops; c = chars[p++].unicode(); if (c == '\r' || c == '\n') goto whoops; *ptr++ = '\\'; } *ptr++ = c; } } sourcetext.resize(ptr - (ushort *)sourcetext.data()); } else {
QString SimpleAbstractStreamReader::textAt(const AST::SourceLocation &from, const AST::SourceLocation &to) { return m_source.mid(from.offset, to.end() - from.begin()); }
bool QmlJSRefactoringFile::isCursorOn(AST::SourceLocation loc) const { const unsigned pos = cursor().position(); return pos >= loc.begin() && pos <= loc.end(); }