forked from qt-creator/qt-creator
Editor: cleanup special cases for snippets.
This commit is contained in:
@@ -1822,9 +1822,6 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item, QChar t
|
||||
|
||||
Symbol *symbol = 0;
|
||||
|
||||
if (TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(m_editor->widget()))
|
||||
edit->setNextChangeIsSnippetSafe();
|
||||
|
||||
if (item.data.isValid()) {
|
||||
if (item.data.canConvert<QString>()) {
|
||||
TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(m_editor->widget());
|
||||
|
||||
@@ -904,8 +904,6 @@ void CodeCompletion::complete(const TextEditor::CompletionItem &item, QChar type
|
||||
QString toInsert = item.text;
|
||||
|
||||
if (QmlJSTextEditor *edit = qobject_cast<QmlJSTextEditor *>(m_editor->widget())) {
|
||||
edit->setNextChangeIsSnippetSafe();
|
||||
|
||||
if (item.data.isValid()) {
|
||||
QTextCursor tc = edit->textCursor();
|
||||
tc.setPosition(m_startPosition, QTextCursor::KeepAnchor);
|
||||
|
||||
@@ -89,17 +89,6 @@
|
||||
using namespace TextEditor;
|
||||
using namespace TextEditor::Internal;
|
||||
|
||||
namespace {
|
||||
class Locker {
|
||||
bool *m_bool;
|
||||
public:
|
||||
inline Locker(bool *b):m_bool(b){ *m_bool = true; }
|
||||
inline ~Locker() { *m_bool = false; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace TextEditor {
|
||||
namespace Internal {
|
||||
|
||||
@@ -258,10 +247,7 @@ BaseTextEditor::BaseTextEditor(QWidget *parent)
|
||||
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||
this, SLOT(currentEditorChanged(Core::IEditor*)));
|
||||
|
||||
d->m_inKeyPressEvent = false;
|
||||
d->m_moveLineUndoHack = false;
|
||||
|
||||
d->m_nextChangeIsSnippetSafe = false;
|
||||
}
|
||||
|
||||
BaseTextEditor::~BaseTextEditor()
|
||||
@@ -495,37 +481,12 @@ ITextMarkable *BaseTextEditor::markableInterface() const
|
||||
return baseTextDocument()->documentMarker();
|
||||
}
|
||||
|
||||
void BaseTextEditor::maybeEmitContentsChangedBecauseOfUndo()
|
||||
{
|
||||
if (!d->m_inKeyPressEvent && !d->m_nextChangeIsSnippetSafe) {
|
||||
d->m_nextChangeIsSnippetSafe = false;
|
||||
|
||||
// i.e. the document was changed outside key press event
|
||||
// Possible with undo, cut, paste, etc.
|
||||
if (d->m_snippetOverlay->isVisible()) {
|
||||
|
||||
d->m_snippetOverlay->hide();
|
||||
d->m_snippetOverlay->clear();
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.clearSelection();
|
||||
setTextCursor(cursor);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (document()->isRedoAvailable()) {
|
||||
emit editableInterface()->contentsChangedBecauseOfUndo();
|
||||
}
|
||||
}
|
||||
|
||||
BaseTextEditorEditable *BaseTextEditor::editableInterface() const
|
||||
{
|
||||
if (!d->m_editable) {
|
||||
d->m_editable = const_cast<BaseTextEditor*>(this)->createEditableInterface();
|
||||
connect(this, SIGNAL(textChanged()),
|
||||
d->m_editable, SIGNAL(contentsChanged()));
|
||||
connect(this, SIGNAL(textChanged()),
|
||||
this, SLOT(maybeEmitContentsChangedBecauseOfUndo()));
|
||||
connect(this, SIGNAL(changed()),
|
||||
d->m_editable, SIGNAL(changed()));
|
||||
}
|
||||
@@ -683,7 +644,6 @@ void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int ch
|
||||
if (d->m_animator)
|
||||
d->m_animator->finish();
|
||||
|
||||
|
||||
d->m_contentsChanged = true;
|
||||
QTextDocument *doc = document();
|
||||
|
||||
@@ -703,11 +663,19 @@ void BaseTextEditor::editorContentsChange(int position, int charsRemoved, int ch
|
||||
}
|
||||
}
|
||||
|
||||
if (d->m_snippetOverlay->isVisible()) {
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.setPosition(position);
|
||||
if (!d->m_snippetOverlay->hasCursorInSelection(cursor)) {
|
||||
d->m_snippetOverlay->hide();
|
||||
d->m_snippetOverlay->clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (doc->isRedoAvailable())
|
||||
emit editableInterface()->contentsChangedBecauseOfUndo();
|
||||
}
|
||||
|
||||
|
||||
void BaseTextEditor::slotSelectionChanged()
|
||||
{
|
||||
if (d->m_inBlockSelectionMode && !textCursor().hasSelection()) {
|
||||
@@ -1108,8 +1076,6 @@ void BaseTextEditor::cleanWhitespace()
|
||||
|
||||
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
Locker inKeyPressEvent(&d->m_inKeyPressEvent);
|
||||
|
||||
viewport()->setCursor(Qt::BlankCursor);
|
||||
ToolTip::instance()->hide();
|
||||
|
||||
@@ -1958,8 +1924,7 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
|
||||
m_requestAutoCompletionRevision(0),
|
||||
m_requestAutoCompletionPosition(0),
|
||||
m_requestAutoCompletionTimer(0),
|
||||
m_cursorBlockNumber(-1),
|
||||
m_inKeyPressEvent(false)
|
||||
m_cursorBlockNumber(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -4084,11 +4049,6 @@ QString BaseTextEditor::insertParagraphSeparator(const QTextCursor &tc) const
|
||||
return QString();
|
||||
}
|
||||
|
||||
void BaseTextEditor::setNextChangeIsSnippetSafe()
|
||||
{
|
||||
d->m_nextChangeIsSnippetSafe = true;
|
||||
}
|
||||
|
||||
QString BaseTextEditor::autoComplete(QTextCursor &cursor, const QString &textToInsert) const
|
||||
{
|
||||
const bool checkBlockEnd = d->m_allowSkippingOfBlockEnd;
|
||||
@@ -5441,6 +5401,12 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source)
|
||||
cursor.endEditBlock();
|
||||
setTextCursor(cursor);
|
||||
ensureCursorVisible();
|
||||
|
||||
if (d->m_snippetOverlay->isVisible() && lines.count() > 1) {
|
||||
d->m_snippetOverlay->hide();
|
||||
d->m_snippetOverlay->clear();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5451,8 +5417,11 @@ void BaseTextEditor::insertFromMimeData(const QMimeData *source)
|
||||
if (CompletionSupport::instance()->isActive())
|
||||
setFocus();
|
||||
|
||||
if (!text.contains(QLatin1Char('\n')) && !text.contains(QLatin1Char('\t')))
|
||||
setNextChangeIsSnippetSafe();
|
||||
if (d->m_snippetOverlay->isVisible() && (text.contains(QLatin1Char('\n'))
|
||||
|| text.contains(QLatin1Char('\t')))) {
|
||||
d->m_snippetOverlay->hide();
|
||||
d->m_snippetOverlay->clear();
|
||||
}
|
||||
|
||||
const TabSettings &ts = d->m_document->tabSettings();
|
||||
QTextCursor cursor = textCursor();
|
||||
|
||||
@@ -346,7 +346,6 @@ private slots:
|
||||
bool inFindScope(const QTextCursor &cursor);
|
||||
bool inFindScope(int selectionStart, int selectionEnd);
|
||||
void currentEditorChanged(Core::IEditor *editor);
|
||||
void maybeEmitContentsChangedBecauseOfUndo();
|
||||
|
||||
private:
|
||||
Internal::BaseTextEditorPrivate *d;
|
||||
@@ -462,8 +461,6 @@ public:
|
||||
// Returns the text that needs to be inserted
|
||||
virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
|
||||
|
||||
virtual void setNextChangeIsSnippetSafe();
|
||||
|
||||
protected:
|
||||
static void countBracket(QChar open, QChar close, QChar c, int *errors, int *stillopen);
|
||||
|
||||
|
||||
@@ -271,9 +271,6 @@ public:
|
||||
|
||||
QPointer<BaseTextEditorAnimator> m_animator;
|
||||
int m_cursorBlockNumber;
|
||||
|
||||
bool m_inKeyPressEvent;
|
||||
bool m_nextChangeIsSnippetSafe;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user