mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 10:46:32 +00:00
implement click to edit
This commit is contained in:
@@ -20,7 +20,6 @@ import DeleteArticleModal from '../../modal/DeleteArticleModal'
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const clipboard = electron.clipboard
|
const clipboard = electron.clipboard
|
||||||
const ipc = electron.ipcRenderer
|
const ipc = electron.ipcRenderer
|
||||||
const remote = electron.remote
|
|
||||||
|
|
||||||
const OSX = global.process.platform === 'darwin'
|
const OSX = global.process.platform === 'darwin'
|
||||||
const BRAND_COLOR = '#18AF90'
|
const BRAND_COLOR = '#18AF90'
|
||||||
@@ -109,7 +108,7 @@ export default class ArticleDetail extends React.Component {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
article: Object.assign({content: ''}, props.activeArticle),
|
article: Object.assign({content: ''}, props.activeArticle),
|
||||||
previewMode: false,
|
previewMode: true,
|
||||||
openShareDropdown: false
|
openShareDropdown: false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +151,6 @@ export default class ArticleDetail extends React.Component {
|
|||||||
editArticle () {
|
editArticle () {
|
||||||
ReactDOM.findDOMNode(this.refs.title).focus()
|
ReactDOM.findDOMNode(this.refs.title).focus()
|
||||||
ReactDOM.findDOMNode(this.refs.title).select()
|
ReactDOM.findDOMNode(this.refs.title).select()
|
||||||
this.setState({previewMode: false})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheArticle () {
|
cacheArticle () {
|
||||||
@@ -223,12 +221,6 @@ export default class ArticleDetail extends React.Component {
|
|||||||
}, () => this.cacheArticle())
|
}, () => this.cacheArticle())
|
||||||
}
|
}
|
||||||
|
|
||||||
handleModeSelectBlur () {
|
|
||||||
if (this.refs.code != null) {
|
|
||||||
this.refs.code.editor.focus()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleContentChange (e, value) {
|
handleContentChange (e, value) {
|
||||||
let { article } = this.state
|
let { article } = this.state
|
||||||
article.content = value
|
article.content = value
|
||||||
@@ -238,37 +230,11 @@ export default class ArticleDetail extends React.Component {
|
|||||||
}, () => this.cacheArticle())
|
}, () => this.cacheArticle())
|
||||||
}
|
}
|
||||||
|
|
||||||
handleTogglePreviewButtonClick (e) {
|
handleCodeEditorBlur (e) {
|
||||||
if (this.state.article.mode === 'markdown') {
|
if (this.state.article.mode === 'markdown' && !this.state.previewMode) {
|
||||||
if (!this.state.previewMode) {
|
this.setState({
|
||||||
let cursorPosition = this.refs.code.getCursorPosition()
|
previewMode: true
|
||||||
let firstVisibleRow = this.refs.code.getFirstVisibleRow()
|
})
|
||||||
this.setState({
|
|
||||||
previewMode: true,
|
|
||||||
cursorPosition,
|
|
||||||
firstVisibleRow
|
|
||||||
}, function () {
|
|
||||||
let previewEl = ReactDOM.findDOMNode(this.refs.preview)
|
|
||||||
let anchors = previewEl.querySelectorAll('.lineAnchor')
|
|
||||||
for (let i = 0; i < anchors.length; i++) {
|
|
||||||
if (parseInt(anchors[i].dataset.key, 10) > cursorPosition.row || i === anchors.length - 1) {
|
|
||||||
var targetAnchor = anchors[i > 0 ? i - 1 : 0]
|
|
||||||
previewEl.scrollTop = targetAnchor.offsetTop - 100
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
remote.getCurrentWebContents().send('list-focus')
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
previewMode: false
|
|
||||||
}, function () {
|
|
||||||
if (this.state.cursorPosition == null) return true
|
|
||||||
this.refs.code.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column)
|
|
||||||
this.refs.code.scrollToLine(this.state.firstVisibleRow)
|
|
||||||
this.refs.code.editor.focus()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,9 +251,24 @@ export default class ArticleDetail extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePreviewButtonDoubleClick (e) {
|
handleModeSelectKeyDown (e) {
|
||||||
|
if (e.keyCode === 9 && !e.shiftKey) {
|
||||||
|
e.preventDefault()
|
||||||
|
this.setState({previewMode: false}, function () {
|
||||||
|
this.refs.code.editor.focus()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (e.keyCode === 9 && e.shiftKey) {
|
||||||
|
e.preventDefault()
|
||||||
|
ReactDOM.findDOMNode(this.refs.title).focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePreviewDoubleClick (e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
previewMode: false
|
previewMode: false
|
||||||
|
}, function () {
|
||||||
|
this.refs.code.editor.focus()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,23 +354,33 @@ export default class ArticleDetail extends React.Component {
|
|||||||
<ModeSelect
|
<ModeSelect
|
||||||
ref='mode'
|
ref='mode'
|
||||||
onChange={e => this.handleModeChange(e)}
|
onChange={e => this.handleModeChange(e)}
|
||||||
|
onKeyDown={e => this.handleModeSelectKeyDown(e)}
|
||||||
value={this.state.article.mode}
|
value={this.state.article.mode}
|
||||||
className='ArticleDetail-panel-header-mode'
|
className='ArticleDetail-panel-header-mode'
|
||||||
onBlur={() => this.handleModeSelectBlur()}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{status.isTutorialOpen ? modeSelectTutorialElement : null}
|
{status.isTutorialOpen ? modeSelectTutorialElement : null}
|
||||||
|
<div className='ArticleDetail-panel-content'>
|
||||||
{this.state.previewMode
|
{this.state.article.mode === 'markdown' && this.state.previewMode
|
||||||
? <MarkdownPreview ref='preview' onDoubleClick={e => this.handlePreviewButtonDoubleClick(e)} content={this.state.article.content}/>
|
? (<MarkdownPreview
|
||||||
: (<CodeEditor
|
ref='preview'
|
||||||
ref='code'
|
onDoubleClick={e => this.handlePreviewDoubleClick(e)}
|
||||||
onChange={(e, value) => this.handleContentChange(e, value)}
|
content={this.state.article.content}
|
||||||
readOnly={false}
|
/>)
|
||||||
mode={this.state.article.mode}
|
: (<CodeEditor
|
||||||
code={this.state.article.content}
|
ref='code'
|
||||||
/>)
|
onChange={(e, value) => this.handleContentChange(e, value)}
|
||||||
}
|
onBlur={e => this.handleCodeEditorBlur(e)}
|
||||||
|
readOnly={false}
|
||||||
|
mode={this.state.article.mode}
|
||||||
|
code={this.state.article.content}
|
||||||
|
/>)}
|
||||||
|
{
|
||||||
|
this.state.article.mode === 'markdown' && this.state.previewMode
|
||||||
|
? <div className='ArticleDetail-panel-content-tooltip'>Double click to edit post</div>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -258,23 +258,35 @@ infoButton()
|
|||||||
width 100%
|
width 100%
|
||||||
font-size 24px
|
font-size 24px
|
||||||
outline none
|
outline none
|
||||||
.MarkdownPreview
|
.ArticleDetail-panel-content
|
||||||
absolute left right bottom
|
absolute left right bottom
|
||||||
top 60px
|
top 60px
|
||||||
marked()
|
.ArticleDetail-panel-content-tooltip
|
||||||
box-sizing border-box
|
absolute bottom right
|
||||||
padding 5px 15px
|
height 24px
|
||||||
border-top solid 1px borderColor
|
background-color alpha(black, 0.5)
|
||||||
overflow-y auto
|
line-height 24px
|
||||||
user-select all
|
color white
|
||||||
&.empty
|
padding 0 15px
|
||||||
color lighten(inactiveTextColor, 10%)
|
opacity 0
|
||||||
user-select none
|
transition 0.1s
|
||||||
font-size 14px
|
&:hover .ArticleDetail-panel-content-tooltip
|
||||||
.CodeEditor
|
opacity 1
|
||||||
absolute left right bottom
|
.MarkdownPreview
|
||||||
top 60px
|
absolute top left right bottom
|
||||||
border-top solid 1px borderColor
|
marked()
|
||||||
min-height 300px
|
box-sizing border-box
|
||||||
border-bottom-left-radius 5px
|
padding 5px 15px
|
||||||
border-bottom-right-radius 5px
|
border-top solid 1px borderColor
|
||||||
|
overflow-y auto
|
||||||
|
user-select all
|
||||||
|
&.empty
|
||||||
|
color lighten(inactiveTextColor, 10%)
|
||||||
|
user-select none
|
||||||
|
font-size 14px
|
||||||
|
.CodeEditor
|
||||||
|
absolute top left right bottom
|
||||||
|
border-top solid 1px borderColor
|
||||||
|
min-height 300px
|
||||||
|
border-bottom-left-radius 5px
|
||||||
|
border-bottom-right-radius 5px
|
||||||
|
|||||||
Reference in New Issue
Block a user