Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ export default class CodeEditor extends React.Component {
'Cmd-T': function (cm) {
// Do nothing
},
'Cmd-I': cm => {
if (global.process.platform === 'darwin') this.applyItalic(cm)
},
'Ctrl-I': cm => {
if (global.process.platform !== 'darwin') this.applyItalic(cm)
},
'Cmd-B': cm => {
if (global.process.platform === 'darwin') this.applyBold(cm)
},
'Ctrl-B': cm => {
if (global.process.platform !== 'darwin') this.applyBold(cm)
},
Enter: 'boostNewLineAndIndentContinueMarkdownList',
'Ctrl-C': (cm) => {
if (cm.getOption('keyMap').substr(0, 3) === 'vim') {
Expand Down Expand Up @@ -184,6 +196,64 @@ export default class CodeEditor extends React.Component {
CodeMirror.Vim.map('ZZ', ':q', 'normal')
}

applyItalic (cm) {
if (cm.somethingSelected()) {
const selection = cm.getSelection()
const str = selection.trim()
const index = selection.indexOf(str)

if (str.length === 0 || str.match(/\n\s*\n/) !== null) return

let newString
const boldAndItalic = str.match(/^\*\*\*(.*)\*\*\*$/)
const bold = str.match(/^\*\*(.*)\*\*$/)
const italic = str.match(/^\*(.*)\*$/)
if (boldAndItalic !== null) {
newString = boldAndItalic[1]
newString = `**${newString}**`
} else if (bold !== null) {
newString = bold[1]
newString = `***${newString}***`
} else if (italic !== null) {
newString = italic[1]
} else {
newString = `*${str}*`
}

const newSelection = selection.substr(0, index) + newString + selection.substr(index + selection.length)
cm.replaceSelection(newSelection)
}
}

applyBold (cm) {
if (cm.somethingSelected()) {
const selection = cm.getSelection()
const str = selection.trim()
const index = selection.indexOf(str)

if (str.length === 0 || str.match(/\n\s*\n/) !== null) return

let newString
const boldAndItalic = str.match(/^\*\*\*(.*)\*\*\*$/)
const bold = str.match(/^\*\*(.*)\*\*$/)
const italic = str.match(/^\*(.*)\*$/)
if (boldAndItalic !== null) {
newString = boldAndItalic[1]
newString = `*${newString}*`
} else if (bold !== null) {
newString = bold[1]
} else if (italic !== null) {
newString = italic[1]
newString = `***${newString}***`
} else {
newString = `**${str}**`
}

const newSelection = selection.substr(0, index) + newString + selection.substr(index + selection.length)
cm.replaceSelection(newSelection)
}
}

expandSnippet (line, cursor, cm, snippets) {
const wordBeforeCursor = this.getWordBeforeCursor(line, cursor.line, cursor.ch)
const templateCursorString = ':{}'
Expand Down