forked from qt-creator/qt-creator
TextEditors: Separate away methods that actually work on a document
Introduces ITextEditorDocument. This is part of a more general "use documents instead of editors whereever possible". It will allow to move to e.g. ITextEditor::openedTextDocumentContents() instead of ITextEditor::openedTextEditorsContents(). Change-Id: I5ebceaa257a0d2c3e8ac4ac51b9b08b6faa42487 Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -213,7 +213,7 @@ void CodepasterPlugin::postEditor()
|
||||
if (ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor)) {
|
||||
data = textEditor->selectedText();
|
||||
if (data.isEmpty())
|
||||
data = textEditor->contents();
|
||||
data = textEditor->textDocument()->contents();
|
||||
mimeType = textEditor->document()->mimeType();
|
||||
}
|
||||
}
|
||||
|
@@ -1482,10 +1482,10 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
const Snapshot &snapshot = m_modelManager->snapshot();
|
||||
|
||||
QTextCursor tc = cursor;
|
||||
QChar ch = characterAt(tc.position());
|
||||
QChar ch = document()->characterAt(tc.position());
|
||||
while (ch.isLetterOrNumber() || ch == QLatin1Char('_')) {
|
||||
tc.movePosition(QTextCursor::NextCharacter);
|
||||
ch = characterAt(tc.position());
|
||||
ch = document()->characterAt(tc.position());
|
||||
}
|
||||
|
||||
// Initially try to macth decl/def. For this we need the semantic doc with the AST.
|
||||
@@ -1493,9 +1493,9 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
&& m_lastSemanticInfo.doc->translationUnit()
|
||||
&& m_lastSemanticInfo.doc->translationUnit()->ast()) {
|
||||
int pos = tc.position();
|
||||
while (characterAt(pos).isSpace())
|
||||
while (document()->characterAt(pos).isSpace())
|
||||
++pos;
|
||||
if (characterAt(pos) == QLatin1Char('(')) {
|
||||
if (document()->characterAt(pos) == QLatin1Char('(')) {
|
||||
link = attemptFuncDeclDef(cursor, m_lastSemanticInfo.doc, snapshot);
|
||||
if (link.hasValidLinkText())
|
||||
return link;
|
||||
@@ -1626,7 +1626,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
QString expression = expressionUnderCursor(tc);
|
||||
|
||||
for (int pos = tc.position();; ++pos) {
|
||||
const QChar ch = characterAt(pos);
|
||||
const QChar ch = document()->characterAt(pos);
|
||||
if (ch.isSpace())
|
||||
continue;
|
||||
else {
|
||||
@@ -2488,9 +2488,9 @@ bool CPPEditorWidget::handleDocumentationComment(QKeyEvent *e)
|
||||
bool CPPEditorWidget::isStartOfDoxygenComment(const QTextCursor &cursor) const
|
||||
{
|
||||
const int pos = cursor.position();
|
||||
QString comment = QString(characterAt(pos - 3))
|
||||
+ characterAt(pos - 2)
|
||||
+ characterAt(pos - 1);
|
||||
QString comment = QString(document()->characterAt(pos - 3))
|
||||
+ document()->characterAt(pos - 2)
|
||||
+ document()->characterAt(pos - 1);
|
||||
|
||||
if ((comment == QLatin1String("/**"))
|
||||
|| (comment == QLatin1String("/*!"))
|
||||
|
@@ -242,7 +242,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
|
||||
|
||||
// If the function doesn't return anything, automatically place the semicolon,
|
||||
// unless we're doing a scope completion (then it might be function definition).
|
||||
const QChar characterAtCursor = editor->characterAt(editor->position());
|
||||
const QChar characterAtCursor = editor->textDocument()->characterAt(editor->position());
|
||||
bool endWithSemicolon = m_typedChar == QLatin1Char(';')
|
||||
|| (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON);
|
||||
const QChar semicolon = m_typedChar.isNull() ? QLatin1Char(';') : m_typedChar;
|
||||
@@ -260,7 +260,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
|
||||
m_typedChar = QChar();
|
||||
}
|
||||
} else if (autoParenthesesEnabled) {
|
||||
const QChar lookAhead = editor->characterAt(editor->position() + 1);
|
||||
const QChar lookAhead = editor->textDocument()->characterAt(editor->position() + 1);
|
||||
if (MatchingText::shouldInsertMatchingText(lookAhead)) {
|
||||
extraChars += QLatin1Char(')');
|
||||
--cursorOffset;
|
||||
@@ -299,7 +299,8 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
|
||||
// Determine the length of characters that should just be kept on the editor, but do
|
||||
// not consider content that ends as an identifier (which could be undesired).
|
||||
const int lineEnd = editor->position(TextEditor::ITextEditor::EndOfLine);
|
||||
const QString inEditor = editor->textAt(editor->position(), lineEnd - editor->position());
|
||||
const QString inEditor = editor->textDocument()->textAt(editor->position(),
|
||||
lineEnd - editor->position());
|
||||
int preserveLength = 0;
|
||||
if (!inEditor.isEmpty()) {
|
||||
preserveLength = toInsert.length() - (editor->position() - basePosition);
|
||||
@@ -317,7 +318,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
|
||||
|
||||
for (int i = 0; i < extraChars.length(); ++i) {
|
||||
const QChar a = extraChars.at(i);
|
||||
const QChar b = editor->characterAt(editor->position() + i + preserveLength);
|
||||
const QChar b = editor->textDocument()->characterAt(editor->position() + i + preserveLength);
|
||||
if (a == b)
|
||||
++extraLength;
|
||||
else
|
||||
|
@@ -73,7 +73,7 @@ QString CppEditorSupport::contents()
|
||||
if (! _textEditor)
|
||||
return QString();
|
||||
else if (! _cachedContents.isEmpty())
|
||||
_cachedContents = _textEditor->contents();
|
||||
_cachedContents = _textEditor->textDocument()->contents();
|
||||
|
||||
return _cachedContents;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ void CppEditorSupport::updateDocumentNow()
|
||||
_updateDocumentTimer->stop();
|
||||
|
||||
QStringList sourceFiles(_textEditor->document()->fileName());
|
||||
_cachedContents = _textEditor->contents();
|
||||
_cachedContents = _textEditor->textDocument()->contents();
|
||||
_documentParser = _modelManager->updateSourceFiles(sourceFiles);
|
||||
}
|
||||
}
|
||||
|
@@ -685,7 +685,7 @@ static bool currentTextEditorPosition(ContextData *data)
|
||||
data->fileName = document->fileName();
|
||||
if (textEditor->property("DisassemblerView").toBool()) {
|
||||
int lineNumber = textEditor->currentLine();
|
||||
QString line = textEditor->contents()
|
||||
QString line = textEditor->textDocument()->contents()
|
||||
.section(QLatin1Char('\n'), lineNumber - 1, lineNumber - 1);
|
||||
data->address = DisassemblerLine::addressFromDisassemblyLine(line);
|
||||
} else {
|
||||
@@ -1845,7 +1845,7 @@ void DebuggerPluginPrivate::requestContextMenu(ITextEditor *editor,
|
||||
const QString fileName = editor->document()->fileName();
|
||||
if (editor->property("DisassemblerView").toBool()) {
|
||||
args.fileName = fileName;
|
||||
QString line = editor->contents()
|
||||
QString line = editor->textDocument()->contents()
|
||||
.section(QLatin1Char('\n'), lineNumber - 1, lineNumber - 1);
|
||||
BreakpointResponse needle;
|
||||
needle.type = BreakpointByAddress;
|
||||
@@ -1959,7 +1959,7 @@ void DebuggerPluginPrivate::toggleBreakpoint()
|
||||
QTC_ASSERT(textEditor, return);
|
||||
const int lineNumber = textEditor->currentLine();
|
||||
if (textEditor->property("DisassemblerView").toBool()) {
|
||||
QString line = textEditor->contents()
|
||||
QString line = textEditor->textDocument()->contents()
|
||||
.section(QLatin1Char('\n'), lineNumber - 1, lineNumber - 1);
|
||||
quint64 address = DisassemblerLine::addressFromDisassemblyLine(line);
|
||||
toggleBreakpointByAddress(address);
|
||||
@@ -2016,7 +2016,7 @@ void DebuggerPluginPrivate::requestMark(ITextEditor *editor,
|
||||
return;
|
||||
|
||||
if (editor->property("DisassemblerView").toBool()) {
|
||||
QString line = editor->contents()
|
||||
QString line = editor->textDocument()->contents()
|
||||
.section(QLatin1Char('\n'), lineNumber - 1, lineNumber - 1);
|
||||
quint64 address = DisassemblerLine::addressFromDisassemblyLine(line);
|
||||
toggleBreakpointByAddress(address);
|
||||
|
@@ -340,7 +340,7 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
||||
QTextCursor tc(plaintext->document());
|
||||
tc.setPosition(pos);
|
||||
|
||||
const QChar ch = editor->characterAt(pos);
|
||||
const QChar ch = editor->textDocument()->characterAt(pos);
|
||||
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
|
||||
tc.movePosition(QTextCursor::EndOfWord);
|
||||
|
||||
|
@@ -340,7 +340,7 @@ static Document::Ptr addDefinition(const Snapshot &docTable,
|
||||
//! \todo use the InsertionPointLocator to insert at the correct place.
|
||||
// (we'll have to extend that class first to do definition insertions)
|
||||
|
||||
const QString contents = editable->contents();
|
||||
const QString contents = editable->textDocument()->contents();
|
||||
int column;
|
||||
editable->convertPosition(contents.length(), line, &column);
|
||||
editable->gotoLine(*line, column);
|
||||
|
@@ -248,7 +248,7 @@ void GLSLTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
|
||||
QString GLSLTextEditorWidget::wordUnderCursor() const
|
||||
{
|
||||
QTextCursor tc = textCursor();
|
||||
const QChar ch = characterAt(tc.position() - 1);
|
||||
const QChar ch = document()->characterAt(tc.position() - 1);
|
||||
// make sure that we're not at the start of the next word.
|
||||
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
|
||||
tc.movePosition(QTextCursor::Left);
|
||||
|
@@ -374,7 +374,7 @@ void QmlJSAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
|
||||
int replacedLength = 0;
|
||||
for (int i = 0; i < replaceable.length(); ++i) {
|
||||
const QChar a = replaceable.at(i);
|
||||
const QChar b = editor->characterAt(editor->position() + i);
|
||||
const QChar b = editor->textDocument()->characterAt(editor->position() + i);
|
||||
if (a == b)
|
||||
++replacedLength;
|
||||
else
|
||||
|
@@ -1001,7 +1001,7 @@ void QmlJSTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
|
||||
QString QmlJSTextEditorWidget::wordUnderCursor() const
|
||||
{
|
||||
QTextCursor tc = textCursor();
|
||||
const QChar ch = characterAt(tc.position() - 1);
|
||||
const QChar ch = document()->characterAt(tc.position() - 1);
|
||||
// make sure that we're not at the start of the next word.
|
||||
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
|
||||
tc.movePosition(QTextCursor::Left);
|
||||
|
@@ -214,7 +214,7 @@ void HoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
|
||||
i = j = pos;
|
||||
QString nameAtt;
|
||||
for (;;) {
|
||||
QChar c = qmlEditor->characterAt(j);
|
||||
QChar c = qmlEditor->document()->characterAt(j);
|
||||
if (!c.isLetterOrNumber()) break;
|
||||
nameAtt.append(c);
|
||||
++j;
|
||||
@@ -222,7 +222,7 @@ void HoverHandler::identifyMatch(TextEditor::ITextEditor *editor, int pos)
|
||||
QStringList qName;
|
||||
while (i>0) {
|
||||
--i;
|
||||
QChar c = qmlEditor->characterAt(i);
|
||||
QChar c = qmlEditor->document()->characterAt(i);
|
||||
if (c.isLetterOrNumber()) {
|
||||
nameAtt.prepend(c);
|
||||
} else if (c == QLatin1Char('.')) {
|
||||
|
@@ -312,7 +312,7 @@ void Qt4Manager::addLibrary(const QString &fileName, ProFileEditorWidget *editor
|
||||
// add extra \n in case the last line is not empty
|
||||
int line, column;
|
||||
editable->convertPosition(endOfDoc, &line, &column);
|
||||
if (!editable->textAt(endOfDoc - column, column).simplified().isEmpty())
|
||||
if (!editable->textDocument()->textAt(endOfDoc - column, column).simplified().isEmpty())
|
||||
snippet = QLatin1Char('\n') + snippet;
|
||||
|
||||
editable->insert(snippet);
|
||||
|
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "basetextdocumentlayout.h"
|
||||
#include "basetexteditor.h"
|
||||
#include "convenience.h"
|
||||
#include "typingsettings.h"
|
||||
#include "storagesettings.h"
|
||||
#include "tabsettings.h"
|
||||
@@ -90,6 +91,21 @@ BaseTextDocument::~BaseTextDocument()
|
||||
delete d;
|
||||
}
|
||||
|
||||
QString BaseTextDocument::contents() const
|
||||
{
|
||||
return document()->toPlainText();
|
||||
}
|
||||
|
||||
QString BaseTextDocument::textAt(int pos, int length) const
|
||||
{
|
||||
return Convenience::textAt(QTextCursor(document()), pos, length);
|
||||
}
|
||||
|
||||
QChar BaseTextDocument::characterAt(int pos) const
|
||||
{
|
||||
return document()->characterAt(pos);
|
||||
}
|
||||
|
||||
QString BaseTextDocument::mimeType() const
|
||||
{
|
||||
return d->m_mimeType;
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "texteditor_global.h"
|
||||
|
||||
#include <coreplugin/textdocument.h>
|
||||
#include "itexteditor.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextCursor;
|
||||
@@ -49,7 +49,7 @@ class ExtraEncodingSettings;
|
||||
class SyntaxHighlighter;
|
||||
class BaseTextDocumentPrivate;
|
||||
|
||||
class TEXTEDITOR_EXPORT BaseTextDocument : public Core::TextDocument
|
||||
class TEXTEDITOR_EXPORT BaseTextDocument : public ITextEditorDocument
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -57,6 +57,11 @@ public:
|
||||
BaseTextDocument();
|
||||
virtual ~BaseTextDocument();
|
||||
|
||||
// ITextEditorDocument
|
||||
QString contents() const;
|
||||
QString textAt(int pos, int length) const;
|
||||
QChar characterAt(int pos) const;
|
||||
|
||||
void setTypingSettings(const TypingSettings &typingSettings);
|
||||
void setStorageSettings(const StorageSettings &storageSettings);
|
||||
void setTabSettings(const TabSettings &tabSettings);
|
||||
|
@@ -707,7 +707,7 @@ void BaseTextEditorWidget::editorContentsChange(int position, int charsRemoved,
|
||||
if (doc->isRedoAvailable())
|
||||
emit editor()->contentsChangedBecauseOfUndo();
|
||||
|
||||
if (charsAdded != 0 && characterAt(position + charsAdded - 1).isPrint())
|
||||
if (charsAdded != 0 && document()->characterAt(position + charsAdded - 1).isPrint())
|
||||
d->m_assistRelevantContentAdded = true;
|
||||
}
|
||||
|
||||
@@ -1241,7 +1241,7 @@ bool BaseTextEditorWidget::camelCaseLeft(QTextCursor &cursor, QTextCursor::MoveM
|
||||
return false;
|
||||
|
||||
forever {
|
||||
QChar c = characterAt(cursor.position());
|
||||
QChar c = document()->characterAt(cursor.position());
|
||||
Input input = Input_other;
|
||||
if (c.isUpper())
|
||||
input = Input_U;
|
||||
@@ -1348,7 +1348,7 @@ bool BaseTextEditorWidget::camelCaseRight(QTextCursor &cursor, QTextCursor::Move
|
||||
};
|
||||
|
||||
forever {
|
||||
QChar c = characterAt(cursor.position());
|
||||
QChar c = document()->characterAt(cursor.position());
|
||||
Input input = Input_other;
|
||||
if (c.isUpper())
|
||||
input = Input_U;
|
||||
@@ -2101,7 +2101,7 @@ void BaseTextEditorWidget::gotoLine(int line, int column)
|
||||
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, column);
|
||||
} else {
|
||||
int pos = cursor.position();
|
||||
while (characterAt(pos).category() == QChar::Separator_Space) {
|
||||
while (document()->characterAt(pos).category() == QChar::Separator_Space) {
|
||||
++pos;
|
||||
}
|
||||
cursor.setPosition(pos);
|
||||
@@ -2148,11 +2148,6 @@ void BaseTextEditorWidget::convertPosition(int pos, int *line, int *column) cons
|
||||
Convenience::convertPosition(document(), pos, line, column);
|
||||
}
|
||||
|
||||
QChar BaseTextEditorWidget::characterAt(int pos) const
|
||||
{
|
||||
return document()->characterAt(pos);
|
||||
}
|
||||
|
||||
bool BaseTextEditorWidget::event(QEvent *e)
|
||||
{
|
||||
#if QT_VERSION >= 0x050000
|
||||
@@ -4752,14 +4747,14 @@ void BaseTextEditorWidget::handleHomeKey(bool anchor)
|
||||
|
||||
const int initpos = cursor.position();
|
||||
int pos = cursor.block().position();
|
||||
QChar character = characterAt(pos);
|
||||
QChar character = document()->characterAt(pos);
|
||||
const QLatin1Char tab = QLatin1Char('\t');
|
||||
|
||||
while (character == tab || character.category() == QChar::Separator_Space) {
|
||||
++pos;
|
||||
if (pos == initpos)
|
||||
break;
|
||||
character = characterAt(pos);
|
||||
character = document()->characterAt(pos);
|
||||
}
|
||||
|
||||
// Go to the start of the block when we're already at the start of the text
|
||||
@@ -4834,7 +4829,7 @@ void BaseTextEditorWidget::handleBackspaceKey()
|
||||
}
|
||||
}
|
||||
} else if (typingSettings.m_smartBackspaceBehavior == TypingSettings::BackspaceUnindents) {
|
||||
const QChar &c = characterAt(pos - 1);
|
||||
const QChar &c = document()->characterAt(pos - 1);
|
||||
if (!(c == QLatin1Char(' ') || c == QLatin1Char('\t'))) {
|
||||
if (cursorWithinSnippet)
|
||||
cursor.beginEditBlock();
|
||||
@@ -5241,7 +5236,7 @@ void BaseTextEditorWidget::_q_matchParentheses()
|
||||
QPalette pal;
|
||||
pal.setBrush(QPalette::Text, d->m_matchFormat.foreground());
|
||||
pal.setBrush(QPalette::Base, d->m_matchFormat.background());
|
||||
d->m_animator->setData(font(), pal, characterAt(d->m_animator->position()));
|
||||
d->m_animator->setData(font(), pal, document()->characterAt(d->m_animator->position()));
|
||||
connect(d->m_animator, SIGNAL(updateRequest(int,QPointF,QRectF)),
|
||||
this, SLOT(_q_animateUpdate(int,QPointF,QRectF)));
|
||||
}
|
||||
@@ -6334,11 +6329,6 @@ void BaseTextEditor::insertExtraToolBarWidget(BaseTextEditor::Side side,
|
||||
m_toolBar->insertWidget(m_toolBar->actions().first(), widget);
|
||||
}
|
||||
|
||||
int BaseTextEditor::find(const QString &) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BaseTextEditor::currentLine() const
|
||||
{
|
||||
return e->textCursor().blockNumber() + 1;
|
||||
@@ -6370,11 +6360,6 @@ QRect BaseTextEditor::cursorRect(int pos) const
|
||||
return result;
|
||||
}
|
||||
|
||||
QString BaseTextEditor::contents() const
|
||||
{
|
||||
return e->toPlainText();
|
||||
}
|
||||
|
||||
QString BaseTextEditor::selectedText() const
|
||||
{
|
||||
if (e->textCursor().hasSelection())
|
||||
@@ -6382,11 +6367,6 @@ QString BaseTextEditor::selectedText() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString BaseTextEditor::textAt(int pos, int length) const
|
||||
{
|
||||
return Convenience::textAt(e->textCursor(), pos, length);
|
||||
}
|
||||
|
||||
void BaseTextEditor::remove(int length)
|
||||
{
|
||||
QTextCursor tc = e->textCursor();
|
||||
|
@@ -158,8 +158,6 @@ public:
|
||||
BaseTextEditor *editor() const;
|
||||
ITextMarkable *markableInterface() const;
|
||||
|
||||
QChar characterAt(int pos) const;
|
||||
|
||||
void print(QPrinter *);
|
||||
|
||||
void setSuggestedFileName(const QString &suggestedFileName);
|
||||
@@ -621,8 +619,7 @@ public:
|
||||
friend class BaseTextEditorWidget;
|
||||
BaseTextEditorWidget *editorWidget() const { return e; }
|
||||
|
||||
// EditorInterface
|
||||
//QWidget *widget() { return e; }
|
||||
// IEditor
|
||||
Core::IDocument * document() { return e->editorDocument(); }
|
||||
bool createNew(const QString &contents) { return e->createNew(contents); }
|
||||
bool open(QString *errorString, const QString &fileName, const QString &realFileName) { return e->open(errorString, fileName, realFileName); }
|
||||
@@ -637,7 +634,6 @@ public:
|
||||
void insertExtraToolBarWidget(Side side, QWidget *widget);
|
||||
|
||||
// ITextEditor
|
||||
int find(const QString &string) const;
|
||||
int currentLine() const;
|
||||
int currentColumn() const;
|
||||
void gotoLine(int line, int column = 0) { e->gotoLine(line, column); }
|
||||
@@ -650,10 +646,7 @@ public:
|
||||
{ e->convertPosition(pos, line, column); }
|
||||
QRect cursorRect(int pos = -1) const;
|
||||
|
||||
QString contents() const;
|
||||
QString selectedText() const;
|
||||
QString textAt(int pos, int length) const;
|
||||
inline QChar characterAt(int pos) const { return e->characterAt(pos); }
|
||||
|
||||
inline ITextMarkable *markableInterface() { return e->markableInterface(); }
|
||||
|
||||
|
@@ -195,8 +195,9 @@ void CodeAssistantPrivate::invoke(AssistKind kind, IAssistProvider *provider)
|
||||
if (isDisplayingProposal() && m_assistKind == kind && !m_proposal->isFragile()) {
|
||||
m_proposalWidget->setReason(ExplicitlyInvoked);
|
||||
m_proposalWidget->updateProposal(
|
||||
m_textEditor->textAt(m_proposal->basePosition(),
|
||||
m_textEditor->position() - m_proposal->basePosition()));
|
||||
m_textEditor->textDocument()->textAt(
|
||||
m_proposal->basePosition(),
|
||||
m_textEditor->position() - m_proposal->basePosition()));
|
||||
} else {
|
||||
destroyContext();
|
||||
requestProposal(ExplicitlyInvoked, kind, provider);
|
||||
@@ -334,7 +335,7 @@ void CodeAssistantPrivate::displayProposal(IAssistProposal *newProposal, AssistR
|
||||
m_proposalWidget->setIsSynchronized(false);
|
||||
else
|
||||
m_proposalWidget->setIsSynchronized(true);
|
||||
m_proposalWidget->showProposal(m_textEditor->textAt(
|
||||
m_proposalWidget->showProposal(m_textEditor->textDocument()->textAt(
|
||||
m_proposal->basePosition(),
|
||||
m_textEditor->position() - m_proposal->basePosition()));
|
||||
}
|
||||
@@ -393,7 +394,7 @@ CompletionAssistProvider *CodeAssistantPrivate::identifyActivationSequence()
|
||||
const int length = provider->activationCharSequenceLength();
|
||||
if (length == 0)
|
||||
continue;
|
||||
QString sequence = m_textEditor->textAt(m_textEditor->position() - length, length);
|
||||
QString sequence = m_textEditor->textDocument()->textAt(m_textEditor->position() - length, length);
|
||||
// In pretty much all cases the sequence will have the appropriate length. Only in the
|
||||
// case of typing the very first characters in the document for providers that request a
|
||||
// length greater than 1 (currently only C++, which specifies 3), the sequence needs to
|
||||
@@ -417,7 +418,7 @@ void CodeAssistantPrivate::notifyChange()
|
||||
destroyContext();
|
||||
} else {
|
||||
m_proposalWidget->updateProposal(
|
||||
m_textEditor->textAt(m_proposal->basePosition(),
|
||||
m_textEditor->textDocument()->textAt(m_proposal->basePosition(),
|
||||
m_textEditor->position() - m_proposal->basePosition()));
|
||||
if (m_proposal->isFragile())
|
||||
startAutomaticProposalTimer();
|
||||
|
@@ -109,10 +109,10 @@ void KeywordsAssistProposalItem::applyContextualContent(TextEditor::BaseTextEdit
|
||||
int cursorOffset = 0;
|
||||
if (m_keywords.isFunction(toInsert) && settings.m_autoInsertBrackets) {
|
||||
if (settings.m_spaceAfterFunctionName) {
|
||||
if (editor->textAt(editor->position(), 2) == QLatin1String(" (")) {
|
||||
if (editor->textDocument()->textAt(editor->position(), 2) == QLatin1String(" (")) {
|
||||
cursorOffset = 2;
|
||||
} else if (editor->characterAt(editor->position()) == QLatin1Char('(')
|
||||
|| editor->characterAt(editor->position()) == QLatin1Char(' ')) {
|
||||
} else if (editor->textDocument()->characterAt(editor->position()) == QLatin1Char('(')
|
||||
|| editor->textDocument()->characterAt(editor->position()) == QLatin1Char(' ')) {
|
||||
replaceLength += 1;
|
||||
toInsert += QLatin1String(" (");
|
||||
} else {
|
||||
@@ -120,7 +120,7 @@ void KeywordsAssistProposalItem::applyContextualContent(TextEditor::BaseTextEdit
|
||||
cursorOffset = -1;
|
||||
}
|
||||
} else {
|
||||
if (editor->characterAt(editor->position()) == QLatin1Char('(')) {
|
||||
if (editor->textDocument()->characterAt(editor->position()) == QLatin1Char('(')) {
|
||||
cursorOffset = 1;
|
||||
} else {
|
||||
toInsert += QLatin1String("()");
|
||||
|
@@ -35,6 +35,11 @@
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
ITextEditorDocument::ITextEditorDocument(QObject *parent)
|
||||
: Core::TextDocument(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QMap<QString, QString> ITextEditor::openedTextEditorsContents()
|
||||
{
|
||||
QMap<QString, QString> workingCopy;
|
||||
@@ -43,7 +48,7 @@ QMap<QString, QString> ITextEditor::openedTextEditorsContents()
|
||||
if (!textEditor)
|
||||
continue;
|
||||
QString fileName = textEditor->document()->fileName();
|
||||
workingCopy[fileName] = textEditor->contents();
|
||||
workingCopy[fileName] = textEditor->textDocument()->contents();
|
||||
}
|
||||
return workingCopy;
|
||||
}
|
||||
@@ -60,3 +65,9 @@ QMap<QString, QTextCodec *> TextEditor::ITextEditor::openedTextEditorsEncodings(
|
||||
}
|
||||
return workingCopy;
|
||||
}
|
||||
|
||||
|
||||
ITextEditorDocument *ITextEditor::textDocument()
|
||||
{
|
||||
return qobject_cast<ITextEditorDocument *>(document());
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "itextmark.h"
|
||||
|
||||
#include <coreplugin/textdocument.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
#include <QMap>
|
||||
@@ -54,6 +55,17 @@ namespace Utils {
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
class TEXTEDITOR_EXPORT ITextEditorDocument : public Core::TextDocument
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ITextEditorDocument(QObject *parent = 0);
|
||||
|
||||
virtual QString contents() const = 0;
|
||||
virtual QString textAt(int pos, int length) const = 0;
|
||||
virtual QChar characterAt(int pos) const = 0;
|
||||
};
|
||||
|
||||
class TEXTEDITOR_EXPORT ITextEditor : public Core::IEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -68,7 +80,8 @@ public:
|
||||
|
||||
ITextEditor() {}
|
||||
|
||||
virtual int find(const QString &string) const = 0;
|
||||
virtual ITextEditorDocument *textDocument();
|
||||
|
||||
/*! Returns the position at \a posOp in characters from the beginning of the document */
|
||||
virtual int position(PositionOperation posOp = Current, int at = -1) const = 0;
|
||||
/*! Converts the \a pos in characters from beginning of document to \a line and \a column */
|
||||
@@ -80,10 +93,7 @@ public:
|
||||
/*! Returns the amount of visible lines (in characters) in the editor */
|
||||
virtual int rowCount() const = 0;
|
||||
|
||||
virtual QString contents() const = 0;
|
||||
virtual QString selectedText() const = 0;
|
||||
virtual QString textAt(int pos, int length) const = 0;
|
||||
virtual QChar characterAt(int pos) const = 0;
|
||||
|
||||
/*! Removes \a length characters to the right of the cursor. */
|
||||
virtual void remove(int length) = 0;
|
||||
|
Reference in New Issue
Block a user