mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
bug-fix: fix Command+-/= to zoom out/in in read mode on macOS
This commit is contained in:
parent
af8cd0d73b
commit
7f8075f0ca
@ -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;
|
||||
|
@ -794,6 +794,14 @@ QString VUtils::generateHtmlTemplate(const QString &p_template,
|
||||
|
||||
extraFile += "<script>var VStylesToInline = '" + g_config->getStylesToInlineWhenCopied() + "';</script>\n";
|
||||
|
||||
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
|
||||
extraFile += "<script>var VOS = 'mac';</script>\n";
|
||||
#elif defined(Q_OS_WIN)
|
||||
extraFile += "<script>var VOS = 'win';</script>\n";
|
||||
#else
|
||||
extraFile += "<script>var VOS = 'linux';</script>\n";
|
||||
#endif
|
||||
|
||||
QString htmlTemplate(p_template);
|
||||
htmlTemplate.replace(HtmlHolder::c_JSHolder, jsFile);
|
||||
if (!extraFile.isEmpty()) {
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user