-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added KeyBindings #103
Open
mohan-mu
wants to merge
8
commits into
jbt:master
Choose a base branch
from
mohan-mu:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
added KeyBindings #103
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0ca2c9e
added KeyBindings
mohan-mu 172c8a0
Update index.js
mohan-mu 56ae789
Update index.js
mohan-mu 53012be
Update index.js
mohan-mu b005a3b
Update index.js
mohan-mu 048ca27
new line fix after selection
mohan-mu 8c6058c
Update index.js
mohan-mu 24de85d
Update index.js
mohan-mu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,22 +106,126 @@ function selectionChanger(selection,operator,endoperator){ | |
} | ||
|
||
editor.addKeyMap({ | ||
// bold | ||
'Ctrl-B': function(cm) { | ||
cm.replaceSelection(selectionChanger(cm.getSelection(),'**')); | ||
}, | ||
// italic | ||
'Ctrl-I': function(cm) { | ||
cm.replaceSelection(selectionChanger(cm.getSelection(),'_')); | ||
}, | ||
// code | ||
'Ctrl-K': function(cm) { | ||
cm.replaceSelection(selectionChanger(cm.getSelection(),'`')); | ||
}, | ||
// keyboard shortcut | ||
'Ctrl-L': function(cm) { | ||
cm.replaceSelection(selectionChanger(cm.getSelection(),'<kbd>','</kbd>')); | ||
// bold | ||
'Ctrl-B': function(cm) { | ||
var selection = cm.getSelection(); | ||
cm.replaceSelection('**' + selection + '**'); | ||
if (!selection) { | ||
var cursorPos = cm.getCursor(); | ||
cm.setCursor(cursorPos.line, cursorPos.ch - 2); | ||
} | ||
}, | ||
// italic | ||
'Ctrl-I': function(cm) { | ||
var selection = cm.getSelection(); | ||
cm.replaceSelection('_' + selection + '_'); | ||
if (!selection) { | ||
var cursorPos = cm.getCursor(); | ||
cm.setCursor(cursorPos.line, cursorPos.ch - 1); | ||
} | ||
}, | ||
// code | ||
'Ctrl-K': function(cm) { | ||
var selection = cm.getSelection(); | ||
cm.replaceSelection('`' + selection + '`'); | ||
if (!selection) { | ||
var cursorPos = cm.getCursor(); | ||
cm.setCursor(cursorPos.line, cursorPos.ch - 1); | ||
} | ||
}, | ||
// keyboard shortcut | ||
'Ctrl-L': function(cm) { | ||
cm.replaceSelection(selectionChanger(cm.getSelection(), '<kbd>', '</kbd>')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your changes appear to change the code to be indented with 2 characters instead of 4, which is the current convention of the file. I'd appreciate if you could make sure the file remains consistent. |
||
}, | ||
//Heading 1 | ||
'Ctrl-Alt-1': function(cm) { | ||
cm.replaceSelection('# ' + cm.getSelection()); | ||
}, | ||
//Heading 2 | ||
'Ctrl-Alt-2': function(cm) { | ||
cm.replaceSelection('## ' + cm.getSelection()); | ||
}, | ||
//Heading 3 | ||
'Ctrl-Alt-3': function(cm) { | ||
cm.replaceSelection('### ' + cm.getSelection()); | ||
}, | ||
//Heading 4 | ||
'Ctrl-Alt-4': function(cm) { | ||
cm.replaceSelection('#### ' + cm.getSelection()); | ||
}, | ||
//Heading 5 | ||
'Ctrl-Alt-5': function(cm) { | ||
cm.replaceSelection('##### ' + cm.getSelection()); | ||
}, | ||
//Heading 6 | ||
'Ctrl-Alt-6': function(cm) { | ||
cm.replaceSelection('###### ' + cm.getSelection()); | ||
}, | ||
// Links | ||
'Shift-Ctrl-L': function(cm) { | ||
var selection = cm.getSelection(); | ||
var text = ''; | ||
var link = ''; | ||
|
||
if (selection.match(/^https?:\/\//)) { | ||
link = selection; | ||
} else { | ||
text = selection; | ||
} | ||
cm.replaceSelection('[' + text + '](' + link + ')'); | ||
|
||
var cursorPos = cm.getCursor(); | ||
if (!selection) { | ||
cm.setCursor(cursorPos.line, cursorPos.ch - 3); | ||
} else if (link) { | ||
cm.setCursor(cursorPos.line, cursorPos.ch - (3 + link.length)); | ||
} else { | ||
cm.setCursor(cursorPos.line, cursorPos.ch - 1); | ||
} | ||
}, | ||
// Insert Image | ||
'Shift-Ctrl-I': function(cm) { | ||
var selection = cm.getSelection(); | ||
var text = ''; | ||
var link = ''; | ||
|
||
if (selection.match(/^https?:\/\//)) { | ||
link = selection; | ||
} else { | ||
text = selection; | ||
} | ||
cm.replaceSelection('![' + text + '](' + link + ')'); | ||
|
||
var cursorPos = cm.getCursor(); | ||
if (!selection) { | ||
cm.setCursor(cursorPos.line, cursorPos.ch - 3); | ||
} else if (link) { | ||
cm.setCursor(cursorPos.line, cursorPos.ch - (3 + link.length)); | ||
} else { | ||
cm.setCursor(cursorPos.line, cursorPos.ch - 1); | ||
} | ||
}, | ||
//Unordered list | ||
'Shift-U': function(cm) { | ||
cm.replaceSelection('* ' + cm.getSelection()); | ||
}, | ||
//Ordered list | ||
'Shift-O': function(cm) { | ||
cm.replaceSelection('1. ' + cm.getSelection()); | ||
}, | ||
//Blockquote | ||
'Shift-Ctrl-.': function(cm) { | ||
cm.replaceSelection('> ' + cm.getSelection()); | ||
}, | ||
//codeblock | ||
"Shift-Ctrl-'": function(cm) { | ||
var selection = cm.getSelection(); | ||
cm.replaceSelection('```javascript' + '\n' + selection+'\n' +'```'); | ||
if (!selection) { | ||
var cursorPos = cm.getCursor(); | ||
cm.setCursor(cursorPos.line -1, cursorPos.ch); | ||
} | ||
}, | ||
}); | ||
|
||
document.addEventListener('drop', function(e) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change takes away the existing functionality where you could use CTRL+B to toggle bold. This would always add more text. For example, pressing the hotkey twice on 'hello' would result in:
Arguably, the first approach wasn't foolproof either, but this implementation is immediately broken.