forked from qt-creator/qt-creator
Markdown: Support bookmarks and jumping to search results
Redirect the currentLine/Column and gotoLine functions to the text editor and ensure that it is visible for gotoLine. Change-Id: I546e2cb1761363e3a75f9adeebcba195e312f00b Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -128,14 +128,16 @@ BookmarksPluginPrivate::BookmarksPluginPrivate()
|
|||||||
mbm->addAction(cmd);
|
mbm->addAction(cmd);
|
||||||
|
|
||||||
connect(&m_toggleAction, &QAction::triggered, this, [this] {
|
connect(&m_toggleAction, &QAction::triggered, this, [this] {
|
||||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
if (editor && !editor->document()->isTemporary())
|
auto widget = TextEditorWidget::fromEditor(editor);
|
||||||
|
if (widget && editor && !editor->document()->isTemporary())
|
||||||
m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine());
|
m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&m_editAction, &QAction::triggered, this, [this] {
|
connect(&m_editAction, &QAction::triggered, this, [this] {
|
||||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
if (editor && !editor->document()->isTemporary()) {
|
auto widget = TextEditorWidget::fromEditor(editor);
|
||||||
|
if (widget && editor && !editor->document()->isTemporary()) {
|
||||||
const FilePath filePath = editor->document()->filePath();
|
const FilePath filePath = editor->document()->filePath();
|
||||||
const int line = editor->currentLine();
|
const int line = editor->currentLine();
|
||||||
if (!m_bookmarkManager.hasBookmarkInPosition(filePath, line))
|
if (!m_bookmarkManager.hasBookmarkInPosition(filePath, line))
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "texteditor.h"
|
#include "texteditor.h"
|
||||||
#include "texteditortr.h"
|
#include "texteditortr.h"
|
||||||
|
|
||||||
|
#include <aggregation/aggregate.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/coreplugintr.h>
|
#include <coreplugin/coreplugintr.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -74,16 +75,23 @@ public:
|
|||||||
layout->addWidget(m_splitter);
|
layout->addWidget(m_splitter);
|
||||||
setWidget(widget);
|
setWidget(widget);
|
||||||
m_widget->installEventFilter(this);
|
m_widget->installEventFilter(this);
|
||||||
|
using namespace Aggregation;
|
||||||
|
Aggregate *agg = Aggregate::parentAggregate(m_textEditorWidget);
|
||||||
|
if (!agg) {
|
||||||
|
agg = new Aggregate;
|
||||||
|
agg->add(m_textEditorWidget);
|
||||||
|
}
|
||||||
|
agg->add(m_widget.get());
|
||||||
|
|
||||||
auto togglePreviewVisible = new QToolButton;
|
auto togglePreviewVisible = new QToolButton;
|
||||||
togglePreviewVisible->setText(Tr::tr("Show Preview"));
|
togglePreviewVisible->setText(Tr::tr("Show Preview"));
|
||||||
togglePreviewVisible->setCheckable(true);
|
togglePreviewVisible->setCheckable(true);
|
||||||
togglePreviewVisible->setChecked(true);
|
togglePreviewVisible->setChecked(true);
|
||||||
|
|
||||||
auto toggleEditorVisible = new QToolButton;
|
m_toggleEditorVisible = new QToolButton;
|
||||||
toggleEditorVisible->setText(Tr::tr("Show Editor"));
|
m_toggleEditorVisible->setText(Tr::tr("Show Editor"));
|
||||||
toggleEditorVisible->setCheckable(true);
|
m_toggleEditorVisible->setCheckable(true);
|
||||||
toggleEditorVisible->setChecked(true);
|
m_toggleEditorVisible->setChecked(true);
|
||||||
|
|
||||||
auto swapViews = new QToolButton;
|
auto swapViews = new QToolButton;
|
||||||
swapViews->setText(Tr::tr("Swap Views"));
|
swapViews->setText(Tr::tr("Swap Views"));
|
||||||
@@ -94,9 +102,9 @@ public:
|
|||||||
toolbarLayout->addStretch();
|
toolbarLayout->addStretch();
|
||||||
if (textEditorRight) {
|
if (textEditorRight) {
|
||||||
toolbarLayout->addWidget(togglePreviewVisible);
|
toolbarLayout->addWidget(togglePreviewVisible);
|
||||||
toolbarLayout->addWidget(toggleEditorVisible);
|
toolbarLayout->addWidget(m_toggleEditorVisible);
|
||||||
} else {
|
} else {
|
||||||
toolbarLayout->addWidget(toggleEditorVisible);
|
toolbarLayout->addWidget(m_toggleEditorVisible);
|
||||||
toolbarLayout->addWidget(togglePreviewVisible);
|
toolbarLayout->addWidget(togglePreviewVisible);
|
||||||
}
|
}
|
||||||
toolbarLayout->addWidget(swapViews);
|
toolbarLayout->addWidget(swapViews);
|
||||||
@@ -137,7 +145,7 @@ public:
|
|||||||
swapViews->setEnabled(view->isVisible() && otherView->isVisible());
|
swapViews->setEnabled(view->isVisible() && otherView->isVisible());
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(toggleEditorVisible,
|
connect(m_toggleEditorVisible,
|
||||||
&QToolButton::toggled,
|
&QToolButton::toggled,
|
||||||
this,
|
this,
|
||||||
[this, browser, togglePreviewVisible, viewToggled](bool visible) {
|
[this, browser, togglePreviewVisible, viewToggled](bool visible) {
|
||||||
@@ -146,8 +154,8 @@ public:
|
|||||||
connect(togglePreviewVisible,
|
connect(togglePreviewVisible,
|
||||||
&QToolButton::toggled,
|
&QToolButton::toggled,
|
||||||
this,
|
this,
|
||||||
[this, browser, toggleEditorVisible, viewToggled, updatePreview](bool visible) {
|
[this, browser, viewToggled, updatePreview](bool visible) {
|
||||||
viewToggled(browser, visible, m_textEditorWidget, toggleEditorVisible);
|
viewToggled(browser, visible, m_textEditorWidget, m_toggleEditorVisible);
|
||||||
if (visible && m_performDelayedUpdate) {
|
if (visible && m_performDelayedUpdate) {
|
||||||
m_performDelayedUpdate = false;
|
m_performDelayedUpdate = false;
|
||||||
updatePreview();
|
updatePreview();
|
||||||
@@ -193,6 +201,18 @@ public:
|
|||||||
|
|
||||||
Core::IDocument *document() const override { return m_document.data(); }
|
Core::IDocument *document() const override { return m_document.data(); }
|
||||||
TextEditorWidget *textEditorWidget() const { return m_textEditorWidget; }
|
TextEditorWidget *textEditorWidget() const { return m_textEditorWidget; }
|
||||||
|
int currentLine() const override { return textEditorWidget()->textCursor().blockNumber() + 1; };
|
||||||
|
int currentColumn() const override
|
||||||
|
{
|
||||||
|
QTextCursor cursor = textEditorWidget()->textCursor();
|
||||||
|
return cursor.position() - cursor.block().position() + 1;
|
||||||
|
}
|
||||||
|
void gotoLine(int line, int column, bool centerLine) override
|
||||||
|
{
|
||||||
|
if (!m_toggleEditorVisible->isChecked())
|
||||||
|
m_toggleEditorVisible->toggle();
|
||||||
|
textEditorWidget()->gotoLine(line, column, centerLine);
|
||||||
|
}
|
||||||
|
|
||||||
bool eventFilter(QObject *obj, QEvent *ev) override
|
bool eventFilter(QObject *obj, QEvent *ev) override
|
||||||
{
|
{
|
||||||
@@ -213,6 +233,7 @@ private:
|
|||||||
TextEditorWidget *m_textEditorWidget;
|
TextEditorWidget *m_textEditorWidget;
|
||||||
TextDocumentPtr m_document;
|
TextDocumentPtr m_document;
|
||||||
QWidget m_toolbar;
|
QWidget m_toolbar;
|
||||||
|
QToolButton *m_toggleEditorVisible;
|
||||||
};
|
};
|
||||||
|
|
||||||
MarkdownEditorFactory::MarkdownEditorFactory()
|
MarkdownEditorFactory::MarkdownEditorFactory()
|
||||||
|
|||||||
Reference in New Issue
Block a user