diff --git a/src/resources/docs/shortcuts_en.md b/src/resources/docs/shortcuts_en.md index 4261870f..cdb6e1f5 100644 --- a/src/resources/docs/shortcuts_en.md +++ b/src/resources/docs/shortcuts_en.md @@ -42,11 +42,13 @@ Save current changes and exit edit mode. #### Text Editing - `Ctrl+B` -Insert bold. Press `Ctrl+B` again to exit. Currently selected text will be changed to bold if exist. +Insert bold. Press `Ctrl+B` again to exit. Current selected text will be changed to bold if exist. - `Ctrl+I` -Insert italic. Press `Ctrl+I` again to exit. Currently selected text will be changed to italic if exist. +Insert italic. Press `Ctrl+I` again to exit. Current selected text will be changed to italic if exist. +- `Ctrl+D` +Insert strikethrought. Press `Ctrl+D` again to exit. Current selected text will be changed to strikethrough if exist. - `Ctrl+O` -Insert inline code. Press `Ctrl+O` again to exit. Currently selected text will be changed to inline code if exist. +Insert inline code. Press `Ctrl+O` again to exit. Current selected text will be changed to inline code if exist. - `Ctrl+H` Backspace. Delete a character backward. - `Ctrl+W` @@ -54,7 +56,7 @@ Delete all the characters from current cursor to the first space backward. - `Ctrl+U` Delete all the characters from current cursor to the beginning of current line. - `Ctrl+` -Insert title at level ``. `` should be 1 to 6. Currently selected text will be changed to title if exist. +Insert title at level ``. `` should be 1 to 6. Current selected text will be changed to title if exist. - `Tab`/`Shift+Tab` Increase or decrease the indentation. If any text is selected, the indentation will operate on all these selected lines. - `Shift+Enter` diff --git a/src/resources/docs/shortcuts_zh.md b/src/resources/docs/shortcuts_zh.md index 6246db89..e1a4f0c5 100644 --- a/src/resources/docs/shortcuts_zh.md +++ b/src/resources/docs/shortcuts_zh.md @@ -45,6 +45,8 @@ 插入粗体;再次按`Ctrl+B`退出。如果已经选择文本,则将当前选择文本加粗。 - `Ctrl+I` 插入斜体;再次按`Ctrl+I`退出。如果已经选择文本,则将当前选择文本改为斜体。 +- `Ctrl+D` +插入删除线;再次按`Ctrl+D`退出。如果已经选择文本,则将当前选择文本改为删除线。 - `Ctrl+O` 插入行内代码;再次按`Ctrl+O`退出。如果已经选择文本,则将当前选择文本改为行内代码。 - `Ctrl+H` diff --git a/src/resources/icons/strikethrough.svg b/src/resources/icons/strikethrough.svg index 2ae29a98..d44defe2 100644 --- a/src/resources/icons/strikethrough.svg +++ b/src/resources/icons/strikethrough.svg @@ -2,7 +2,7 @@ Layer 1 - S - + D + - \ No newline at end of file + diff --git a/src/resources/icons/underline.svg b/src/resources/icons/underline.svg deleted file mode 100644 index 2ef3453f..00000000 --- a/src/resources/icons/underline.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - Layer 1 - U - - - \ No newline at end of file diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 6e31648a..e5774abd 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -187,21 +187,24 @@ void VMainWindow::initViewToolBar() QAction *onePanelViewAct = new QAction(QIcon(":/resources/icons/one_panel.svg"), tr("&Single Panel"), this); onePanelViewAct->setStatusTip(tr("Display only the notes list panel")); + onePanelViewAct->setToolTip(tr("Single Panel (Ctrl+E P)")); connect(onePanelViewAct, &QAction::triggered, this, &VMainWindow::onePanelView); QAction *twoPanelViewAct = new QAction(QIcon(":/resources/icons/two_panels.svg"), tr("&Two Panels"), this); twoPanelViewAct->setStatusTip(tr("Display both the folders and notes list panel")); + twoPanelViewAct->setToolTip(tr("Two Panels (Ctrl+E P)")); connect(twoPanelViewAct, &QAction::triggered, this, &VMainWindow::twoPanelView); QMenu *panelMenu = new QMenu(this); + panelMenu->setToolTipsVisible(true); panelMenu->addAction(onePanelViewAct); panelMenu->addAction(twoPanelViewAct); expandViewAct = new QAction(QIcon(":/resources/icons/expand.svg"), - tr("Expand"), this); + tr("Expand (Ctrl+E E)"), this); expandViewAct->setStatusTip(tr("Expand the edit area")); expandViewAct->setCheckable(true); expandViewAct->setMenu(panelMenu); @@ -229,7 +232,7 @@ void VMainWindow::initEditToolBar() m_editToolBar->addSeparator(); QAction *boldAct = new QAction(QIcon(":/resources/icons/bold.svg"), - tr("Bold"), this); + tr("Bold (Ctrl+B)"), this); boldAct->setStatusTip(tr("Insert bold text or change selected text to bold")); connect(boldAct, &QAction::triggered, this, [this](){ @@ -241,7 +244,7 @@ void VMainWindow::initEditToolBar() m_editToolBar->addAction(boldAct); QAction *italicAct = new QAction(QIcon(":/resources/icons/italic.svg"), - tr("Italic"), this); + tr("Italic (Ctrl+I)"), this); italicAct->setStatusTip(tr("Insert italic text or change selected text to italic")); connect(italicAct, &QAction::triggered, this, [this](){ @@ -252,20 +255,8 @@ void VMainWindow::initEditToolBar() m_editToolBar->addAction(italicAct); - QAction *underlineAct = new QAction(QIcon(":/resources/icons/underline.svg"), - tr("Underline"), this); - underlineAct->setStatusTip(tr("Insert underlined text or change selected text to underlined")); - connect(underlineAct, &QAction::triggered, - this, [this](){ - if (m_curTab) { - m_curTab->decorateText(TextDecoration::Underline); - } - }); - - m_editToolBar->addAction(underlineAct); - QAction *strikethroughAct = new QAction(QIcon(":/resources/icons/strikethrough.svg"), - tr("Strikethrough"), this); + tr("Strikethrough (Ctrl+D)"), this); strikethroughAct->setStatusTip(tr("Insert strikethrough text or change selected text to strikethroughed")); connect(strikethroughAct, &QAction::triggered, this, [this](){ @@ -277,7 +268,7 @@ void VMainWindow::initEditToolBar() m_editToolBar->addAction(strikethroughAct); QAction *inlineCodeAct = new QAction(QIcon(":/resources/icons/inline_code.svg"), - tr("Inline Code"), this); + tr("Inline Code (Ctrl+O)"), this); inlineCodeAct->setStatusTip(tr("Insert inline-code text or change selected text to inline-coded")); connect(inlineCodeAct, &QAction::triggered, this, [this](){ @@ -336,14 +327,16 @@ void VMainWindow::initFileToolBar() discardExitAct = new QAction(QIcon(":/resources/icons/discard_exit.svg"), tr("Discard Changes And Read"), this); discardExitAct->setStatusTip(tr("Discard changes and exit edit mode")); + discardExitAct->setToolTip(tr("Discard Changes And Read (Ctrl+E Q)")); connect(discardExitAct, &QAction::triggered, editArea, &VEditArea::readFile); QMenu *exitEditMenu = new QMenu(this); + exitEditMenu->setToolTipsVisible(true); exitEditMenu->addAction(discardExitAct); saveExitAct = new QAction(QIcon(":/resources/icons/save_exit.svg"), - tr("Save Changes And Read"), this); + tr("Save Changes And Read (Ctrl+T)"), this); saveExitAct->setStatusTip(tr("Save changes and exit edit mode")); saveExitAct->setMenu(exitEditMenu); saveExitAct->setShortcut(QKeySequence("Ctrl+T")); diff --git a/src/vmdeditoperations.cpp b/src/vmdeditoperations.cpp index 9a65e74b..13c9c2f8 100644 --- a/src/vmdeditoperations.cpp +++ b/src/vmdeditoperations.cpp @@ -328,6 +328,17 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event) break; } + case Qt::Key_D: + { + if (modifiers == Qt::ControlModifier) { + decorateStrikethrough(); + p_event->accept(); + ret = true; + } + + break; + } + default: break; } @@ -653,18 +664,24 @@ void VMdEditOperations::decorateText(TextDecoration p_decoration) return; } - m_vim->setMode(VimMode::Insert, false); - switch (p_decoration) { case TextDecoration::Bold: + m_vim->setMode(VimMode::Insert, false); decorateBold(); break; case TextDecoration::Italic: + m_vim->setMode(VimMode::Insert, false); decorateItalic(); break; + case TextDecoration::Strikethrough: + m_vim->setMode(VimMode::Insert, false); + decorateStrikethrough(); + break; + case TextDecoration::InlineCode: + m_vim->setMode(VimMode::Insert, false); decorateInlineCode(); break; @@ -784,3 +801,40 @@ void VMdEditOperations::decorateInlineCode() cursor.endEditBlock(); m_editor->setTextCursor(cursor); } + +void VMdEditOperations::decorateStrikethrough() +{ + QTextCursor cursor = m_editor->textCursor(); + cursor.beginEditBlock(); + if (cursor.hasSelection()) { + // Insert ~~ around the selected text. + int start = cursor.selectionStart(); + int end = cursor.selectionEnd(); + cursor.clearSelection(); + cursor.setPosition(start, QTextCursor::MoveAnchor); + cursor.insertText("~~"); + cursor.setPosition(end + 2, QTextCursor::MoveAnchor); + cursor.insertText("~~"); + } else { + // Insert ~~~~ and place cursor in the middle. + // Or if there are one ~~ after current cursor, just skip it. + int pos = cursor.positionInBlock(); + bool hasStrikethrough = false; + QString text = cursor.block().text(); + if (pos <= text.size() - 2) { + if (text[pos] == '~' && text[pos + 1] == '~') { + hasStrikethrough = true; + } + } + + if (hasStrikethrough) { + cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 2); + } else { + cursor.insertText("~~~~"); + cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 2); + } + } + + cursor.endEditBlock(); + m_editor->setTextCursor(cursor); +} diff --git a/src/vmdeditoperations.h b/src/vmdeditoperations.h index c297c49b..c2aaa8bc 100644 --- a/src/vmdeditoperations.h +++ b/src/vmdeditoperations.h @@ -56,6 +56,9 @@ private: // Insert inline-code marker or set selected text inline-coded. void decorateInlineCode(); + // Insert strikethrough marker or set selected text strikethrough. + void decorateStrikethrough(); + // The cursor position after auto indent or auto list. // It will be -1 if last key press do not trigger the auto indent or auto list. int m_autoIndentPos; diff --git a/src/vnote.qrc b/src/vnote.qrc index f9a8cc1e..f6f58715 100644 --- a/src/vnote.qrc +++ b/src/vnote.qrc @@ -113,7 +113,6 @@ utils/flowchart.js/raphael.min.js resources/icons/bold.svg resources/icons/italic.svg - resources/icons/underline.svg resources/icons/strikethrough.svg resources/icons/inline_code.svg