diff --git a/src/resources/markdown_template.js b/src/resources/markdown_template.js index d3ea880c..5452f5e4 100644 --- a/src/resources/markdown_template.js +++ b/src/resources/markdown_template.js @@ -88,6 +88,10 @@ if (typeof VAddTOC == 'undefined') { VAddTOC = false; } +if (typeof VOS == 'undefined') { + VOS = 'win'; +} + // Whether highlight special blocks like puml, flowchart. var highlightSpecialBlocks = false; @@ -287,6 +291,7 @@ document.onkeydown = function(e) { var key; var shift; var ctrl; + var meta; if (e.which) { key = e.which; } else { @@ -295,12 +300,14 @@ document.onkeydown = function(e) { shift = !!e.shiftKey; ctrl = !!e.ctrlKey; + meta = !!e.metaKey; switch (key) { // Skip Ctrl, Shift, Alt, Supper. case 16: case 17: case 18: case 91: + case 92: clear = false; break; @@ -326,7 +333,7 @@ document.onkeydown = function(e) { case 104: case 105: { - if (pendingKeys.length != 0 || ctrl || shift) { + if (pendingKeys.length != 0 || ctrl || shift || meta) { accept = false; break; } @@ -338,7 +345,7 @@ document.onkeydown = function(e) { } case 74: // J - if (!ctrl && !shift) { + if (!ctrl && !shift && !meta) { window.scrollBy(0, 100); break; } @@ -347,7 +354,7 @@ document.onkeydown = function(e) { break; case 75: // K - if (!ctrl && !shift) { + if (!ctrl && !shift && !meta) { window.scrollBy(0, -100); break; } @@ -356,7 +363,7 @@ document.onkeydown = function(e) { break; case 72: // H - if (!ctrl && !shift) { + if (!ctrl && !shift && !meta) { window.scrollBy(-100, 0); break; } @@ -365,7 +372,7 @@ document.onkeydown = function(e) { break; case 76: // L - if (!ctrl && !shift) { + if (!ctrl && !shift && !meta) { window.scrollBy(100, 0); break; } @@ -381,7 +388,7 @@ document.onkeydown = function(e) { window.scrollTo(scrollLeft, scrollHeight); break; } - } else if (!ctrl) { + } else if (!ctrl && !meta) { if (pendingKeys.length == 0) { // First g, pend it. pendingKeys.push({ @@ -440,7 +447,7 @@ document.onkeydown = function(e) { break; } } - } else if (!ctrl) { + } else if (!ctrl && !meta) { // [ if (pendingKeys.length == 0) { // First [, pend it. @@ -483,7 +490,7 @@ document.onkeydown = function(e) { break; } } - } else if (!ctrl) { + } else if (!ctrl && !meta) { // ] if (pendingKeys.length == 0) { // First ], pend it. @@ -526,7 +533,7 @@ document.onkeydown = function(e) { if (accept) { e.preventDefault(); } else { - content.keyPressEvent(key, ctrl, shift); + content.keyPressEvent(key, ctrl, shift, meta); } }; @@ -994,9 +1001,10 @@ var vds_scrolled = false; window.onmousedown = function(e) { e = e || window.event; + var isCtrl = VOS == 'mac' ? e.metaKey : e.ctrlKey; // Left button and Ctrl key. if (e.buttons == 1 - && e.ctrlKey + && isCtrl && window.getSelection().type != 'Range') { vds_oriMouseClientX = e.clientX; vds_oriMouseClientY = e.clientY; diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index a7fb3888..4d7cb41b 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -794,6 +794,14 @@ QString VUtils::generateHtmlTemplate(const QString &p_template, extraFile += "\n"; +#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) + extraFile += "\n"; +#elif defined(Q_OS_WIN) + extraFile += "\n"; +#else + extraFile += "\n"; +#endif + QString htmlTemplate(p_template); htmlTemplate.replace(HtmlHolder::c_JSHolder, jsFile); if (!extraFile.isEmpty()) { diff --git a/src/vdocument.cpp b/src/vdocument.cpp index 78e812ae..3aa5f5db 100644 --- a/src/vdocument.cpp +++ b/src/vdocument.cpp @@ -69,9 +69,9 @@ void VDocument::setLog(const QString &p_log) emit logChanged(p_log); } -void VDocument::keyPressEvent(int p_key, bool p_ctrl, bool p_shift) +void VDocument::keyPressEvent(int p_key, bool p_ctrl, bool p_shift, bool p_meta) { - emit keyPressed(p_key, p_ctrl, p_shift); + emit keyPressed(p_key, p_ctrl, p_shift, p_meta); } void VDocument::highlightTextAsync(const QString &p_text, int p_id, int p_timeStamp) diff --git a/src/vdocument.h b/src/vdocument.h index fc2eecd1..cbe5555f 100644 --- a/src/vdocument.h +++ b/src/vdocument.h @@ -81,7 +81,7 @@ public slots: void setHeader(const QString &anchor); void setLog(const QString &p_log); - void keyPressEvent(int p_key, bool p_ctrl, bool p_shift); + void keyPressEvent(int p_key, bool p_ctrl, bool p_shift, bool p_meta); void updateText(); void highlightTextCB(const QString &p_html, int p_id, int p_timeStamp); @@ -126,7 +126,7 @@ signals: void logChanged(const QString &p_log); - void keyPressed(int p_key, bool p_ctrl, bool p_shift); + void keyPressed(int p_key, bool p_ctrl, bool p_shift, bool p_meta); void requestHighlightText(const QString &p_text, int p_id, int p_timeStamp); diff --git a/src/vmdtab.cpp b/src/vmdtab.cpp index ceb84e79..fd274fb7 100644 --- a/src/vmdtab.cpp +++ b/src/vmdtab.cpp @@ -709,10 +709,17 @@ void VMdTab::clearSearchedWordHighlight() } } -void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift) +void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift, bool p_meta) { V_ASSERT(m_webViewer); +#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) + bool macCtrl = p_meta; +#else + Q_UNUSED(p_meta); + bool macCtrl = false; +#endif + switch (p_key) { // Esc case 27: @@ -721,7 +728,7 @@ void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift) // Dash case 189: - if (p_ctrl) { + if (p_ctrl || macCtrl) { // Zoom out. zoomWebPage(false); } @@ -730,7 +737,7 @@ void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift) // Equal case 187: - if (p_ctrl) { + if (p_ctrl || macCtrl) { // Zoom in. zoomWebPage(true); } @@ -739,7 +746,7 @@ void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift) // 0 case 48: - if (p_ctrl) { + if (p_ctrl || macCtrl) { // Recover zoom. m_webViewer->setZoomFactor(1); } diff --git a/src/vmdtab.h b/src/vmdtab.h index 7e723447..11c32657 100644 --- a/src/vmdtab.h +++ b/src/vmdtab.h @@ -131,7 +131,7 @@ private slots: void updateCurrentHeader(int p_blockNumber); // Handle key press event in Web view. - void handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift); + void handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift, bool p_meta); // m_editor requests to save changes and enter read mode. void saveAndRead();