mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Additional Keyboard Shortcuts and improvements to text highlighting
This fixes the event where text would be selected after manipulation from shortcut, the cursor is now placed after the text. On links and images the url field text is highlighted. Additional shortcuts; * Ctrl+U: Make text uppercase * Ctrl+Shift+U: Make text lowercase * Ctrl+Alt+Shift+U: Make text titlecase * Ctrl+Alt+W: Select word * Ctrl+L: Make into list
This commit is contained in:
parent
bf1bb25d06
commit
f6f095b381
2 changed files with 52 additions and 5 deletions
|
@ -15,10 +15,52 @@
|
|||
self.replace();
|
||||
},
|
||||
replace: function () {
|
||||
var text = this.elem.getSelection(), md;
|
||||
if (this.options.syntax[this.style]) {
|
||||
md = this.options.syntax[this.style].replace('$1', text);
|
||||
this.elem.replaceSelection(md);
|
||||
var text = this.elem.getSelection(), pass = true, md, cursor, word;
|
||||
switch (this.style) {
|
||||
case "link":
|
||||
md = this.options.syntax.link.replace('$1', text);
|
||||
this.elem.replaceSelection(md, "end");
|
||||
cursor = this.elem.getCursor();
|
||||
this.elem.setSelection({line: cursor.line, ch: cursor.ch - 8}, {line: cursor.line, ch: cursor.ch - 1});
|
||||
pass = false;
|
||||
break;
|
||||
case "image":
|
||||
md = this.options.syntax.image.replace('$1', text);
|
||||
this.elem.replaceSelection(md, "end");
|
||||
cursor = this.elem.getCursor();
|
||||
this.elem.setSelection({line: cursor.line, ch: cursor.ch - 8}, {line: cursor.line, ch: cursor.ch - 1});
|
||||
pass = false;
|
||||
break;
|
||||
case "uppercase":
|
||||
md = text.toLocaleUpperCase();
|
||||
break;
|
||||
case "lowercase":
|
||||
md = text.toLocaleLowerCase();
|
||||
break;
|
||||
case "titlecase":
|
||||
md = text.replace(/\w\S*/g, function (text) {return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase(); });
|
||||
break;
|
||||
case "selectword":
|
||||
cursor = this.elem.getCursor();
|
||||
word = this.elem.getTokenAt(cursor);
|
||||
if (!/\w$/g.test(word.string)) {
|
||||
this.elem.setSelection({line: cursor.line, ch: word.start}, {line: cursor.line, ch: word.end - 1});
|
||||
} else {
|
||||
this.elem.setSelection({line: cursor.line, ch: word.start}, {line: cursor.line, ch: word.end});
|
||||
}
|
||||
break;
|
||||
case "list":
|
||||
md = text.replace(/^/gm, "* ");
|
||||
this.elem.replaceSelection("\n" + md + "\n", "end");
|
||||
pass = false;
|
||||
break;
|
||||
default:
|
||||
if (this.options.syntax[this.style]) {
|
||||
md = this.options.syntax[this.style].replace('$1', text);
|
||||
}
|
||||
}
|
||||
if (pass && md) {
|
||||
this.elem.replaceSelection(md, "end");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -23,7 +23,12 @@
|
|||
{'key': 'Ctrl+Shift+L', 'style': 'link'},
|
||||
{'key': 'Ctrl+Shift+I', 'style': 'image'},
|
||||
{'key': 'Ctrl+Q', 'style': 'blockquote'},
|
||||
{'key': 'Ctrl+Shift+1', 'style': 'currentdate'}
|
||||
{'key': 'Ctrl+Shift+1', 'style': 'currentdate'},
|
||||
{'key': 'Ctrl+U', 'style': 'uppercase'},
|
||||
{'key': 'Ctrl+Shift+U', 'style': 'lowercase'},
|
||||
{'key': 'Ctrl+Alt+Shift+U', 'style': 'titlecase'},
|
||||
{'key': 'Ctrl+Alt+W', 'style': 'selectword'},
|
||||
{'key': 'Ctrl+L', 'style': 'list'}
|
||||
];
|
||||
|
||||
// The publish bar associated with a post, which has the TagWidget and
|
||||
|
|
Loading…
Add table
Reference in a new issue