editor: Ctrl+; to insert inline code, Ctrl+J/K to scroll page

This commit is contained in:
Le Tan 2018-07-07 17:57:00 +08:00
parent 7ef3d49c0c
commit d9c8051fa3
13 changed files with 66 additions and 26 deletions

View File

@ -64,6 +64,9 @@ Zoom in/out the page.
Zoom in/out the page through the mouse scroll.
- `Ctrl+0`
Recover the page zoom factor to 100%.
- `Ctrl+J/K`
Scroll page down/up without changing cursor.
#### Text Editing
- `Ctrl+B`
@ -72,8 +75,8 @@ Insert bold. Press `Ctrl+B` again to exit. Current selected text will be changed
Insert italic. Press `Ctrl+I` again to exit. Current selected text will be changed to italic if exists.
- `Ctrl+D`
Insert strikethrought. Press `Ctrl+D` again to exit. Current selected text will be changed to strikethrough if exists.
- `Ctrl+K`
Insert inline code. Press `Ctrl+K` again to exit. Current selected text will be changed to inline code if exists.
- `Ctrl+;`
Insert inline code. Press `Ctrl+;` again to exit. Current selected text will be changed to inline code if exists.
- `Ctrl+M`
Insert fenced code block. Press `Ctrl+M` again to exit. Current selected text will be wrapped into a code block if exists.
- `Ctrl+L`
@ -213,9 +216,9 @@ Popup the attachments list of current note.
- `X`
Close current tab.
- `J`
Jump to next tab.
Jump to the next tab.
- `K`
Jump to last tab.
Jump to the previous tab.
- `1` - `9`
Number key 1 to 9 will jump to the tabs with corresponding sequence number.
- `0`

View File

@ -64,6 +64,8 @@
鼠标滚轮实现放大/缩小页面。
- `Ctrl+0`
恢复页面大小为100%。
- `Ctrl+J/K`
向下/向上滚动页面,不会改变光标。
#### 文本编辑
- `Ctrl+B`
@ -72,8 +74,8 @@
插入斜体;再次按`Ctrl+I`退出。如果已经选择文本,则将当前选择文本改为斜体。
- `Ctrl+D`
插入删除线;再次按`Ctrl+D`退出。如果已经选择文本,则将当前选择文本改为删除线。
- `Ctrl+K`
插入行内代码;再次按`Ctrl+K`退出。如果已经选择文本,则将当前选择文本改为行内代码。
- `Ctrl+;`
插入行内代码;再次按`Ctrl+;`退出。如果已经选择文本,则将当前选择文本改为行内代码。
- `Ctrl+M`
插入代码块;再次按`Ctrl+M`退出。如果已经选择文本,则将当前选择文本嵌入到代码块中。
- `Ctrl+L`

View File

@ -2,6 +2,6 @@
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<text stroke="#000000" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " font-weight="bold" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_4" y="248.490375" x="-146.756839" stroke-width="0" fill="#000000">B</text>
<text stroke="#000000" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " font-weight="bold" xml:space="preserve" text-anchor="middle" font-family="sans-serif" font-size="24" id="svg_4" y="248.490375" x="-146.756839" stroke-width="0" fill="#000000">B</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 472 B

After

Width:  |  Height:  |  Size: 477 B

View File

@ -1,6 +1,6 @@
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<text style="cursor: move;" fill="#000000" stroke-width="0" x="-146.75684" y="248.49038" id="svg_4" font-size="24" font-family="serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000">#</text>
<text style="cursor: move;" fill="#000000" stroke-width="0" x="-146.75684" y="248.49038" id="svg_4" font-size="24" font-family="sans-serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000">#</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 472 B

After

Width:  |  Height:  |  Size: 477 B

View File

@ -2,6 +2,6 @@
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<text stroke="#000000" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " font-weight="normal" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_4" y="248.490375" x="-146.756839" stroke-width="0" fill="#000000">H</text>
<text style="cursor: move;" fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="sans-serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">H</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 474 B

After

Width:  |  Height:  |  Size: 521 B

View File

@ -2,6 +2,6 @@
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<text style="cursor: move;" fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">K</text>
<text style="cursor: move;" fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="sans-serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">C</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 516 B

After

Width:  |  Height:  |  Size: 521 B

View File

@ -2,6 +2,6 @@
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<text font-style="italic" stroke="#000000" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " font-weight="normal" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_4" y="248.490375" x="-146.756839" stroke-width="0" fill="#000000">I</text>
<text font-style="italic" stroke="#000000" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " font-weight="normal" xml:space="preserve" text-anchor="middle" font-family="sans-serif" font-size="24" id="svg_4" y="248.490375" x="-146.756839" stroke-width="0" fill="#000000">I</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 493 B

After

Width:  |  Height:  |  Size: 499 B

View File

@ -2,7 +2,7 @@
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<text fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">D</text>
<text fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="sans-serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">S</text>
<rect stroke="#000000" fill="#000000" stroke-width="5" x="91" y="262" width="325" height="21" id="svg_2" stroke-opacity="0"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 622 B

After

Width:  |  Height:  |  Size: 627 B

View File

@ -305,6 +305,7 @@ document.onkeydown = function(e) {
shift = !!e.shiftKey;
ctrl = !!e.ctrlKey;
meta = !!e.metaKey;
var isCtrl = VOS == 'mac' ? e.metaKey : e.ctrlKey;
switch (key) {
// Skip Ctrl, Shift, Alt, Supper.
case 16:
@ -349,7 +350,7 @@ document.onkeydown = function(e) {
}
case 74: // J
if (!ctrl && !shift && !meta) {
if (!shift && (!ctrl || isCtrl) && (!meta || isCtrl)) {
window.scrollBy(0, 100);
break;
}
@ -358,7 +359,7 @@ document.onkeydown = function(e) {
break;
case 75: // K
if (!ctrl && !shift && !meta) {
if (!shift && (!ctrl || isCtrl) && (!meta || isCtrl)) {
window.scrollBy(0, -100);
break;
}

View File

@ -93,7 +93,7 @@ enable_smart_im_in_vim_mode=true
; Display an area besides the editor area to show line number
; 0 - None, 1 - Absolute, 2 - Relative, 3 - CodeBlock
editor_line_number=0
editor_line_number=1
; Whether minimize to system tray when closing the app
; -1: uninitialized, prompt user for the behavior

View File

@ -777,6 +777,12 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
processCommand(m_tokens);
}
} else if (VUtils::isControlModifierForVim(modifiers)) {
if (key == Qt::Key_J || key == Qt::Key_K) {
// Let it be handled outside.
resetState();
goto exit;
}
}
break;

View File

@ -535,7 +535,7 @@ QToolBar *VMainWindow::initEditToolBar(QSize p_iconSize)
m_editToolBar->addAction(strikethroughAct);
QAction *inlineCodeAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/inline_code.svg"),
tr("Inline Code\t%1").arg(VUtils::getShortcutText("Ctrl+K")),
tr("Inline Code\t%1").arg(VUtils::getShortcutText("Ctrl+;")),
this);
inlineCodeAct->setStatusTip(tr("Insert inline-code text or change selected text to inline-coded"));
connect(inlineCodeAct, &QAction::triggered,

View File

@ -12,6 +12,8 @@
#include <QGuiApplication>
#include <QApplication>
#include <QClipboard>
#include <QScrollBar>
#include "vmdeditoperations.h"
#include "dialog/vinsertimagedialog.h"
#include "dialog/vselectdialog.h"
@ -333,7 +335,7 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
break;
}
case Qt::Key_K:
case Qt::Key_Semicolon:
{
if (modifiers == Qt::ControlModifier) {
decorateInlineCode();
@ -403,6 +405,32 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
break;
}
case Qt::Key_J:
{
if (VUtils::isControlModifierForVim(modifiers)) {
// Scroll down without changing cursor.
QScrollBar *vbar = m_editor->verticalScrollBarW();
if (vbar && (vbar->minimum() != vbar->maximum())) {
vbar->triggerAction(QAbstractSlider::SliderSingleStepAdd);
}
}
break;
}
case Qt::Key_K:
{
if (VUtils::isControlModifierForVim(modifiers)) {
// Scroll up without changing cursor.
QScrollBar *vbar = m_editor->verticalScrollBarW();
if (vbar && (vbar->minimum() != vbar->maximum())) {
vbar->triggerAction(QAbstractSlider::SliderSingleStepSub);
}
}
break;
}
default:
break;
}