Commit 127d3b96 authored by hjk's avatar hjk

TextEditor: Move base of operation from Editor to *Widget

One less level of indirection

Change-Id: I4777bd7d54e572f36a490aeb747a8e0f89599049
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 0feb80fa
......@@ -263,10 +263,10 @@ public:
{}
virtual bool isCorrective() const { return m_replaceDotForArrow; }
virtual void makeCorrection(BaseTextEditor *editor)
virtual void makeCorrection(BaseTextEditorWidget *editorWidget)
{
editor->setCursorPosition(basePosition() - 1);
editor->replace(1, QLatin1String("->"));
editorWidget->setCursorPosition(basePosition() - 1);
editorWidget->replace(1, QLatin1String("->"));
moveBasePosition(1);
}
......@@ -351,7 +351,7 @@ public:
ClangAssistProposalItem() {}
virtual bool prematurelyApplies(const QChar &c) const;
virtual void applyContextualContent(TextEditor::BaseTextEditor *editor,
virtual void applyContextualContent(TextEditor::BaseTextEditorWidget *editorWidget,
int basePosition) const;
void keepCompletionOperator(unsigned compOp) { m_completionOperator = compOp; }
......@@ -410,7 +410,7 @@ bool ClangAssistProposalItem::prematurelyApplies(const QChar &typedChar) const
return ok;
}
void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *editor,
void ClangAssistProposalItem::applyContextualContent(BaseTextEditorWidget *editorWidget,
int basePosition) const
{
const CodeCompletionResult ccr = originalItem();
......@@ -455,7 +455,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
// 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 = editorWidget->characterAt(editorWidget->position());
bool endWithSemicolon = m_typedChar == QLatin1Char(';')/*
|| (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON)*/; //###
const QChar semicolon = m_typedChar.isNull() ? QLatin1Char(';') : m_typedChar;
......@@ -473,7 +473,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
m_typedChar = QChar();
}
} else if (autoParenthesesEnabled) {
const QChar lookAhead = editor->characterAt(editor->position() + 1);
const QChar lookAhead = editorWidget->characterAt(editorWidget->position() + 1);
if (MatchingText::shouldInsertMatchingText(lookAhead)) {
extraChars += QLatin1Char(')');
--cursorOffset;
......@@ -508,12 +508,12 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
}
// Avoid inserting characters that are already there
const int endsPosition = editor->position(TextEditor::BaseTextEditor::EndOfLine);
const QString existingText = editor->textAt(editor->position(), endsPosition - editor->position());
const int endsPosition = editorWidget->position(TextEditor::BaseTextEditor::EndOfLine);
const QString existingText = editorWidget->textAt(editorWidget->position(), endsPosition - editorWidget->position());
int existLength = 0;
if (!existingText.isEmpty()) {
// Calculate the exist length in front of the extra chars
existLength = toInsert.length() - (editor->position() - basePosition);
existLength = toInsert.length() - (editorWidget->position() - basePosition);
while (!existingText.startsWith(toInsert.right(existLength))) {
if (--existLength == 0)
break;
......@@ -521,7 +521,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
}
for (int i = 0; i < extraChars.length(); ++i) {
const QChar a = extraChars.at(i);
const QChar b = editor->characterAt(editor->position() + i + existLength);
const QChar b = editorWidget->characterAt(editorWidget->position() + i + existLength);
if (a == b)
++extraLength;
else
......@@ -530,11 +530,11 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
toInsert += extraChars;
// Insert the remainder of the name
const int length = editor->position() - basePosition + existLength + extraLength;
editor->setCursorPosition(basePosition);
editor->replace(length, toInsert);
const int length = editorWidget->position() - basePosition + existLength + extraLength;
editorWidget->setCursorPosition(basePosition);
editorWidget->replace(length, toInsert);
if (cursorOffset)
editor->setCursorPosition(editor->position() + cursorOffset);
editorWidget->setCursorPosition(editorWidget->position() + cursorOffset);
}
bool ClangCompletionAssistInterface::objcEnabled() const
......
......@@ -39,7 +39,7 @@ VirtualFunctionProposalItem::VirtualFunctionProposalItem(
{
}
void VirtualFunctionProposalItem::apply(TextEditor::BaseTextEditor *, int) const
void VirtualFunctionProposalItem::apply(TextEditor::BaseTextEditorWidget *, int) const
{
if (!m_link.hasValidTarget())
return;
......
......@@ -40,7 +40,7 @@ class VirtualFunctionProposalItem: public TextEditor::BasicProposalItem {
public:
VirtualFunctionProposalItem(const TextEditor::BaseTextEditorWidget::Link &link,
bool openInSplit = true);
void apply(TextEditor::BaseTextEditor * /* editor */, int /* basePosition */) const;
void apply(TextEditor::BaseTextEditorWidget * /* editorWidget */, int /* basePosition */) const;
TextEditor::BaseTextEditorWidget::Link link() const { return m_link; } // Exposed for tests
private:
......
......@@ -91,7 +91,7 @@ public:
m_isOverloaded(false) {}
bool prematurelyApplies(const QChar &c) const QTC_OVERRIDE;
void applyContextualContent(BaseTextEditor *editor, int basePosition) const QTC_OVERRIDE;
void applyContextualContent(BaseTextEditorWidget *editorWidget, int basePosition) const QTC_OVERRIDE;
bool isOverloaded() const { return m_isOverloaded; }
void markAsOverloaded() { m_isOverloaded = true; }
......@@ -121,8 +121,7 @@ bool CppAssistProposalModel::isSortable(const QString &prefix) const
IAssistProposalItem *CppAssistProposalModel::proposalItem(int index) const
{
BasicProposalItem *item =
static_cast<BasicProposalItem *>(BasicProposalItemListModel::proposalItem(index));
auto item = static_cast<BasicProposalItem *>(BasicProposalItemListModel::proposalItem(index));
if (!item->data().canConvert<QString>()) {
CppAssistProposalItem *cppItem = static_cast<CppAssistProposalItem *>(item);
cppItem->keepCompletionOperator(m_completionOperator);
......@@ -163,9 +162,9 @@ bool CppAssistProposalItem::prematurelyApplies(const QChar &typedChar) const
return false;
}
static bool isDereferenced(BaseTextEditor *editor, int basePosition)
static bool isDereferenced(BaseTextEditorWidget *editorWidget, int basePosition)
{
QTextCursor cursor = editor->textCursor();
QTextCursor cursor = editorWidget->textCursor();
cursor.setPosition(basePosition);
BackwardsScanner scanner(cursor);
......@@ -183,7 +182,7 @@ static bool isDereferenced(BaseTextEditor *editor, int basePosition)
return false;
}
void CppAssistProposalItem::applyContextualContent(BaseTextEditor *editor, int basePosition) const
void CppAssistProposalItem::applyContextualContent(BaseTextEditorWidget *editorWidget, int basePosition) const
{
Symbol *symbol = 0;
......@@ -233,7 +232,7 @@ void CppAssistProposalItem::applyContextualContent(BaseTextEditor *editor, int b
if (function->argumentCount() == 0)
extraChars += QLatin1Char('<');
#endif
} else if (!isDereferenced(editor, basePosition) && !function->isAmbiguous()) {
} else if (!isDereferenced(editorWidget, basePosition) && !function->isAmbiguous()) {
// When the user typed the opening parenthesis, he'll likely also type the closing one,
// in which case it would be annoying if we put the cursor after the already automatically
// inserted closing parenthesis.
......@@ -247,7 +246,7 @@ void CppAssistProposalItem::applyContextualContent(BaseTextEditor *editor, int b
// 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 = editorWidget->characterAt(editorWidget->position());
bool endWithSemicolon = m_typedChar == QLatin1Char(';')
|| (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON);
const QChar semicolon = m_typedChar.isNull() ? QLatin1Char(';') : m_typedChar;
......@@ -265,7 +264,7 @@ void CppAssistProposalItem::applyContextualContent(BaseTextEditor *editor, int b
m_typedChar = QChar();
}
} else if (autoParenthesesEnabled) {
const QChar lookAhead = editor->characterAt(editor->position() + 1);
const QChar lookAhead = editorWidget->characterAt(editorWidget->position() + 1);
if (MatchingText::shouldInsertMatchingText(lookAhead)) {
extraChars += QLatin1Char(')');
--cursorOffset;
......@@ -303,11 +302,11 @@ void CppAssistProposalItem::applyContextualContent(BaseTextEditor *editor, int b
// 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(BaseTextEditor::EndOfLine);
const QString inEditor = editor->textAt(editor->position(), lineEnd - editor->position());
const int lineEnd = editorWidget->position(BaseTextEditor::EndOfLine);
const QString inEditor = editorWidget->textAt(editorWidget->position(), lineEnd - editorWidget->position());
int preserveLength = 0;
if (!inEditor.isEmpty()) {
preserveLength = toInsert.length() - (editor->position() - basePosition);
preserveLength = toInsert.length() - (editorWidget->position() - basePosition);
const int inEditorLength = inEditor.length();
while (preserveLength > 0) {
if (inEditor.startsWith(toInsert.right(preserveLength))
......@@ -321,7 +320,7 @@ void CppAssistProposalItem::applyContextualContent(BaseTextEditor *editor, int b
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 = editorWidget->characterAt(editorWidget->position() + i + preserveLength);
if (a == b)
++extraLength;
else
......@@ -331,11 +330,11 @@ void CppAssistProposalItem::applyContextualContent(BaseTextEditor *editor, int b
toInsert += extraChars;
// Insert the remainder of the name
const int length = editor->position() - basePosition + preserveLength + extraLength;
editor->setCursorPosition(basePosition);
editor->replace(length, toInsert);
const int length = editorWidget->position() - basePosition + preserveLength + extraLength;
editorWidget->setCursorPosition(basePosition);
editorWidget->replace(length, toInsert);
if (cursorOffset)
editor->setCursorPosition(editor->position() + cursorOffset);
editorWidget->setCursorPosition(editorWidget->position() + cursorOffset);
}
// --------------------
......@@ -441,18 +440,18 @@ public:
{}
bool isCorrective() const QTC_OVERRIDE { return m_replaceDotForArrow; }
void makeCorrection(BaseTextEditor *editor) QTC_OVERRIDE;
void makeCorrection(BaseTextEditorWidget *editorWidget) QTC_OVERRIDE;
private:
bool m_replaceDotForArrow;
};
void CppAssistProposal::makeCorrection(BaseTextEditor *editor)
void CppAssistProposal::makeCorrection(BaseTextEditorWidget *editorWidget)
{
const int oldPosition = editor->position();
editor->setCursorPosition(basePosition() - 1);
editor->replace(1, QLatin1String("->"));
editor->setCursorPosition(oldPosition + 1);
const int oldPosition = editorWidget->position();
editorWidget->setCursorPosition(basePosition() - 1);
editorWidget->replace(1, QLatin1String("->"));
editorWidget->setCursorPosition(oldPosition + 1);
moveBasePosition(1);
}
......
......@@ -899,7 +899,7 @@ public:
return text() == m_provider->needle();
}
void applyContextualContent(BaseTextEditor *, int) const QTC_OVERRIDE
void applyContextualContent(BaseTextEditorWidget *, int) const QTC_OVERRIDE
{
QTC_ASSERT(m_provider->handler(), return);
m_provider->handler()->handleReplay(text().mid(m_provider->needle().size()));
......
......@@ -353,12 +353,12 @@ bool QmlJSAssistProposalItem::prematurelyApplies(const QChar &c) const
|| (text().endsWith(QLatin1Char('.')) && c == QLatin1Char('.'));
}
void QmlJSAssistProposalItem::applyContextualContent(BaseTextEditor *editor,
void QmlJSAssistProposalItem::applyContextualContent(BaseTextEditorWidget *editorWidget,
int basePosition) const
{
const int currentPosition = editor->position();
editor->setCursorPosition(basePosition);
editor->remove(currentPosition - basePosition);
const int currentPosition = editorWidget->position();
editorWidget->setCursorPosition(basePosition);
editorWidget->remove(currentPosition - basePosition);
QString content = text();
int cursorOffset = 0;
......@@ -377,16 +377,16 @@ void QmlJSAssistProposalItem::applyContextualContent(BaseTextEditor *editor,
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 = editorWidget->characterAt(editorWidget->position() + i);
if (a == b)
++replacedLength;
else
break;
}
const int length = editor->position() - basePosition + replacedLength;
editor->replace(length, content);
const int length = editorWidget->position() - basePosition + replacedLength;
editorWidget->replace(length, content);
if (cursorOffset)
editor->setCursorPosition(editor->position() + cursorOffset);
editorWidget->setCursorPosition(editorWidget->position() + cursorOffset);
}
// -------------------------
......
......@@ -57,7 +57,7 @@ class QmlJSAssistProposalItem : public TextEditor::BasicProposalItem
{
public:
bool prematurelyApplies(const QChar &c) const QTC_OVERRIDE;
void applyContextualContent(TextEditor::BaseTextEditor *editor,
void applyContextualContent(TextEditor::BaseTextEditorWidget *editorWidget,
int basePosition) const QTC_OVERRIDE;
};
......
......@@ -7284,7 +7284,7 @@ BaseTextEditor *BaseTextEditorFactory::createEditorHelper(const BaseTextDocument
editor->m_widget = widget;
widget->setTextDocument(document);
widget->d->m_codeAssistant.configure(editor);
widget->d->m_codeAssistant.configure(widget);
widget->d->m_commentDefinition.setStyle(m_commentStyle);
if (m_autoCompleterCreator)
......
......@@ -64,7 +64,7 @@ public:
setText(text);
}
void apply(BaseTextEditor *editor, int /*basePosition*/) const QTC_OVERRIDE
void apply(BaseTextEditorWidget *editorWidget, int /*basePosition*/) const QTC_OVERRIDE
{
//Move to last in circular clipboard
......@@ -78,7 +78,7 @@ public:
BaseTextEditorWidget::duplicateMimeData(m_mimeData.data()));
//Paste
editor->editorWidget()->paste();
editorWidget->paste();
}
private:
......
......@@ -104,33 +104,33 @@ bool BasicProposalItem::prematurelyApplies(const QChar &c) const
return false;
}
void BasicProposalItem::apply(BaseTextEditor *editor, int basePosition) const
void BasicProposalItem::apply(BaseTextEditorWidget *editorWidget, int basePosition) const
{
if (data().canConvert<QString>())
applySnippet(editor, basePosition);
applySnippet(editorWidget, basePosition);
else if (data().canConvert<QuickFixOperation::Ptr>())
applyQuickFix(editor, basePosition);
applyQuickFix(editorWidget, basePosition);
else
applyContextualContent(editor, basePosition);
applyContextualContent(editorWidget, basePosition);
}
void BasicProposalItem::applyContextualContent(BaseTextEditor *editor, int basePosition) const
void BasicProposalItem::applyContextualContent(BaseTextEditorWidget *editorWidget, int basePosition) const
{
const int currentPosition = editor->position();
editor->setCursorPosition(basePosition);
editor->replace(currentPosition - basePosition, text());
const int currentPosition = editorWidget->position();
editorWidget->setCursorPosition(basePosition);
editorWidget->replace(currentPosition - basePosition, text());
}
void BasicProposalItem::applySnippet(BaseTextEditor *editor, int basePosition) const
void BasicProposalItem::applySnippet(BaseTextEditorWidget *editorWidget, int basePosition) const
{
QTextCursor tc = editor->textCursor();
QTextCursor tc = editorWidget->textCursor();
tc.setPosition(basePosition, QTextCursor::KeepAnchor);
editor->editorWidget()->insertCodeSnippet(tc, data().toString());
editorWidget->insertCodeSnippet(tc, data().toString());
}
void BasicProposalItem::applyQuickFix(BaseTextEditor *editor, int basePosition) const
void BasicProposalItem::applyQuickFix(BaseTextEditorWidget *editorWidget, int basePosition) const
{
Q_UNUSED(editor)
Q_UNUSED(editorWidget)
Q_UNUSED(basePosition)
QuickFixOperation::Ptr op = data().value<QuickFixOperation::Ptr>();
......
......@@ -64,10 +64,10 @@ public:
bool implicitlyApplies() const QTC_OVERRIDE;
bool prematurelyApplies(const QChar &c) const QTC_OVERRIDE;
void apply(BaseTextEditor *editor, int basePosition) const QTC_OVERRIDE;
virtual void applyContextualContent(BaseTextEditor *editor, int basePosition) const;
virtual void applySnippet(BaseTextEditor *editor, int basePosition) const;
virtual void applyQuickFix(BaseTextEditor *editor, int basePosition) const;
void apply(BaseTextEditorWidget *editorWidget, int basePosition) const QTC_OVERRIDE;
virtual void applyContextualContent(BaseTextEditorWidget *editorWidget, int basePosition) const;
virtual void applySnippet(BaseTextEditorWidget *editorWidget, int basePosition) const;
virtual void applyQuickFix(BaseTextEditorWidget *editorWidget, int basePosition) const;
private:
QIcon m_icon;
......
......@@ -79,7 +79,7 @@ public:
CodeAssistantPrivate(CodeAssistant *assistant);
virtual ~CodeAssistantPrivate();
void configure(BaseTextEditor *textEditor);
void configure(BaseTextEditorWidget *editorWidget);
void reconfigure();
bool isConfigured() const;
......@@ -119,7 +119,7 @@ private slots:
private:
CodeAssistant *m_q;
BaseTextEditor *m_textEditor;
BaseTextEditorWidget *m_editorWidget;
CompletionAssistProvider *m_completionProvider;
QList<QuickFixAssistProvider *> m_quickFixProviders;
Internal::ProcessorRunner *m_requestRunner;
......@@ -145,7 +145,7 @@ static const int AutomaticProposalTimerInterval = 400;
CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
: m_q(assistant)
, m_textEditor(0)
, m_editorWidget(0)
, m_completionProvider(0)
, m_requestRunner(0)
, m_requestProvider(0)
......@@ -171,33 +171,33 @@ CodeAssistantPrivate::~CodeAssistantPrivate()
{
}
void CodeAssistantPrivate::configure(BaseTextEditor *textEditor)
void CodeAssistantPrivate::configure(BaseTextEditorWidget *editorWidget)
{
// @TODO: There's a list of providers but currently only the first one is used. Perhaps we
// should implement a truly mechanism to support multiple providers for an editor (either
// merging or not proposals) or just leave it as not extensible and store directly the one
// completion and quick-fix provider (getting rid of the list).
m_textEditor = textEditor;
m_completionProvider = textEditor->editorWidget()->completionAssistProvider();
m_editorWidget = editorWidget;
m_completionProvider = editorWidget->completionAssistProvider();
m_quickFixProviders =
ExtensionSystem::PluginManager::getObjects<QuickFixAssistProvider>();
filterEditorSpecificProviders(&m_quickFixProviders, m_textEditor->document()->id());
filterEditorSpecificProviders(&m_quickFixProviders, m_editorWidget->textDocument()->id());
m_textEditor->editorWidget()->installEventFilter(this);
connect(m_textEditor->textDocument(),SIGNAL(mimeTypeChanged()),
m_editorWidget->installEventFilter(this);
connect(m_editorWidget->textDocument(),SIGNAL(mimeTypeChanged()),
m_q, SLOT(reconfigure()));
}
void CodeAssistantPrivate::reconfigure()
{
if (isConfigured())
m_completionProvider = m_textEditor->editorWidget()->completionAssistProvider();
m_completionProvider = m_editorWidget->completionAssistProvider();
}
bool CodeAssistantPrivate::isConfigured() const
{
return m_textEditor != 0;
return m_editorWidget != 0;
}
void CodeAssistantPrivate::invoke(AssistKind kind, IAssistProvider *provider)
......@@ -210,9 +210,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->textDocument()->textAt(
m_editorWidget->textDocument()->textAt(
m_proposal->basePosition(),
m_textEditor->position() - m_proposal->basePosition()));
m_editorWidget->position() - m_proposal->basePosition()));
} else {
destroyContext();
requestProposal(ExplicitlyInvoked, kind, provider);
......@@ -248,7 +248,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
{
QTC_ASSERT(!isWaitingForProposal(), return);
if (m_textEditor->editorWidget()->hasBlockSelection())
if (m_editorWidget->hasBlockSelection())
return; // TODO
if (!provider) {
......@@ -263,8 +263,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
m_assistKind = kind;
IAssistProcessor *processor = provider->createProcessor();
IAssistInterface *assistInterface =
m_textEditor->editorWidget()->createAssistInterface(kind, reason);
IAssistInterface *assistInterface = m_editorWidget->createAssistInterface(kind, reason);
if (!assistInterface)
return;
......@@ -324,7 +323,7 @@ void CodeAssistantPrivate::displayProposal(IAssistProposal *newProposal, AssistR
}
int basePosition = proposalCandidate->basePosition();
if (m_textEditor->position() < basePosition)
if (m_editorWidget->position() < basePosition)
return;
if (m_abortedBasePosition == basePosition && reason != ExplicitlyInvoked)
......@@ -334,7 +333,7 @@ void CodeAssistantPrivate::displayProposal(IAssistProposal *newProposal, AssistR
m_proposal.reset(proposalCandidate.take());
if (m_proposal->isCorrective())
m_proposal->makeCorrection(m_textEditor);
m_proposal->makeCorrection(m_editorWidget);
basePosition = m_proposal->basePosition();
m_proposalWidget = m_proposal->createWidget();
......@@ -348,22 +347,22 @@ void CodeAssistantPrivate::displayProposal(IAssistProposal *newProposal, AssistR
m_proposalWidget->setAssistant(m_q);
m_proposalWidget->setReason(reason);
m_proposalWidget->setKind(m_assistKind);
m_proposalWidget->setUnderlyingWidget(m_textEditor->widget());
m_proposalWidget->setUnderlyingWidget(m_editorWidget);
m_proposalWidget->setModel(m_proposal->model());
m_proposalWidget->setDisplayRect(m_textEditor->cursorRect(basePosition));
m_proposalWidget->setDisplayRect(m_editorWidget->cursorRect(basePosition));
if (m_receivedContentWhileWaiting)
m_proposalWidget->setIsSynchronized(false);
else
m_proposalWidget->setIsSynchronized(true);
m_proposalWidget->showProposal(m_textEditor->textDocument()->textAt(
m_proposalWidget->showProposal(m_editorWidget->textDocument()->textAt(
basePosition,
m_textEditor->position() - basePosition));
m_editorWidget->position() - basePosition));
}
void CodeAssistantPrivate::processProposalItem(IAssistProposalItem *proposalItem)
{
QTC_ASSERT(m_proposal, return);
proposalItem->apply(m_textEditor, m_proposal->basePosition());
proposalItem->apply(m_editorWidget, m_proposal->basePosition());
destroyContext();
process();
}
......@@ -371,9 +370,9 @@ void CodeAssistantPrivate::processProposalItem(IAssistProposalItem *proposalItem
void CodeAssistantPrivate::handlePrefixExpansion(const QString &newPrefix)
{
QTC_ASSERT(m_proposal, return);
const int currentPosition = m_textEditor->position();
m_textEditor->setCursorPosition(m_proposal->basePosition());
m_textEditor->replace(currentPosition - m_proposal->basePosition(), newPrefix);
const int currentPosition = m_editorWidget->position();
m_editorWidget->setCursorPosition(m_proposal->basePosition());
m_editorWidget->replace(currentPosition - m_proposal->basePosition(), newPrefix);
notifyChange();
}
......@@ -416,7 +415,7 @@ CompletionAssistProvider *CodeAssistantPrivate::identifyActivationSequence()
const int length = m_completionProvider->activationCharSequenceLength();
if (length == 0)
return 0;
QString sequence = m_textEditor->textDocument()->textAt(m_textEditor->position() - length,
QString sequence = m_editorWidget->textDocument()->textAt(m_editorWidget->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
......@@ -434,12 +433,12 @@ void CodeAssistantPrivate::notifyChange()
if (isDisplayingProposal()) {
QTC_ASSERT(m_proposal, return);
if (m_textEditor->position() < m_proposal->basePosition()) {
if (m_editorWidget->position() < m_proposal->basePosition()) {
destroyContext();
} else {
m_proposalWidget->updateProposal(
m_textEditor->textDocument()->textAt(m_proposal->basePosition(),
m_textEditor->position() - m_proposal->basePosition()));
m_editorWidget->textDocument()->textAt(m_proposal->basePosition(),
m_editorWidget->position() - m_proposal->basePosition()));
if (m_proposal->isFragile())
startAutomaticProposalTimer();
}
......@@ -544,9 +543,9 @@ CodeAssistant::~CodeAssistant()
delete d;
}
void CodeAssistant::configure(BaseTextEditor *textEditor)
void CodeAssistant::configure(BaseTextEditorWidget *editorWidget)
{
d->configure(textEditor);
d->configure(editorWidget);
}
void CodeAssistant::process()
......
......@@ -40,7 +40,7 @@ namespace TextEditor {
class CodeAssistantPrivate;
class IAssistProvider;
class BaseTextEditor;
class BaseTextEditorWidget;
class CodeAssistant : public QObject
{
......@@ -50,7 +50,7 @@ public:
CodeAssistant();
~CodeAssistant();
void configure(BaseTextEditor *textEditor);
void configure(BaseTextEditorWidget *editorWidget);
void process();
void notifyChange();
......
......@@ -56,7 +56,7 @@ bool FunctionHintProposal::isCorrective() const
return false;
}
void FunctionHintProposal::makeCorrection(BaseTextEditor *)
void FunctionHintProposal::makeCorrection(BaseTextEditorWidget *)
{}
IAssistProposalModel *FunctionHintProposal::model() const
......