diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 57705560..166b25bb 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -148,7 +148,7 @@ export default class CodeEditor extends React.Component { cm.execCommand('insertSoftTab') } 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 if (expandSnippet(line, cursor, cm, expandData) === false) { if (tabs) { diff --git a/browser/main/modals/PreferencesModal/SnippetEditor.js b/browser/main/modals/PreferencesModal/SnippetEditor.js index 92da3ae6..15110f34 100644 --- a/browser/main/modals/PreferencesModal/SnippetEditor.js +++ b/browser/main/modals/PreferencesModal/SnippetEditor.js @@ -2,6 +2,8 @@ import CodeMirror from 'codemirror' import PropTypes from 'prop-types' import React from 'react' 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 buildCMRulers = (rulers, enableRulers) => @@ -14,7 +16,7 @@ export default class SnippetEditor extends React.Component { componentDidMount () { const { rulers, enableRulers } = this.props - let cm = CodeMirror(this.refs.root, { + this.cm = CodeMirror(this.refs.root, { rulers: buildCMRulers(rulers, enableRulers), lineNumbers: this.props.displayLineNumbers, lineWrapping: true, @@ -29,11 +31,34 @@ export default class SnippetEditor extends React.Component { gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'], autoCloseBrackets: true, }) - cm.setValue("asdasd") - cm.setSize("100%", "100%") + this.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 let fontFamily = this.props.fontFamily fontFamily = _.isString(fontFamily) && fontFamily.length > 0 diff --git a/browser/main/modals/PreferencesModal/SnippetTab.js b/browser/main/modals/PreferencesModal/SnippetTab.js index 74787943..7d46cc65 100644 --- a/browser/main/modals/PreferencesModal/SnippetTab.js +++ b/browser/main/modals/PreferencesModal/SnippetTab.js @@ -13,16 +13,24 @@ class SnippetTab extends React.Component { this.state = { 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 () { let { snippets } = this.state return ( snippets.map((snippet) => ( -
+
this.handleSnippetClick(snippet.id)}> {snippet.name}
)) @@ -42,6 +50,7 @@ class SnippetTab extends React.Component {
{this.renderSnippetList()}
+ {this.state.currentSnippet ?
{i18n.__('Snippet name')}
@@ -50,7 +59,8 @@ class SnippetTab extends React.Component {
- + scrollPastEnd={config.editor.scrollPastEnd} + snippetId={this.state.currentSnippet} />
+ : ''} ) } diff --git a/browser/main/modals/PreferencesModal/SnippetTab.styl b/browser/main/modals/PreferencesModal/SnippetTab.styl index 363c4c95..4f32bb3f 100644 --- a/browser/main/modals/PreferencesModal/SnippetTab.styl +++ b/browser/main/modals/PreferencesModal/SnippetTab.styl @@ -91,10 +91,20 @@ .snippet-item width 100% height 50px - font-size 20px + font-size 15px line-height 50px - padding 0 10px + padding 0 5% cursor pointer + position relative + + &::after + width 90% + height 1px + background rgba(0, 0, 0, 0.1) + position absolute + top 100% + left 5% + content '' &:hover background darken(#f5f5f5, 5)