diff options
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r-- | src/plugins/texteditor/basefilefind.cpp | 3 | ||||
-rw-r--r-- | src/plugins/texteditor/bookmarkmanager.cpp | 1 | ||||
-rw-r--r-- | src/plugins/texteditor/completionsettingspage.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/displaysettingspage.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettings.cpp | 3 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettingspage.cpp | 7 | ||||
-rw-r--r-- | src/plugins/texteditor/refactoringchanges.cpp | 11 | ||||
-rw-r--r-- | src/plugins/texteditor/refactoringchanges.h | 1 | ||||
-rw-r--r-- | src/plugins/texteditor/textdocument.cpp | 5 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 44 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditor.h | 10 |
11 files changed, 67 insertions, 22 deletions
diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp index ce6d2f4999..0faa871b5c 100644 --- a/src/plugins/texteditor/basefilefind.cpp +++ b/src/plugins/texteditor/basefilefind.cpp @@ -594,8 +594,7 @@ FilePaths BaseFileFind::replaceAll(const QString &text, const SearchResultItems item.mainRange().end.column + 1); changeSet.replace(start, end, replacement); } - file->setChangeSet(changeSet); - file->apply(); + file->apply(changeSet); } return changes.keys(); diff --git a/src/plugins/texteditor/bookmarkmanager.cpp b/src/plugins/texteditor/bookmarkmanager.cpp index 6dcb4de6cc..a61cc58736 100644 --- a/src/plugins/texteditor/bookmarkmanager.cpp +++ b/src/plugins/texteditor/bookmarkmanager.cpp @@ -876,6 +876,7 @@ void BookmarkManager::edit() auto layout = new QFormLayout(&dlg); auto noteEdit = new QLineEdit(b->note()); noteEdit->setMinimumWidth(300); + noteEdit->setFocus(); auto lineNumberSpinbox = new QSpinBox; lineNumberSpinbox->setRange(1, INT_MAX); lineNumberSpinbox->setValue(b->lineNumber()); diff --git a/src/plugins/texteditor/completionsettingspage.cpp b/src/plugins/texteditor/completionsettingspage.cpp index aba8646714..03f45404c6 100644 --- a/src/plugins/texteditor/completionsettingspage.cpp +++ b/src/plugins/texteditor/completionsettingspage.cpp @@ -214,7 +214,7 @@ CompletionSettingsPageWidget::CompletionSettingsPageWidget(CompletionSettingsPag } }, Group { - title(Tr::tr("&Automatically insert matching characters")), + title(Tr::tr("&Automatically Insert Matching Characters")), Row { Column { m_insertBrackets, diff --git a/src/plugins/texteditor/displaysettingspage.cpp b/src/plugins/texteditor/displaysettingspage.cpp index b5435ed5e9..fe914b27ce 100644 --- a/src/plugins/texteditor/displaysettingspage.cpp +++ b/src/plugins/texteditor/displaysettingspage.cpp @@ -108,7 +108,7 @@ public: rightAligned->setChecked(true); betweenLines = new QRadioButton(Tr::tr("Between lines")); - displayAnnotations = new QGroupBox(Tr::tr("Line annotations")), + displayAnnotations = new QGroupBox(Tr::tr("Line Annotations")), displayAnnotations->setCheckable(true); using namespace Layouting; diff --git a/src/plugins/texteditor/fontsettings.cpp b/src/plugins/texteditor/fontsettings.cpp index e74a37c0d3..44b179d01c 100644 --- a/src/plugins/texteditor/fontsettings.cpp +++ b/src/plugins/texteditor/fontsettings.cpp @@ -491,8 +491,7 @@ static QString defaultFontFamily() return QLatin1String("Menlo"); const QString sourceCodePro(g_sourceCodePro); - const QFontDatabase dataBase; - if (dataBase.hasFamily(sourceCodePro)) + if (QFontDatabase::hasFamily(sourceCodePro)) return sourceCodePro; if (Utils::HostOsInfo::isAnyUnixHost()) diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp index bdd899b7e0..f528496dcf 100644 --- a/src/plugins/texteditor/fontsettingspage.cpp +++ b/src/plugins/texteditor/fontsettingspage.cpp @@ -458,15 +458,14 @@ void FontSettingsPageWidget::updateFontZoom(const FontSettings &fontSettings) QList<int> FontSettingsPageWidget::pointSizesForSelectedFont() const { - QFontDatabase db; const QString familyName = m_fontComboBox->currentFont().family(); - QList<int> sizeLst = db.pointSizes(familyName); + QList<int> sizeLst = QFontDatabase::pointSizes(familyName); if (!sizeLst.isEmpty()) return sizeLst; - QStringList styles = db.styles(familyName); + QStringList styles = QFontDatabase::styles(familyName); if (!styles.isEmpty()) - sizeLst = db.pointSizes(familyName, styles.first()); + sizeLst = QFontDatabase::pointSizes(familyName, styles.first()); if (sizeLst.isEmpty()) sizeLst = QFontDatabase::standardSizes(); diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index ebd487cc37..c8688f2fba 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -214,6 +214,9 @@ void RefactoringFile::setOpenEditor(bool activate, int pos) bool RefactoringFile::apply() { + if (m_changes.isEmpty()) + return true; + // test file permissions if (!m_filePath.isWritableFile()) { ReadOnlyFilesDialog roDialog(m_filePath, ICore::dialogParent()); @@ -287,6 +290,12 @@ bool RefactoringFile::apply() return result; } +bool RefactoringFile::apply(const Utils::ChangeSet &changeSet) +{ + setChangeSet(changeSet); + return apply(); +} + void RefactoringFile::setupFormattingRanges(const QList<ChangeSet::EditOp> &replaceList) { QTextDocument * const doc = m_editor ? m_editor->document() : m_document; @@ -359,7 +368,7 @@ void RefactoringFile::doFormatting() Utils::sort(m_formattingCursors, [](const auto &tc1, const auto &tc2) { return tc1.first.selectionStart() < tc2.first.selectionStart(); }); - static const QString clangFormatLineRemovalBlocker("// QTC_TEMP"); + static const QString clangFormatLineRemovalBlocker(""); for (auto &[formattingCursor, _] : m_formattingCursors) { const QTextBlock firstBlock = document->findBlock(formattingCursor.selectionStart()); const QTextBlock lastBlock = document->findBlock(formattingCursor.selectionEnd()); diff --git a/src/plugins/texteditor/refactoringchanges.h b/src/plugins/texteditor/refactoringchanges.h index 913c731df2..3e043c4f6b 100644 --- a/src/plugins/texteditor/refactoringchanges.h +++ b/src/plugins/texteditor/refactoringchanges.h @@ -60,6 +60,7 @@ public: void setChangeSet(const Utils::ChangeSet &changeSet); void setOpenEditor(bool activate = false, int pos = -1); bool apply(); + bool apply(const Utils::ChangeSet &changeSet); bool create(const QString &contents, bool reindent, bool openInEditor); protected: diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 9d8133912c..7fcfe5c86c 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -522,10 +522,7 @@ bool TextDocument::applyChangeSet(const ChangeSet &changeSet) { if (changeSet.isEmpty()) return true; - PlainRefactoringFileFactory changes; - const RefactoringFilePtr file = changes.file(filePath()); - file->setChangeSet(changeSet); - return file->apply(); + return PlainRefactoringFileFactory().file(filePath())->apply(changeSet); } // the blocks list must be sorted diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 92636e63cd..f7f47c10ac 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -354,6 +354,7 @@ public: BaseTextEditorPrivate() = default; TextEditorFactoryPrivate *m_origin = nullptr; + QByteArray m_savedNavigationState; }; class HoverHandlerRunner @@ -772,7 +773,6 @@ public: QSharedPointer<TextDocument> m_document; QList<QMetaObject::Connection> m_documentConnections; QByteArray m_tempState; - QByteArray m_tempNavigationState; bool m_parenthesesMatchingEnabled = false; QTimer m_parenthesesMatchingTimer; @@ -6498,7 +6498,7 @@ void TextEditorWidgetPrivate::slotUpdateRequest(const QRect &r, int dy) void TextEditorWidgetPrivate::saveCurrentCursorPositionForNavigation() { m_lastCursorChangeWasInteresting = true; - m_tempNavigationState = q->saveState(); + emit q->saveCurrentStateForNavigationHistory(); } void TextEditorWidgetPrivate::updateCurrentLineHighlight() @@ -6554,8 +6554,7 @@ void TextEditorWidget::slotCursorPositionChanged() << "indent:" << BaseTextDocumentLayout::userData(textCursor().block())->foldingIndent(); #endif if (!d->m_contentsChanged && d->m_lastCursorChangeWasInteresting) { - if (EditorManager::currentEditor() && EditorManager::currentEditor()->widget() == this) - EditorManager::addCurrentPositionToNavigationHistory(d->m_tempNavigationState); + emit addSavedStateToNavigationHistory(); d->m_lastCursorChangeWasInteresting = false; } else if (d->m_contentsChanged) { d->saveCurrentCursorPositionForNavigation(); @@ -6861,7 +6860,6 @@ void TextEditorWidget::mouseReleaseEvent(QMouseEvent *e) { const Qt::MouseButton button = e->button(); if (d->m_linkPressed && d->isMouseNavigationEvent(e) && button == Qt::LeftButton) { - EditorManager::addCurrentPositionToNavigationHistory(); bool inNextSplit = ((e->modifiers() & Qt::AltModifier) && !alwaysOpenLinksInNextSplit()) || (alwaysOpenLinksInNextSplit() && !(e->modifiers() & Qt::AltModifier)); @@ -7589,7 +7587,7 @@ bool TextEditorWidget::openLink(const Utils::Link &link, bool inNextSplit) } if (!inNextSplit && textDocument()->filePath() == link.targetFilePath) { - EditorManager::addCurrentPositionToNavigationHistory(); + emit addCurrentStateToNavigationHistory(); gotoLine(link.targetLine, link.targetColumn, true, true); setFocus(); return true; @@ -9059,7 +9057,7 @@ QMimeData *TextEditorWidget::createMimeDataFromSelection(bool withHtml) const } else { const int startPosition = current.position() - selectionStart - removedCount; - int endPosition = startPosition + current.text().count(); + int endPosition = startPosition + current.text().size(); if (current != last) endPosition++; removedCount += endPosition - startPosition; @@ -9605,6 +9603,23 @@ void BaseTextEditor::select(int toPos) editorWidget()->setTextCursor(tc); } +void BaseTextEditor::saveCurrentStateForNavigationHistory() +{ + d->m_savedNavigationState = saveState(); +} + +void BaseTextEditor::addSavedStateToNavigationHistory() +{ + if (EditorManager::currentEditor() == this) + EditorManager::addCurrentPositionToNavigationHistory(d->m_savedNavigationState); +} + +void BaseTextEditor::addCurrentStateToNavigationHistory() +{ + if (EditorManager::currentEditor() == this) + EditorManager::addCurrentPositionToNavigationHistory(); +} + void TextEditorWidgetPrivate::updateCursorPosition() { m_contextHelpItem = HelpItem(); @@ -10236,6 +10251,21 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP [editor](EditorManager::OpenEditorFlags flags) { EditorManager::activateEditor(editor, flags); }); + QObject::connect( + textEditorWidget, + &TextEditorWidget::saveCurrentStateForNavigationHistory, + editor, + &BaseTextEditor::saveCurrentStateForNavigationHistory); + QObject::connect( + textEditorWidget, + &TextEditorWidget::addSavedStateToNavigationHistory, + editor, + &BaseTextEditor::addSavedStateToNavigationHistory); + QObject::connect( + textEditorWidget, + &TextEditorWidget::addCurrentStateToNavigationHistory, + editor, + &BaseTextEditor::addCurrentStateToNavigationHistory); if (m_useGenericHighlighter) textEditorWidget->setupGenericHighlighter(); diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 78dc0e0b82..c155bb8ff2 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -169,6 +169,11 @@ public: private: friend class TextEditorFactory; friend class Internal::TextEditorFactoryPrivate; + + void saveCurrentStateForNavigationHistory(); + void addSavedStateToNavigationHistory(); + void addCurrentStateToNavigationHistory(); + Internal::BaseTextEditorPrivate *d; }; @@ -532,6 +537,11 @@ signals: void requestCallHierarchy(const QTextCursor &cursor); void toolbarOutlineChanged(QWidget *newOutline); + // used by the IEditor + void saveCurrentStateForNavigationHistory(); + void addSavedStateToNavigationHistory(); + void addCurrentStateToNavigationHistory(); + protected: QTextBlock blockForVisibleRow(int row) const; QTextBlock blockForVerticalOffset(int offset) const; |