Skip to content

Commit 9f8246a

Browse files
committed
add default language for snippet note
1 parent 039f737 commit 9f8246a

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

browser/main/Detail/SnippetNoteDetail.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,12 @@ class SnippetNoteDetail extends React.Component {
573573
}
574574

575575
addSnippet () {
576+
const { config } = this.props
576577
const { note } = this.state
577578

578579
note.snippets = note.snippets.concat([{
579580
name: '',
580-
mode: 'Plain Text',
581+
mode: config.editor.snippetDefaultLanguage || 'text',
581582
content: ''
582583
}])
583584
const snippetIndex = note.snippets.length - 1

browser/main/NewNoteButton/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ class NewNoteButton extends React.Component {
3434
}
3535

3636
handleNewNoteButtonClick (e) {
37-
const { location, dispatch } = this.props
37+
const { location, dispatch, config } = this.props
3838
const { storage, folder } = this.resolveTargetFolder()
3939

4040
modal.open(NewNoteModal, {
4141
storage: storage.key,
4242
folder: folder.key,
4343
dispatch,
44-
location
44+
location,
45+
config
4546
})
4647
}
4748

browser/main/modals/NewNoteModal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class NewNoteModal extends React.Component {
6161
handleSnippetNoteButtonClick (e) {
6262
AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_SNIPPET')
6363
AwsMobileAnalyticsConfig.recordDynamicCustomEvent('ADD_ALLNOTE')
64-
const { storage, folder, dispatch, location } = this.props
64+
const { storage, folder, dispatch, location, config } = this.props
6565

6666
dataApi
6767
.createNote(storage, {
@@ -72,7 +72,7 @@ class NewNoteModal extends React.Component {
7272
snippets: [
7373
{
7474
name: '',
75-
mode: 'text',
75+
mode: config.editor.snippetDefaultLanguage || 'text',
7676
content: ''
7777
}
7878
]

browser/main/modals/PreferencesModal/ConfigTab.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
line-height 30px
2525

2626
.group-section-label
27-
width 150px
27+
width 200px
2828
text-align left
2929
margin-right 10px
3030
font-size 14px

browser/main/modals/PreferencesModal/UiTab.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class UiTab extends React.Component {
8585
displayLineNumbers: this.refs.editorDisplayLineNumbers.checked,
8686
switchPreview: this.refs.editorSwitchPreview.value,
8787
keyMap: this.refs.editorKeyMap.value,
88+
snippetDefaultLanguage: this.refs.editorSnippetDefaultLanguage.value,
8889
scrollPastEnd: this.refs.scrollPastEnd.checked,
8990
fetchUrlTitle: this.refs.editorFetchUrlTitle.checked
9091
},
@@ -386,6 +387,22 @@ class UiTab extends React.Component {
386387
<p styleName='note-for-keymap'>{i18n.__('⚠️ Please restart boostnote after you change the keymap')}</p>
387388
</div>
388389
</div>
390+
391+
<div styleName='group-section'>
392+
<div styleName='group-section-label'>
393+
{i18n.__('Snippet Default Language')}
394+
</div>
395+
<div styleName='group-section-control'>
396+
<select value={config.editor.snippetDefaultLanguage}
397+
ref='editorSnippetDefaultLanguage'
398+
onChange={(e) => this.handleUIChange(e)}
399+
>
400+
{
401+
_.sortBy(CodeMirror.modeInfo.map(mode => mode.name)).map(name => (<option value={name}>{name}</option>))
402+
}
403+
</select>
404+
</div>
405+
</div>
389406

390407
<div styleName='group-checkBoxSection'>
391408
<label>

0 commit comments

Comments
 (0)