diff --git a/browser/finder/NoteDetail.js b/browser/finder/NoteDetail.js
index 9d4ce907..68d3d5ab 100644
--- a/browser/finder/NoteDetail.js
+++ b/browser/finder/NoteDetail.js
@@ -140,20 +140,6 @@ class NoteDetail extends React.Component {
key={index}
style={{zIndex: isActive ? 5 : 4}}
>
-
-
-
-
{snippet.mode === 'markdown'
? {
+ menu.append(new MenuItem(item))
+ })
+ menu.popup(remote.getCurrentWindow())
+}
+
+const context = {
+ popup
+}
+
+module.export = context
+export default context
diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js
index 23582be4..49d08890 100644
--- a/browser/main/Detail/SnippetNoteDetail.js
+++ b/browser/main/Detail/SnippetNoteDetail.js
@@ -10,6 +10,7 @@ import dataApi from 'browser/main/lib/dataApi'
import { hashHistory } from 'react-router'
import ee from 'browser/main/lib/eventEmitter'
import CodeMirror from 'codemirror'
+import SnippetTab from './SnippetTab'
function pass (name) {
switch (name) {
@@ -238,6 +239,10 @@ class SnippetNoteDetail extends React.Component {
}
handleTabPlusButtonClick (e) {
+ this.addSnippet()
+ }
+
+ addSnippet () {
let { note } = this.state
note.snippets = note.snippets.concat([{
@@ -245,9 +250,13 @@ class SnippetNoteDetail extends React.Component {
mode: 'text',
content: ''
}])
+ let snippetIndex = note.snippets.length - 1
this.setState({
- note
+ note,
+ snippetIndex
+ }, () => {
+ this.refs['tab-' + snippetIndex].startRenaming()
})
}
@@ -279,15 +288,19 @@ class SnippetNoteDetail extends React.Component {
let snippets = this.state.note.snippets.slice()
snippets.splice(index, 1)
this.state.note.snippets = snippets
+ let snippetIndex = this.state.snippetIndex >= snippets.length
+ ? snippets.length - 1
+ : this.state.snippetIndex
this.setState({
- note: this.state.note
+ note: this.state.note,
+ snippetIndex
})
}
- handleNameInputChange (e, index) {
+ renameSnippetByIndex (index, name) {
let snippets = this.state.note.snippets.slice()
- snippets[index].name = e.target.value
- let syntax = CodeMirror.findModeByFileName(e.target.value.trim())
+ snippets[index].name = name
+ let syntax = CodeMirror.findModeByFileName(name.trim())
let mode = syntax != null ? syntax.name : null
if (mode != null) snippets[index].mode = mode
this.state.note.snippets = snippets
@@ -339,8 +352,62 @@ class SnippetNoteDetail extends React.Component {
}
}
- handleDeleteKeyDown (e) {
- if (e.keyCode === 27) this.handleDeleteCancelButtonClick(e)
+ handleKeyDown (e) {
+ switch (e.keyCode) {
+ case 9:
+ if (e.ctrlKey && !e.shiftKey) {
+ e.preventDefault()
+ this.jumpNextTab()
+ } else if (e.ctrlKey && e.shiftKey) {
+ e.preventDefault()
+ this.jumpPrevTab()
+ } else if (!e.ctrlKey && !e.shiftKey && e.target === this.refs.description) {
+ e.preventDefault()
+ this.focusEditor()
+ }
+ break
+ case 76:
+ let shouldFocus = global.process.platform === 'darwin'
+ ? e.metaKey
+ : e.ctrlKey
+ if (shouldFocus) {
+ e.preventDefault()
+ this.focus()
+ }
+ break
+ case 84:
+ {
+ let shouldFocus = global.process.platform === 'darwin'
+ ? e.metaKey
+ : e.ctrlKey
+ if (e.shouldFocus) {
+ e.preventDefault()
+ this.addSnippet()
+ }
+ }
+ }
+
+ }
+
+ jumpNextTab () {
+ this.setState({
+ snippetIndex: (this.state.snippetIndex + 1) % this.state.note.snippets.length
+ }, () => {
+ this.focusEditor()
+ })
+ }
+
+ jumpPrevTab () {
+ this.setState({
+ snippetIndex: (this.state.snippetIndex - 1 + this.state.note.snippets.length) % this.state.note.snippets.length
+ }, () => {
+ this.focusEditor()
+ })
+ }
+
+ focusEditor () {
+ console.log('code-' + this.state.snippetIndex)
+ this.refs['code-' + this.state.snippetIndex].focus()
}
render () {
@@ -354,31 +421,19 @@ class SnippetNoteDetail extends React.Component {
let tabList = note.snippets.map((snippet, index) => {
let isActive = this.state.snippetIndex === index
- return
-
- {note.snippets.length > 1 &&
-
- }
-
+ ref={'tab-' + index}
+ snippet={snippet}
+ isActive={isActive}
+ onClick={(e) => this.handleTabButtonClick(e, index)}
+ onDelete={(e) => this.handleTabDeleteButtonClick(e, index)}
+ onRename={(name) => this.renameSnippetByIndex(index, name)}
+ isDeletable={note.snippets.length > 1}
+ />
})
+
let viewList = note.snippets.map((snippet, index) => {
let isActive = this.state.snippetIndex === index
@@ -389,22 +444,6 @@ class SnippetNoteDetail extends React.Component {
key={index}
style={{zIndex: isActive ? 5 : 4}}
>
-
- this.handleNameInputChange(e, index)}
- />
-
-
{snippet.mode === 'markdown'
? this.handleKeyDown(e)}
>
@@ -478,8 +518,8 @@ class SnippetNoteDetail extends React.Component {
-
-
- {tabList}
-
+