Skip to content

Commit 0697bc0

Browse files
OlcodRokt33r
authored andcommitted
Add ability to sort lines with a hot key combination
1 parent 43d8ebb commit 0697bc0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

browser/components/CodeEditor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ export default class CodeEditor extends React.Component {
241241
const newCursorPos = cm.doc.posFromIndex(formattedCursorPos)
242242
cm.doc.setCursor(newCursorPos)
243243
},
244+
[translateHotkey(hotkey.sortLines)]: cm => {
245+
const selection = cm.doc.getSelection()
246+
const appendLineBreak = /\n$/.test(selection)
247+
248+
const sorted = _.split(selection.trim(), '\n').sort()
249+
const sortedString = _.join(sorted, '\n') + (appendLineBreak ? '\n' : '')
250+
251+
cm.doc.replaceSelection(sortedString)
252+
},
244253
[translateHotkey(hotkey.pasteSmartly)]: cm => {
245254
this.handlePaste(cm, true)
246255
}

browser/main/lib/ConfigManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const DEFAULT_CONFIG = {
3232
deleteNote: OSX ? 'Command + Shift + Backspace' : 'Ctrl + Shift + Backspace',
3333
pasteSmartly: OSX ? 'Command + Shift + V' : 'Ctrl + Shift + V',
3434
prettifyMarkdown: 'Shift + F',
35+
sortLines: OSX ? 'Command + Shift + S' : 'Ctrl + Shift + S',
3536
insertDate: OSX ? 'Command + /' : 'Ctrl + /',
3637
insertDateTime: OSX ? 'Command + Alt + /' : 'Ctrl + Shift + /',
3738
toggleMenuBar: 'Alt'

0 commit comments

Comments
 (0)