-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Text expansion support #1848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text expansion support #1848
Conversation
|
@ZeroX-DG Wow, it looks nice!! |
browser/components/CodeEditor.js
Outdated
| const { rulers, enableRulers } = this.props | ||
| const emptyChars = /\t|\s|\r|\n/ | ||
| if (!fs.existsSync(consts.SNIPPET_FILE)) { | ||
| const defaultSnippets = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That are quite a lot 'default' snippets not everybody needs. Nevertheless they will be inserted by default... not sure if that's a good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right 😄 I think leaving just 1 default snippet is enough, will fix it soon
browser/lib/consts.js
Outdated
| function getAppData () { | ||
| return process.env.APPDATA || (process.platform === 'darwin' | ||
| ? process.env.HOME + 'Library/Preferences' | ||
| : require('os').homedir() + '/.config') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.sep woulde be way better than a hardcoded '/' since that isn't platformindependent!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First time I heard of path.sep new stuff to learn! thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using path.sep is not the best. Please use path.join() to concatenating path.
| import crypto from 'crypto' | ||
| import consts from 'browser/lib/consts' | ||
|
|
||
| function createSnippet (snippets) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why didn't you write any tests?!
Tests are good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I was busy at that time, I'll add some tests for it 😄
refactored some code fixed snippet content empty on changed from list fixed snippet name not updating on list when changed
…d old snippet still display when deleted
…Boostnote into text-expansion-support
|
@Rokt33r It's basically done, please tell me if you need anything |
Rokt33r
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to generate snippets.json file if it does not exist.
Error: ENOENT: no such file or directory, open '/Users/~/.config/Boostnote/snippets.json'
|
That's weird, I have make sure that the snippets.json will be created if it's not exist everytime Boostnote is executed. Look like the path in your error is wrong, I have adjusted it, maybe it's the cause to this problem |
|
I can't wait until this lands in the main distribution. |
|
@ChasManRors Just a few more changes and it will be ready! |
sosukesuzuki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please confirm my reviews!
browser/components/CodeEditor.js
Outdated
| for (let i = 0; i < snippets.length; i++) { | ||
| if (snippets[i].prefix.indexOf(wordBeforeCursor.text) !== -1) { | ||
| if (snippets[i].content.indexOf(templateCursorString) !== -1) { | ||
| let snippetLines = snippets[i].content.split('\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use const instead of let.
browser/components/CodeEditor.js
Outdated
| let cursorLineNumber = 0 | ||
| let cursorLinePosition = 0 | ||
| for (let j = 0; j < snippetLines.length; j++) { | ||
| let cursorIndex = snippetLines[j].indexOf(templateCursorString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use const instead of let.
browser/lib/consts.js
Outdated
| const fs = require('sander') | ||
| const { remote } = require('electron') | ||
| const { app } = remote | ||
| const os = require('os') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove os, because it is never used.
| }).catch(err => { throw err }) | ||
| } | ||
|
|
||
| renderSnippetList () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it is better than now, to extract renderSnippetList as stateless functional component.
| renderSnippetList () { | ||
| const { snippets } = this.state | ||
| return ( | ||
| <ul id='snippets' style={{height: 'calc(100% - 8px)', overflow: 'scroll', background: '#f5f5f5'}}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is possible, I want you to write style to browser/main/modals/PreferencesModal/SnippetTab.styl.
| <div styleName='SnippetEditor' ref='root' tabIndex='-1' style={{ | ||
| fontFamily: fontFamily.join(', '), | ||
| fontSize: fontSize, | ||
| position: 'absolute', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please write style of position, width, height to other stylus file.
| import React from 'react' | ||
| import CSSModules from 'browser/lib/CSSModules' | ||
| import styles from './SnippetTab.styl' | ||
| import fs from 'fs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove fs, because fs is never used.
| import SnippetEditor from './SnippetEditor' | ||
| import i18n from 'browser/lib/i18n' | ||
| import dataApi from 'browser/main/lib/dataApi' | ||
| import consts from 'browser/lib/consts' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove consts. because consts is never used.
| import CodeMirror from 'codemirror' | ||
| import React from 'react' | ||
| import _ from 'lodash' | ||
| import fs from 'fs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove fs because fs is never used.
| import React from 'react' | ||
| import _ from 'lodash' | ||
| import fs from 'fs' | ||
| import consts from 'browser/lib/consts' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove consts because consts is never used.
browser/components/CodeEditor.js
Outdated
| import crypto from 'crypto' | ||
| import consts from 'browser/lib/consts' | ||
| import fs from 'fs' | ||
| const { ipcRenderer, remote } = require('electron') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remote is never used, please remove it.
|
@sosukesuzuki I have changed my code, please take a look 😃 |
sosukesuzuki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your fix!
Please fix it a bit. Confirm my reviews:pray:
And, please confirm this comment.
| import React from 'react' | ||
| import _ from 'lodash' | ||
| import styles from './SnippetTab.styl' | ||
| import CSSModules from 'react-css-modules' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please usebrowser/lib/CSSModules instead of react-css-modules.
| this.handleSnippetNameOrPrefixChange() | ||
| }} | ||
| value={currentSnippet ? currentSnippet.name : ''} | ||
| onChange={e => { this.onSnippetNameOrPrefixChanged(e, 'name') }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ } is unnecessary. please write like below:
onChange={e => this.onSnippetNameOrPrefixChanged(e, 'name')}| this.handleSnippetNameOrPrefixChange() | ||
| }} | ||
| value={currentSnippet ? currentSnippet.prefix : ''} | ||
| onChange={e => { this.onSnippetNameOrPrefixChanged(e, 'prefix') }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ } is unnecessary. please write like below:
onChange={e => this.onSnippetNameOrPrefixChanged(e, 'prefix') }|
@ZeroX-DG please fix a conflict! |
|
@sosukesuzuki , I have confirmed you requests. |
|
@ZeroX-DG |
|
@sosukesuzuki , Sorry for missing a theme, I've added the monokai theme & switched all colors to the color variables in the index.styl file |

This is a new feature and has been requested here:
#1830, #576
Basically this feature allow you to create snippet (like code snippet) and use it to boost up your typing speed.
Enough with words! here is the demo:

To use this feature, you will first need to type in the prefix of the snippet which is just a word to trigger the snippet content (in the example above it's
ipsum) then press tab to expand the snippetYou can also define your own snippet at the snippet tab in setting
When you edit the snippet name or prefix or content, the snippet will automatically update so don't worry if you forget to hit the save button although there is no save button 😄
You can set more than just one prefix and separate them using commas like this:

You can delete the snippet by right click on the snippet and click delete
You can also create a note template using this feature. By adding the special string
:{}you can set the cursor position in your template once it's generated.The only problem is that I haven't add new details to the language file, will do it if I have time 😃