mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
implemented drag/drop for tabs
This commit is contained in:
@@ -85,6 +85,19 @@ class SnippetTab extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
handleDragStart (e) {
|
||||
e.dataTransfer.dropEffect = 'move'
|
||||
this.props.onDragStart(e)
|
||||
}
|
||||
|
||||
handleDragEnd (e) {
|
||||
this.props.onDragEnd(e)
|
||||
}
|
||||
|
||||
handleDrop (e) {
|
||||
this.props.onDrop(e)
|
||||
}
|
||||
|
||||
render () {
|
||||
const { isActive, snippet, isDeletable } = this.props
|
||||
return (
|
||||
@@ -98,6 +111,10 @@ class SnippetTab extends React.Component {
|
||||
onClick={(e) => this.handleClick(e)}
|
||||
onDoubleClick={(e) => this.handleRenameClick(e)}
|
||||
onContextMenu={(e) => this.handleContextMenu(e)}
|
||||
onDragStart={(e) => this.handleDragStart(e)}
|
||||
onDragEnd={(e) => this.handleDragEnd(e)}
|
||||
onDrop={(e) => this.handleDrop(e)}
|
||||
draggable='true'
|
||||
>
|
||||
{snippet.name.trim().length > 0
|
||||
? snippet.name
|
||||
@@ -127,6 +144,7 @@ class SnippetTab extends React.Component {
|
||||
}
|
||||
|
||||
SnippetTab.propTypes = {
|
||||
|
||||
}
|
||||
|
||||
export default CSSModules(SnippetTab, styles)
|
||||
|
||||
@@ -236,6 +236,26 @@ class SnippetNoteDetail extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
handleTabDragStart (e, index) {
|
||||
e.dataTransfer.setData('text/plain', index)
|
||||
}
|
||||
|
||||
handleTabDrop (e, index) {
|
||||
const oldIndex = parseInt(e.dataTransfer.getData('text'))
|
||||
|
||||
const snippets = this.state.note.snippets.slice()
|
||||
const draggedSnippet = snippets[oldIndex]
|
||||
snippets[oldIndex] = snippets[index]
|
||||
snippets[index] = draggedSnippet
|
||||
const snippetIndex = index
|
||||
|
||||
const note = Object.assign({}, this.state.note, {snippets})
|
||||
this.setState({ note, snippetIndex }, () => {
|
||||
this.save()
|
||||
this.refs['code-' + this.state.snippetIndex].reload()
|
||||
})
|
||||
}
|
||||
|
||||
handleTabDeleteButtonClick (e, index) {
|
||||
if (this.state.note.snippets.length > 1) {
|
||||
if (this.state.note.snippets[index].content.trim().length > 0) {
|
||||
@@ -511,6 +531,8 @@ class SnippetNoteDetail extends React.Component {
|
||||
onDelete={(e) => this.handleTabDeleteButtonClick(e, index)}
|
||||
onRename={(name) => this.renameSnippetByIndex(index, name)}
|
||||
isDeletable={note.snippets.length > 1}
|
||||
onDragStart={(e) => this.handleTabDragStart(e, index)}
|
||||
onDrop={(e) => this.handleTabDrop(e, index)}
|
||||
/>
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user