Skip to content
Closed
Changes from 1 commit
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
61 changes: 61 additions & 0 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,69 @@ export default class CodeEditor extends React.Component {
'Cmd-T': function (cm) {
// Do nothing
},
'Ctrl-I': function(cm) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For macOS, we have to implement this to Cmd-I and Cmd-B.
So, we have to extract the handler and make it work depending on OS.
Like the below:

'Cmd-I': function (cm) {
  if (global.process.platform !== 'darwin') { return }
  applyItalic(cm)
},
'Ctrl-I': function (cm) {
  if (global.process.platform === 'darwin') { return }
  applyItalic(cm)
}

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

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

let newString
let boldAndItalic = str.match(/^\*\*\*(.*)\*\*\*$/)
let bold = str.match(/^\*\*(.*)\*\*$/)
let 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]
newString = newString
} else {
newString = `*${str}*`
}

let newSelection = selection.substr(0, index) + newString + selection.substr(index + selection.length)
cm.replaceSelection(newSelection)
}
},
'Ctrl-B': function(cm) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same to here

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

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

let newString
let boldAndItalic = str.match(/^\*\*\*(.*)\*\*\*$/)
let bold = str.match(/^\*\*(.*)\*\*$/)
let 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]
newString = `***${newString}***`
} else {
newString = `**${str}**`
}

let newSelection = selection.substr(0, index) + newString + selection.substr(index + selection.length)
cm.replaceSelection(newSelection)
}
},
Enter: 'boostNewLineAndIndentContinueMarkdownList',
'Ctrl-C': (cm) => {
console.log('here', cm)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this unnecessary logging

if (cm.getOption('keyMap').substr(0, 3) === 'vim') {
document.execCommand('copy')
}
Expand Down