mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
improved style for snippet list
This commit is contained in:
@@ -148,7 +148,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
cm.execCommand('insertSoftTab')
|
cm.execCommand('insertSoftTab')
|
||||||
}
|
}
|
||||||
cm.execCommand('goLineEnd')
|
cm.execCommand('goLineEnd')
|
||||||
} else if (!emptyChars.test(charBeforeCursor) || cursor.ch !== 0) {
|
} else if (!emptyChars.test(charBeforeCursor) || cursor.ch > 1) {
|
||||||
// text expansion on tab key if the char before is alphabet
|
// text expansion on tab key if the char before is alphabet
|
||||||
if (expandSnippet(line, cursor, cm, expandData) === false) {
|
if (expandSnippet(line, cursor, cm, expandData) === false) {
|
||||||
if (tabs) {
|
if (tabs) {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import CodeMirror from 'codemirror'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
import fs from 'fs'
|
||||||
|
import { findStorage } from 'browser/lib/findStorage'
|
||||||
|
|
||||||
const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace']
|
const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace']
|
||||||
const buildCMRulers = (rulers, enableRulers) =>
|
const buildCMRulers = (rulers, enableRulers) =>
|
||||||
@@ -14,7 +16,7 @@ export default class SnippetEditor extends React.Component {
|
|||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { rulers, enableRulers } = this.props
|
const { rulers, enableRulers } = this.props
|
||||||
let cm = CodeMirror(this.refs.root, {
|
this.cm = CodeMirror(this.refs.root, {
|
||||||
rulers: buildCMRulers(rulers, enableRulers),
|
rulers: buildCMRulers(rulers, enableRulers),
|
||||||
lineNumbers: this.props.displayLineNumbers,
|
lineNumbers: this.props.displayLineNumbers,
|
||||||
lineWrapping: true,
|
lineWrapping: true,
|
||||||
@@ -29,11 +31,34 @@ export default class SnippetEditor extends React.Component {
|
|||||||
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
||||||
autoCloseBrackets: true,
|
autoCloseBrackets: true,
|
||||||
})
|
})
|
||||||
cm.setValue("asdasd")
|
this.cm.setSize("100%", "100%")
|
||||||
cm.setSize("100%", "100%")
|
let snippetId = this.props.snippetId
|
||||||
|
|
||||||
|
const storagePath = findStorage(this.props.storageKey).path
|
||||||
|
const expandDataFile = path.join(storagePath, 'expandData.json')
|
||||||
|
if (!fs.existsSync(expandDataFile)) {
|
||||||
|
const defaultExpandData = [
|
||||||
|
{
|
||||||
|
matches: ['lorem', 'ipsum'],
|
||||||
|
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
||||||
|
},
|
||||||
|
{ match: 'h1', content: '# '},
|
||||||
|
{ match: 'h2', content: '## '},
|
||||||
|
{ match: 'h3', content: '### '},
|
||||||
|
{ match: 'h4', content: '#### '},
|
||||||
|
{ match: 'h5', content: '##### '},
|
||||||
|
{ match: 'h6', content: '###### '}
|
||||||
|
];
|
||||||
|
fs.writeFileSync(expandDataFile, JSON.stringify(defaultExpandData), 'utf8')
|
||||||
|
}
|
||||||
|
const expandData = JSON.parse(fs.readFileSync(expandDataFile, 'utf8'))
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
componentWillReceiveProps(newProps) {
|
||||||
|
this.cm.setValue(newProps.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
const { fontSize } = this.props
|
const { fontSize } = this.props
|
||||||
let fontFamily = this.props.fontFamily
|
let fontFamily = this.props.fontFamily
|
||||||
fontFamily = _.isString(fontFamily) && fontFamily.length > 0
|
fontFamily = _.isString(fontFamily) && fontFamily.length > 0
|
||||||
|
|||||||
@@ -13,16 +13,24 @@ class SnippetTab extends React.Component {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
snippets: [
|
snippets: [
|
||||||
{ id: 'abcsajisdjiasd', name: 'Hello' }
|
{ id: 'abcsajisdjiasd', name: 'Hello', content: 'asdddddddsaddddddd' },
|
||||||
]
|
{ id: 'btbjieejbiebfe', name: 'Hello 2', content: 'asdddddddsaddddddd' }
|
||||||
|
],
|
||||||
|
currentSnippet: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleSnippetClick(id) {
|
||||||
|
this.setState({'currentSnippet': id})
|
||||||
|
}
|
||||||
|
|
||||||
renderSnippetList () {
|
renderSnippetList () {
|
||||||
let { snippets } = this.state
|
let { snippets } = this.state
|
||||||
return (
|
return (
|
||||||
snippets.map((snippet) => (
|
snippets.map((snippet) => (
|
||||||
<div styleName='snippet-item' key={snippet.id}>
|
<div styleName='snippet-item'
|
||||||
|
key={snippet.id}
|
||||||
|
onClick={() => this.handleSnippetClick(snippet.id)}>
|
||||||
{snippet.name}
|
{snippet.name}
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
@@ -42,6 +50,7 @@ class SnippetTab extends React.Component {
|
|||||||
<div styleName='snippet-list'>
|
<div styleName='snippet-list'>
|
||||||
{this.renderSnippetList()}
|
{this.renderSnippetList()}
|
||||||
</div>
|
</div>
|
||||||
|
{this.state.currentSnippet ?
|
||||||
<div styleName='snippet-detail'>
|
<div styleName='snippet-detail'>
|
||||||
<div styleName='group-section'>
|
<div styleName='group-section'>
|
||||||
<div styleName='group-section-label'>{i18n.__('Snippet name')}</div>
|
<div styleName='group-section-label'>{i18n.__('Snippet name')}</div>
|
||||||
@@ -50,7 +59,8 @@ class SnippetTab extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div styleName='snippet-editor-section'>
|
<div styleName='snippet-editor-section'>
|
||||||
<SnippetEditor
|
<SnippetEditor
|
||||||
|
storageKey={this.props.storageKey}
|
||||||
theme={config.editor.theme}
|
theme={config.editor.theme}
|
||||||
keyMap={config.editor.keyMap}
|
keyMap={config.editor.keyMap}
|
||||||
fontFamily={config.editor.fontFamily}
|
fontFamily={config.editor.fontFamily}
|
||||||
@@ -60,9 +70,11 @@ class SnippetTab extends React.Component {
|
|||||||
enableRulers={config.editor.enableRulers}
|
enableRulers={config.editor.enableRulers}
|
||||||
rulers={config.editor.rulers}
|
rulers={config.editor.rulers}
|
||||||
displayLineNumbers={config.editor.displayLineNumbers}
|
displayLineNumbers={config.editor.displayLineNumbers}
|
||||||
scrollPastEnd={config.editor.scrollPastEnd} />
|
scrollPastEnd={config.editor.scrollPastEnd}
|
||||||
|
snippetId={this.state.currentSnippet} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
: ''}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,10 +91,20 @@
|
|||||||
.snippet-item
|
.snippet-item
|
||||||
width 100%
|
width 100%
|
||||||
height 50px
|
height 50px
|
||||||
font-size 20px
|
font-size 15px
|
||||||
line-height 50px
|
line-height 50px
|
||||||
padding 0 10px
|
padding 0 5%
|
||||||
cursor pointer
|
cursor pointer
|
||||||
|
position relative
|
||||||
|
|
||||||
|
&::after
|
||||||
|
width 90%
|
||||||
|
height 1px
|
||||||
|
background rgba(0, 0, 0, 0.1)
|
||||||
|
position absolute
|
||||||
|
top 100%
|
||||||
|
left 5%
|
||||||
|
content ''
|
||||||
|
|
||||||
&:hover
|
&:hover
|
||||||
background darken(#f5f5f5, 5)
|
background darken(#f5f5f5, 5)
|
||||||
|
|||||||
Reference in New Issue
Block a user