diff --git a/src/resources/pre_template.html b/src/resources/pre_template.html index 426e9f79..f3b7a0c6 100644 --- a/src/resources/pre_template.html +++ b/src/resources/pre_template.html @@ -136,6 +136,7 @@ return; default: + content.keyPressEvent(key); keyState = 0; return; } diff --git a/src/resources/template.html b/src/resources/template.html index b2596318..d0a4095c 100644 --- a/src/resources/template.html +++ b/src/resources/template.html @@ -253,6 +253,7 @@ return; default: + content.keyPressEvent(key); keyState = 0; return; } diff --git a/src/vdocument.cpp b/src/vdocument.cpp index da7e7e54..da8a06d2 100644 --- a/src/vdocument.cpp +++ b/src/vdocument.cpp @@ -66,6 +66,10 @@ void VDocument::setHtml(const QString &html) void VDocument::setLog(const QString &p_log) { qDebug() << "JS:" << p_log; - m_log = p_log; - emit logChanged(m_log); + emit logChanged(p_log); +} + +void VDocument::keyPressEvent(int p_key) +{ + emit keyPressed(p_key); } diff --git a/src/vdocument.h b/src/vdocument.h index cfa6f2b4..f526acc1 100644 --- a/src/vdocument.h +++ b/src/vdocument.h @@ -10,7 +10,6 @@ class VDocument : public QObject Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged) Q_PROPERTY(QString toc MEMBER m_toc NOTIFY tocChanged) Q_PROPERTY(QString html MEMBER m_html NOTIFY htmlChanged) - Q_PROPERTY(QString log MEMBER m_log NOTIFY logChanged) public: explicit VDocument(QObject *parent = 0); @@ -26,6 +25,7 @@ public slots: void setToc(const QString &toc); void setHeader(const QString &anchor); void setLog(const QString &p_log); + void keyPressEvent(int p_key); signals: void textChanged(const QString &text); @@ -34,14 +34,13 @@ signals: void headerChanged(const QString &anchor); void htmlChanged(const QString &html); void logChanged(const QString &p_log); + void keyPressed(int p_key); private: QString m_text; QString m_toc; QString m_header; QString m_html; - // Used for debugging - QString m_log; }; #endif // VDOCUMENT_H diff --git a/src/vedittab.cpp b/src/vedittab.cpp index cfe94639..0221d0c9 100644 --- a/src/vedittab.cpp +++ b/src/vedittab.cpp @@ -16,12 +16,14 @@ #include "vtoc.h" #include "vmdedit.h" #include "dialog/vfindreplacedialog.h" +#include "veditarea.h" extern VConfigManager vconfig; VEditTab::VEditTab(VFile *p_file, OpenFileMode p_mode, QWidget *p_parent) : QStackedWidget(p_parent), m_file(p_file), isEditMode(false), - mdConverterType(vconfig.getMdConverterType()), m_fileModified(false) + mdConverterType(vconfig.getMdConverterType()), m_fileModified(false), + m_editArea(NULL) { tableOfContent.filePath = p_file->retrivePath(); curHeader.filePath = p_file->retrivePath(); @@ -44,6 +46,11 @@ VEditTab::~VEditTab() } } +void VEditTab::init(VEditArea *p_editArea) +{ + m_editArea = p_editArea; +} + void VEditTab::setupUI() { switch (m_file->getDocType()) { @@ -262,6 +269,8 @@ void VEditTab::setupMarkdownPreview() this, &VEditTab::updateTocFromHtml); connect(&document, SIGNAL(headerChanged(const QString&)), this, SLOT(updateCurHeader(const QString &))); + connect(&document, &VDocument::keyPressed, + this, &VEditTab::handleWebKeyPressed); page->setWebChannel(channel); if (mdConverterType == MarkdownConverterType::Marked) { @@ -538,3 +547,16 @@ bool VEditTab::checkToc() return ret; } +void VEditTab::handleWebKeyPressed(int p_key) +{ + switch (p_key) { + // Esc + case 27: + m_editArea->getFindReplaceDialog()->closeDialog(); + break; + + default: + break; + } +} + diff --git a/src/vedittab.h b/src/vedittab.h index f156ccac..baf91cfb 100644 --- a/src/vedittab.h +++ b/src/vedittab.h @@ -15,6 +15,7 @@ class QWebEngineView; class VNote; class QXmlStreamReader; +class VEditArea; class VEditTab : public QStackedWidget { @@ -22,6 +23,7 @@ class VEditTab : public QStackedWidget public: VEditTab(VFile *p_file, OpenFileMode p_mode, QWidget *p_parent = 0); ~VEditTab(); + void init(VEditArea *p_editArea); bool closeFile(bool p_forced); // Enter edit mode void editFile(); @@ -63,6 +65,7 @@ private slots: void updateTocFromHeaders(const QVector &headers); void handleTextChanged(); void noticeStatusChanged(); + void handleWebKeyPressed(int p_key); private: void setupUI(); @@ -90,6 +93,7 @@ private: VToc tableOfContent; VAnchor curHeader; bool m_fileModified; + VEditArea *m_editArea; }; inline bool VEditTab::getIsEditMode() const diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp index 05e9cc1e..17b33d46 100644 --- a/src/veditwindow.cpp +++ b/src/veditwindow.cpp @@ -242,6 +242,7 @@ bool VEditWindow::closeAllFiles(bool p_forced) int VEditWindow::openFileInTab(VFile *p_file, OpenFileMode p_mode) { VEditTab *editor = new VEditTab(p_file, p_mode); + editor->init(m_editArea); connect(editor, &VEditTab::getFocused, this, &VEditWindow::getFocused); connect(editor, &VEditTab::outlineChanged,