Feat: add highlight menu item (#1532)

This commit is contained in:
Ran Luo 2019-10-27 00:38:22 +08:00 committed by GitHub
parent 168257605f
commit ab97336e89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 16 deletions

View File

@ -110,6 +110,7 @@ Here is an example:
| `formatStrong` | <kbd>CmdOrCtrl</kbd>+<kbd>B</kbd> | Set the font of the selected text to bold |
| `formatEmphasis` | <kbd>CmdOrCtrl</kbd>+<kbd>I</kbd> | Set the font of the selected text to italic |
| `formatUnderline` | <kbd>CmdOrCtrl</kbd>+<kbd>U</kbd> | Change the selected text to underline |
| `highlight` | <kbd>CmdOrCtrl</kbd>+<kbd>Shift</kbd>+<kbd>H</kbd> | Highlight the selected text by <mark> tag |
| `formatInlineCode` | <kbd>CmdOrCtrl</kbd>+<kbd>`</kbd> | Change the selected text to inline code |
| `formatInlineMath` | <kbd>CmdOrCtrl</kbd>+<kbd>Shift</kbd>+<kbd>M</kbd> | Change the selected text to inline math |
| `formatStrike` | <kbd>CmdOrCtrl</kbd>+<kbd>D</kbd> | Strike through the selected text |

View File

@ -84,6 +84,7 @@ class Keybindings {
['formatStrong', 'CmdOrCtrl+B'],
['formatEmphasis', 'CmdOrCtrl+I'],
['formatUnderline', 'CmdOrCtrl+U'],
['highlight', 'Shift+CmdOrCtrl+H'],
['formatInlineCode', 'CmdOrCtrl+`'],
['formatInlineMath', 'Shift+CmdOrCtrl+M'],
['formatStrike', 'CmdOrCtrl+D'],

View File

@ -44,6 +44,14 @@ export default function (keybindings) {
click (menuItem, browserWindow) {
actions.format(browserWindow, 'sub')
}
}, {
id: 'highlightMenuItem',
label: 'Highlight',
type: 'checkbox',
accelerator: keybindings.getAccelerator('highlight'),
click (menuItem, browserWindow) {
actions.format(browserWindow, 'mark')
}
}, {
type: 'separator'
}, {

View File

@ -1,9 +1,12 @@
html {
-webkit-font-smoothing: antialiased;
}
pre {
-webkit-font-smoothing: auto;
@keyframes loading {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes highlight {
@ -18,15 +21,37 @@ pre {
}
}
@keyframes loading {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
html {
-webkit-font-smoothing: antialiased;
}
pre {
-webkit-font-smoothing: auto;
}
mark {
display: inline-block;
height: 1.2em;
line-height: 1.2;
}
mark::before,
mark::after {
clip-path: inset(100%);
clip: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
mark::before {
content: " [highlight start] ";
}
mark::after {
content: " [highlight end] ";
}
#ag-editor-id summary {

View File

@ -206,6 +206,10 @@ export const FORMAT_MARKER_MAP = {
sup: {
open: '<sup>',
close: '</sup>'
},
mark: {
open: '<mark>',
close: '</mark>'
}
}

View File

@ -104,6 +104,7 @@ const addFormat = (type, block, { start, end }) => {
}
case 'sub':
case 'sup':
case 'mark':
case 'u': {
const MARKER = FORMAT_MARKER_MAP[type]
const oldText = block.text
@ -133,7 +134,7 @@ const addFormat = (type, block, { start, end }) => {
const checkTokenIsInlineFormat = token => {
const { type, tag } = token
if (FORMAT_TYPES.includes(type)) return true
if (type === 'html_tag' && /^(?:u|sub|sup)$/i.test(tag)) return true
if (type === 'html_tag' && /^(?:u|sub|sup|mark)$/i.test(tag)) return true
return false
}