mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
Merge pull request #4145 from ErisDS/pr/3484
Enable cycling header levels with ctrl+h.
This commit is contained in:
commit
5bae948c69
@ -53,17 +53,17 @@
|
||||
<tr>
|
||||
<td>H1</td>
|
||||
<td># Heading</td>
|
||||
<td>Ctrl + Alt + 1</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>H2</td>
|
||||
<td>## Heading</td>
|
||||
<td>Ctrl + Alt + 2</td>
|
||||
<td>Ctrl/⌘ + H</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>H3</td>
|
||||
<td>### Heading</td>
|
||||
<td>Ctrl + Alt + 3</td>
|
||||
<td>Ctrl/⌘ + H (x2)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -6,6 +6,9 @@
|
||||
import titleize from 'ghost/utils/titleize';
|
||||
|
||||
function init() {
|
||||
// remove predefined `ctrl+h` shortcut
|
||||
delete CodeMirror.keyMap.emacsy['Ctrl-H'];
|
||||
|
||||
//Used for simple, noncomputational replace-and-go! shortcuts.
|
||||
// See default case in shortcut function below.
|
||||
CodeMirror.prototype.simpleShortcutSyntax = {
|
||||
@ -24,39 +27,27 @@ function init() {
|
||||
fromLineStart = {line: cursor.line, ch: 0},
|
||||
toLineEnd = {line: cursor.line, ch: line.length},
|
||||
md, letterCount, textIndex, position, converter,
|
||||
generatedHTML;
|
||||
generatedHTML, match, currentHeaderLevel, hashPrefix,
|
||||
replacementLine;
|
||||
|
||||
switch (type) {
|
||||
case 'h1':
|
||||
line = line.replace(/^#* /, '');
|
||||
this.replaceRange('# ' + line, fromLineStart, toLineEnd);
|
||||
this.setCursor(cursor.line, cursor.ch + 2);
|
||||
return;
|
||||
case 'h2':
|
||||
line = line.replace(/^#* /, '');
|
||||
this.replaceRange('## ' + line, fromLineStart, toLineEnd);
|
||||
this.setCursor(cursor.line, cursor.ch + 3);
|
||||
return;
|
||||
case 'h3':
|
||||
line = line.replace(/^#* /, '');
|
||||
this.replaceRange('### ' + line, fromLineStart, toLineEnd);
|
||||
this.setCursor(cursor.line, cursor.ch + 4);
|
||||
return;
|
||||
case 'h4':
|
||||
line = line.replace(/^#* /, '');
|
||||
this.replaceRange('#### ' + line, fromLineStart, toLineEnd);
|
||||
this.setCursor(cursor.line, cursor.ch + 5);
|
||||
return;
|
||||
case 'h5':
|
||||
line = line.replace(/^#* /, '');
|
||||
this.replaceRange('##### ' + line, fromLineStart, toLineEnd);
|
||||
this.setCursor(cursor.line, cursor.ch + 6);
|
||||
return;
|
||||
case 'h6':
|
||||
line = line.replace(/^#* /, '');
|
||||
this.replaceRange('###### ' + line, fromLineStart, toLineEnd);
|
||||
this.setCursor(cursor.line, cursor.ch + 7);
|
||||
return;
|
||||
case 'cycleHeaderLevel':
|
||||
match = line.match(/^#+/);
|
||||
|
||||
if (!match) {
|
||||
currentHeaderLevel = 1;
|
||||
} else {
|
||||
currentHeaderLevel = match[0].length;
|
||||
}
|
||||
|
||||
if (currentHeaderLevel > 2) { currentHeaderLevel = 1; }
|
||||
|
||||
hashPrefix = new Array(currentHeaderLevel + 2).join('#');
|
||||
replacementLine = hashPrefix + ' ' + line.replace(/^#* /, '');
|
||||
|
||||
this.replaceRange(replacementLine, fromLineStart, toLineEnd);
|
||||
this.setCursor(cursor.line, cursor.ch + replacementLine.length);
|
||||
break;
|
||||
case 'link':
|
||||
md = this.simpleShortcutSyntax.link.replace('$1', text);
|
||||
this.replaceSelection(md, 'end');
|
||||
@ -111,7 +102,7 @@ function init() {
|
||||
|
||||
// Talk to Ember
|
||||
this.component.sendAction('openModal', 'copy-html', { generatedHTML: generatedHTML });
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
if (this.simpleShortcutSyntax[type]) {
|
||||
|
@ -21,14 +21,7 @@ shortcuts['ctrl+U'] = {action: 'codeMirrorShortcut', options: {type: 'uppercase'
|
||||
shortcuts['ctrl+shift+U'] = {action: 'codeMirrorShortcut', options: {type: 'lowercase'}};
|
||||
shortcuts['ctrl+alt+shift+U'] = {action: 'codeMirrorShortcut', options: {type: 'titlecase'}};
|
||||
shortcuts[ctrlOrCmd + '+shift+c'] = {action: 'codeMirrorShortcut', options: {type: 'copyHTML'}};
|
||||
|
||||
//Headings
|
||||
shortcuts['ctrl+alt+1'] = {action: 'codeMirrorShortcut', options: {type: 'h1'}};
|
||||
shortcuts['ctrl+alt+2'] = {action: 'codeMirrorShortcut', options: {type: 'h2'}};
|
||||
shortcuts['ctrl+alt+3'] = {action: 'codeMirrorShortcut', options: {type: 'h3'}};
|
||||
shortcuts['ctrl+alt+4'] = {action: 'codeMirrorShortcut', options: {type: 'h4'}};
|
||||
shortcuts['ctrl+alt+5'] = {action: 'codeMirrorShortcut', options: {type: 'h5'}};
|
||||
shortcuts['ctrl+alt+6'] = {action: 'codeMirrorShortcut', options: {type: 'h6'}};
|
||||
shortcuts[ctrlOrCmd + '+h'] = {action: 'codeMirrorShortcut', options: {type: 'cycleHeaderLevel'}};
|
||||
|
||||
//Formatting
|
||||
shortcuts['ctrl+q'] = {action: 'codeMirrorShortcut', options: {type: 'blockquote'}};
|
||||
|
Loading…
Reference in New Issue
Block a user