mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-25 08:28:11 +00:00
Disable some codeEditor hotkeys if not in a gfm langauge editor.
This might not be the most elegant way to do this. I was not able to find, in quick searches, a method of adding/removing extraKeys outside of instantiation.
This commit is contained in:
@@ -207,6 +207,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeHeader : function (number) {
|
makeHeader : function (number) {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection();
|
const selection = this.codeMirror.getSelection();
|
||||||
const header = Array(number).fill('#').join('');
|
const header = Array(number).fill('#').join('');
|
||||||
this.codeMirror.replaceSelection(`${header} ${selection}`, 'around');
|
this.codeMirror.replaceSelection(`${header} ${selection}`, 'around');
|
||||||
@@ -215,6 +216,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeBold : function() {
|
makeBold : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '**' && selection.slice(-2) === '**';
|
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '**' && selection.slice(-2) === '**';
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `**${selection}**`, 'around');
|
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `**${selection}**`, 'around');
|
||||||
if(selection.length === 0){
|
if(selection.length === 0){
|
||||||
@@ -224,6 +226,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeItalic : function() {
|
makeItalic : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 1) === '*' && selection.slice(-1) === '*';
|
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 1) === '*' && selection.slice(-1) === '*';
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(1, -1) : `*${selection}*`, 'around');
|
this.codeMirror.replaceSelection(t ? selection.slice(1, -1) : `*${selection}*`, 'around');
|
||||||
if(selection.length === 0){
|
if(selection.length === 0){
|
||||||
@@ -233,6 +236,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeSuper : function() {
|
makeSuper : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 1) === '^' && selection.slice(-1) === '^';
|
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 1) === '^' && selection.slice(-1) === '^';
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(1, -1) : `^${selection}^`, 'around');
|
this.codeMirror.replaceSelection(t ? selection.slice(1, -1) : `^${selection}^`, 'around');
|
||||||
if(selection.length === 0){
|
if(selection.length === 0){
|
||||||
@@ -242,6 +246,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeSub : function() {
|
makeSub : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '^^' && selection.slice(-2) === '^^';
|
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '^^' && selection.slice(-2) === '^^';
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `^^${selection}^^`, 'around');
|
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `^^${selection}^^`, 'around');
|
||||||
if(selection.length === 0){
|
if(selection.length === 0){
|
||||||
@@ -252,10 +257,12 @@ const CodeEditor = createClass({
|
|||||||
|
|
||||||
|
|
||||||
makeNbsp : function() {
|
makeNbsp : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
this.codeMirror.replaceSelection(' ', 'end');
|
this.codeMirror.replaceSelection(' ', 'end');
|
||||||
},
|
},
|
||||||
|
|
||||||
makeSpace : function() {
|
makeSpace : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection();
|
const selection = this.codeMirror.getSelection();
|
||||||
const t = selection.slice(0, 8) === '{{width:' && selection.slice(0 -4) === '% }}';
|
const t = selection.slice(0, 8) === '{{width:' && selection.slice(0 -4) === '% }}';
|
||||||
if(t){
|
if(t){
|
||||||
@@ -267,6 +274,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeSpace : function() {
|
removeSpace : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection();
|
const selection = this.codeMirror.getSelection();
|
||||||
const t = selection.slice(0, 8) === '{{width:' && selection.slice(0 -4) === '% }}';
|
const t = selection.slice(0, 8) === '{{width:' && selection.slice(0 -4) === '% }}';
|
||||||
if(t){
|
if(t){
|
||||||
@@ -276,10 +284,12 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
newColumn : function() {
|
newColumn : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
this.codeMirror.replaceSelection('\n\\column\n\n', 'end');
|
this.codeMirror.replaceSelection('\n\\column\n\n', 'end');
|
||||||
},
|
},
|
||||||
|
|
||||||
newPage : function() {
|
newPage : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
this.codeMirror.replaceSelection('\n\\page\n\n', 'end');
|
this.codeMirror.replaceSelection('\n\\page\n\n', 'end');
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -293,6 +303,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeUnderline : function() {
|
makeUnderline : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 3) === '<u>' && selection.slice(-4) === '</u>';
|
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 3) === '<u>' && selection.slice(-4) === '</u>';
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(3, -4) : `<u>${selection}</u>`, 'around');
|
this.codeMirror.replaceSelection(t ? selection.slice(3, -4) : `<u>${selection}</u>`, 'around');
|
||||||
if(selection.length === 0){
|
if(selection.length === 0){
|
||||||
@@ -302,6 +313,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeSpan : function() {
|
makeSpan : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '{{' && selection.slice(-2) === '}}';
|
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '{{' && selection.slice(-2) === '}}';
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `{{ ${selection}}}`, 'around');
|
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `{{ ${selection}}}`, 'around');
|
||||||
if(selection.length === 0){
|
if(selection.length === 0){
|
||||||
@@ -311,6 +323,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeDiv : function() {
|
makeDiv : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '{{' && selection.slice(-2) === '}}';
|
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '{{' && selection.slice(-2) === '}}';
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `{{\n${selection}\n}}`, 'around');
|
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `{{\n${selection}\n}}`, 'around');
|
||||||
if(selection.length === 0){
|
if(selection.length === 0){
|
||||||
@@ -341,6 +354,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeLink : function() {
|
makeLink : function() {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const isLink = /^\[(.*)\]\((.*)\)$/;
|
const isLink = /^\[(.*)\]\((.*)\)$/;
|
||||||
const selection = this.codeMirror.getSelection().trim();
|
const selection = this.codeMirror.getSelection().trim();
|
||||||
let match;
|
let match;
|
||||||
@@ -358,6 +372,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
makeList : function(listType) {
|
makeList : function(listType) {
|
||||||
|
if(this.props.language !== 'gfm') return;
|
||||||
const selectionStart = this.codeMirror.getCursor('from'), selectionEnd = this.codeMirror.getCursor('to');
|
const selectionStart = this.codeMirror.getCursor('from'), selectionEnd = this.codeMirror.getCursor('to');
|
||||||
this.codeMirror.setSelection(
|
this.codeMirror.setSelection(
|
||||||
{ line: selectionStart.line, ch: 0 },
|
{ line: selectionStart.line, ch: 0 },
|
||||||
|
|||||||
Reference in New Issue
Block a user