Skip to content

Commit 007d3e5

Browse files
authored
Merge branch 'master' into Issue_1900
2 parents e9218d1 + 266323b commit 007d3e5

29 files changed

+213
-81
lines changed

browser/components/CodeEditor.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import _ from 'lodash'
44
import CodeMirror from 'codemirror'
55
import 'codemirror-mode-elixir'
66
import attachmentManagement from 'browser/main/lib/dataApi/attachmentManagement'
7+
import convertModeName from 'browser/lib/convertModeName'
78
import eventEmitter from 'browser/main/lib/eventEmitter'
89
import iconv from 'iconv-lite'
910

@@ -15,21 +16,6 @@ const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', '
1516
const buildCMRulers = (rulers, enableRulers) =>
1617
enableRulers ? rulers.map(ruler => ({ column: ruler })) : []
1718

18-
function pass (name) {
19-
switch (name) {
20-
case 'ejs':
21-
return 'Embedded Javascript'
22-
case 'html_ruby':
23-
return 'Embedded Ruby'
24-
case 'objectivec':
25-
return 'Objective C'
26-
case 'text':
27-
return 'Plain Text'
28-
default:
29-
return name
30-
}
31-
}
32-
3319
export default class CodeEditor extends React.Component {
3420
constructor (props) {
3521
super(props)
@@ -50,6 +36,9 @@ export default class CodeEditor extends React.Component {
5036
el = el.parentNode
5137
}
5238
this.props.onBlur != null && this.props.onBlur(e)
39+
40+
const {storageKey, noteKey} = this.props
41+
attachmentManagement.deleteAttachmentsNotPresentInNote(this.editor.getValue(), storageKey, noteKey)
5342
}
5443
this.pasteHandler = (editor, e) => this.handlePaste(editor, e)
5544
this.loadStyleHandler = (e) => {
@@ -229,7 +218,7 @@ export default class CodeEditor extends React.Component {
229218
}
230219

231220
setMode (mode) {
232-
let syntax = CodeMirror.findModeByName(pass(mode))
221+
let syntax = CodeMirror.findModeByName(convertModeName(mode))
233222
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
234223

235224
this.editor.setOption('mode', syntax.mime)

browser/components/MarkdownPreview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import flowchart from 'flowchart'
1010
import SequenceDiagram from 'js-sequence-diagrams'
1111
import eventEmitter from 'browser/main/lib/eventEmitter'
1212
import htmlTextHelper from 'browser/lib/htmlTextHelper'
13+
import convertModeName from 'browser/lib/convertModeName'
1314
import copy from 'copy-to-clipboard'
1415
import mdurl from 'mdurl'
1516
import exportNote from 'browser/main/lib/dataApi/exportNote'
@@ -122,7 +123,6 @@ if (!OSX) {
122123
defaultFontFamily.unshift('meiryo')
123124
}
124125
const defaultCodeBlockFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace']
125-
126126
export default class MarkdownPreview extends React.Component {
127127
constructor (props) {
128128
super(props)
@@ -430,7 +430,7 @@ export default class MarkdownPreview extends React.Component {
430430
: 'default'
431431

432432
_.forEach(this.refs.root.contentWindow.document.querySelectorAll('.code code'), (el) => {
433-
let syntax = CodeMirror.findModeByName(el.className)
433+
let syntax = CodeMirror.findModeByName(convertModeName(el.className))
434434
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
435435
CodeMirror.requireMode(syntax.mode, () => {
436436
const content = htmlTextHelper.decodeEntities(el.innerHTML)

browser/components/NoteItemSimple.styl

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ body[data-theme="dark"]
104104
background-color alpha($ui-dark-button--active-backgroundColor, 20%)
105105
color $ui-dark-text-color
106106
.item-simple-title
107+
.item-simple-title-empty
107108
.item-simple-title-icon
108109
.item-simple-bottom-time
109110
transition 0.15s
@@ -117,6 +118,7 @@ body[data-theme="dark"]
117118
background-color $ui-dark-button--active-backgroundColor
118119
color $ui-dark-text-color
119120
.item-simple-title
121+
.item-simple-title-empty
120122
.item-simple-title-icon
121123
.item-simple-bottom-time
122124
transition 0.15s
@@ -165,9 +167,10 @@ body[data-theme="solarized-dark"]
165167
background-color $ui-solarized-dark-noteList-backgroundColor
166168
&:hover
167169
transition 0.15s
168-
// background-color alpha($ui-dark-button--active-backgroundColor, 20%)
170+
background-color alpha($ui-dark-button--active-backgroundColor, 60%)
169171
color $ui-solarized-dark-text-color
170172
.item-simple-title
173+
.item-simple-title-empty
171174
.item-simple-title-icon
172175
.item-simple-bottom-time
173176
transition 0.15s
@@ -178,9 +181,10 @@ body[data-theme="solarized-dark"]
178181
color $ui-solarized-dark-text-color
179182
&:active
180183
transition 0.15s
181-
background-color $ui-solarized-dark-button--active-backgroundColor
182-
color $ui-solarized-dark-text-color
184+
// background-color $ui-solarized-dark-button--active-backgroundColor
185+
color $ui-dark-text-color
183186
.item-simple-title
187+
.item-simple-title-empty
184188
.item-simple-title-icon
185189
.item-simple-bottom-time
186190
transition 0.15s
@@ -192,11 +196,13 @@ body[data-theme="solarized-dark"]
192196

193197
.item-simple--active
194198
border-color $ui-solarized-dark-borderColor
195-
background-color $ui-solarized-dark-button--active-backgroundColor
199+
background-color $ui-solarized-dark-tag-backgroundColor
196200
.item-simple-wrapper
197201
border-color transparent
198202
.item-simple-title
203+
.item-simple-title-empty
199204
.item-simple-title-icon
205+
color $ui-dark-text-color
200206
.item-simple-bottom-time
201207
color $ui-solarized-dark-text-color
202208
.item-simple-bottom-tagList-item
@@ -207,11 +213,14 @@ body[data-theme="solarized-dark"]
207213
color #c0392b
208214
.item-simple-bottom-tagList-item
209215
background-color alpha(#fff, 20%)
210-
.item-simple-right
211-
float right
212-
.item-simple-right-storageName
213-
padding-left 4px
214-
opacity 0.4
216+
.item-simple-title
217+
color $ui-dark-text-color
218+
border-bottom $ui-dark-borderColor
219+
.item-simple-right
220+
float right
221+
.item-simple-right-storageName
222+
padding-left 4px
223+
opacity 0.4
215224

216225
body[data-theme="monokai"]
217226
.root
@@ -223,13 +232,14 @@ body[data-theme="monokai"]
223232
background-color $ui-monokai-noteList-backgroundColor
224233
&:hover
225234
transition 0.15s
226-
// background-color alpha($ui-dark-button--active-backgroundColor, 20%)
235+
background-color alpha($ui-monokai-button-backgroundColor, 60%)
227236
color $ui-monokai-text-color
228237
.item-simple-title
238+
.item-simple-title-empty
229239
.item-simple-title-icon
230240
.item-simple-bottom-time
231241
transition 0.15s
232-
color $ui-monokai-text-color
242+
color $ui-solarized-dark-text-color
233243
.item-simple-bottom-tagList-item
234244
transition 0.15s
235245
background-color alpha(#fff, 20%)
@@ -239,6 +249,7 @@ body[data-theme="monokai"]
239249
background-color $ui-monokai-button--active-backgroundColor
240250
color $ui-monokai-text-color
241251
.item-simple-title
252+
.item-simple-title-empty
242253
.item-simple-title-icon
243254
.item-simple-bottom-time
244255
transition 0.15s
@@ -254,6 +265,7 @@ body[data-theme="monokai"]
254265
.item-simple-wrapper
255266
border-color transparent
256267
.item-simple-title
268+
.item-simple-title-empty
257269
.item-simple-title-icon
258270
.item-simple-bottom-time
259271
color $ui-monokai-text-color
@@ -265,8 +277,11 @@ body[data-theme="monokai"]
265277
color #c0392b
266278
.item-simple-bottom-tagList-item
267279
background-color alpha(#fff, 20%)
268-
.item-simple-right
269-
float right
270-
.item-simple-right-storageName
271-
padding-left 4px
272-
opacity 0.4
280+
.item-simple-title
281+
color $ui-dark-text-color
282+
border-bottom $ui-dark-borderColor
283+
.item-simple-right
284+
float right
285+
.item-simple-right-storageName
286+
padding-left 4px
287+
opacity 0.4

browser/components/SnippetTab.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class SnippetTab extends React.Component {
5555
this.handleRename()
5656
break
5757
case 27:
58-
this.setState({
59-
name: this.props.snippet.name,
58+
this.setState((prevState, props) => ({
59+
name: props.snippet.name,
6060
isRenaming: false
61-
})
61+
}))
6262
break
6363
}
6464
}

browser/lib/convertModeName.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function convertModeName (name) {
2+
switch (name) {
3+
case 'ejs':
4+
return 'Embedded Javascript'
5+
case 'html_ruby':
6+
return 'Embedded Ruby'
7+
case 'objectivec':
8+
return 'Objective C'
9+
case 'text':
10+
return 'Plain Text'
11+
default:
12+
return name
13+
}
14+
}

browser/lib/markdown.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ class Markdown {
145145
const deflate = require('markdown-it-plantuml/lib/deflate')
146146
this.md.use(require('markdown-it-plantuml'), '', {
147147
generateSource: function (umlCode) {
148+
const stripTrailingSlash = (url) => url.endsWith('/') ? url.slice(0, -1) : url
149+
const serverAddress = stripTrailingSlash(config.preview.plantUMLServerAddress) + '/svg'
148150
const s = unescape(encodeURIComponent(umlCode))
149151
const zippedCode = deflate.encode64(
150152
deflate.zip_deflate(`@startuml\n${s}\n@enduml`, 9)
151153
)
152-
return `http://www.plantuml.com/plantuml/svg/${zippedCode}`
154+
return `${serverAddress}/${zippedCode}`
153155
}
154156
})
155157

browser/main/Detail/MarkdownNoteDetail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MarkdownNoteDetail extends React.Component {
5858
}
5959

6060
componentWillReceiveProps (nextProps) {
61-
if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) {
61+
if (nextProps.note.key !== this.props.note.key && !this.state.isMovingNote) {
6262
if (this.saveQueue != null) this.saveNow()
6363
this.setState({
6464
note: Object.assign({}, nextProps.note)

browser/main/Detail/SnippetNoteDetail.js

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import context from 'browser/lib/context'
1818
import ConfigManager from 'browser/main/lib/ConfigManager'
1919
import _ from 'lodash'
2020
import {findNoteTitle} from 'browser/lib/findNoteTitle'
21+
import convertModeName from 'browser/lib/convertModeName'
2122
import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig'
2223
import TrashButton from './TrashButton'
2324
import RestoreButton from './RestoreButton'
@@ -29,21 +30,6 @@ import { formatDate } from 'browser/lib/date-formatter'
2930
import i18n from 'browser/lib/i18n'
3031
import { confirmDeleteNote } from 'browser/lib/confirmDeleteNote'
3132

32-
function pass (name) {
33-
switch (name) {
34-
case 'ejs':
35-
return 'Embedded Javascript'
36-
case 'html_ruby':
37-
return 'Embedded Ruby'
38-
case 'objectivec':
39-
return 'Objective C'
40-
case 'text':
41-
return 'Plain Text'
42-
default:
43-
return name
44-
}
45-
}
46-
4733
const electron = require('electron')
4834
const { remote } = electron
4935
const { Menu, MenuItem, dialog } = remote
@@ -82,7 +68,7 @@ class SnippetNoteDetail extends React.Component {
8268
}
8369

8470
componentWillReceiveProps (nextProps) {
85-
if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) {
71+
if (nextProps.note.key !== this.props.note.key && !this.state.isMovingNote) {
8672
if (this.saveQueue != null) this.saveNow()
8773
const nextNote = Object.assign({
8874
description: ''
@@ -382,11 +368,11 @@ class SnippetNoteDetail extends React.Component {
382368
name: mode
383369
})
384370
}
385-
this.setState({note: Object.assign(this.state.note, {snippets: snippets})})
371+
this.setState(state => ({note: Object.assign(state.note, {snippets: snippets})}))
386372

387-
this.setState({
388-
note: this.state.note
389-
}, () => {
373+
this.setState(state => ({
374+
note: state.note
375+
}), () => {
390376
this.save()
391377
})
392378
}
@@ -395,11 +381,11 @@ class SnippetNoteDetail extends React.Component {
395381
return (e) => {
396382
const snippets = this.state.note.snippets.slice()
397383
snippets[index].mode = name
398-
this.setState({note: Object.assign(this.state.note, {snippets: snippets})})
384+
this.setState(state => ({note: Object.assign(state.note, {snippets: snippets})}))
399385

400-
this.setState({
401-
note: this.state.note
402-
}, () => {
386+
this.setState(state => ({
387+
note: state.note
388+
}), () => {
403389
this.save()
404390
})
405391

@@ -413,10 +399,10 @@ class SnippetNoteDetail extends React.Component {
413399
return (e) => {
414400
const snippets = this.state.note.snippets.slice()
415401
snippets[index].content = this.refs['code-' + index].value
416-
this.setState({note: Object.assign(this.state.note, {snippets: snippets})})
417-
this.setState({
418-
note: this.state.note
419-
}, () => {
402+
this.setState(state => ({note: Object.assign(state.note, {snippets: snippets})}))
403+
this.setState(state => ({
404+
note: state.note
405+
}), () => {
420406
this.save()
421407
})
422408
}
@@ -611,17 +597,17 @@ class SnippetNoteDetail extends React.Component {
611597
}
612598

613599
jumpNextTab () {
614-
this.setState({
615-
snippetIndex: (this.state.snippetIndex + 1) % this.state.note.snippets.length
616-
}, () => {
600+
this.setState(state => ({
601+
snippetIndex: (state.snippetIndex + 1) % state.note.snippets.length
602+
}), () => {
617603
this.focusEditor()
618604
})
619605
}
620606

621607
jumpPrevTab () {
622-
this.setState({
623-
snippetIndex: (this.state.snippetIndex - 1 + this.state.note.snippets.length) % this.state.note.snippets.length
624-
}, () => {
608+
this.setState(state => ({
609+
snippetIndex: (state.snippetIndex - 1 + state.note.snippets.length) % state.note.snippets.length
610+
}), () => {
625611
this.focusEditor()
626612
})
627613
}
@@ -677,7 +663,7 @@ class SnippetNoteDetail extends React.Component {
677663
const viewList = note.snippets.map((snippet, index) => {
678664
const isActive = this.state.snippetIndex === index
679665

680-
let syntax = CodeMirror.findModeByName(pass(snippet.mode))
666+
let syntax = CodeMirror.findModeByName(convertModeName(snippet.mode))
681667
if (syntax == null) syntax = CodeMirror.findModeByName('Plain Text')
682668

683669
return <div styleName='tabView'

browser/main/lib/ConfigManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const DEFAULT_CONFIG = {
5353
latexInlineClose: '$',
5454
latexBlockOpen: '$$',
5555
latexBlockClose: '$$',
56+
plantUMLServerAddress: 'http://www.plantuml.com/plantuml',
5657
scrollPastEnd: false,
5758
smartQuotes: true,
5859
sanitize: 'STRICT' // 'STRICT', 'ALLOW_STYLES', 'NONE'

0 commit comments

Comments
 (0)