Skip to content

Commit f3732c7

Browse files
committed
Merge branch 'dev'
* dev: temporary setup 0.4.5 emit empty event(to create new record of today if not exists) MAIN_DETAIL_COPY, *_BY_SYNTAX, CLIENT_VERSION 追加 debug ModeSelect component fix markdown style a little more Markdown styleを少し改善 bump up version to 0.4.5 and change codesign path 自動的にスクロールを合わせてくれる fix release path add electron-builder & modify deploy scripts bump up Ace editor Github release Conflicts: package.json
2 parents 7fcaaa2 + a4c72a9 commit f3732c7

10 files changed

Lines changed: 143 additions & 47 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.env
22
node_modules/*
33
!node_modules/boost
4-
Boost-darwin-x64/
5-
backup/
4+
dist/
65
compiled

browser/main/HomePage/ArticleDetail.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export default class ArticleDetail extends React.Component {
162162
}
163163

164164
handleClipboardButtonClick (e) {
165+
activityRecord.emit('MAIN_DETAIL_COPY')
165166
clipboard.writeText(this.props.activeArticle.content)
166167
notify('Saved to Clipboard!', {
167168
body: 'Paste it wherever you want!'
@@ -293,9 +294,9 @@ export default class ArticleDetail extends React.Component {
293294
if (newArticle.title.length === 0) {
294295
newArticle.title = `Created at ${moment(newArticle.createdAt).format('YYYY/MM/DD HH:mm')}`
295296
}
296-
activityRecord.emit('ARTICLE_CREATE')
297+
activityRecord.emit('ARTICLE_CREATE', {mode: newArticle.mode})
297298
} else {
298-
activityRecord.emit('ARTICLE_UPDATE')
299+
activityRecord.emit('ARTICLE_UPDATE', {mode: newArticle.mode})
299300
}
300301

301302
dispatch(updateArticle(newArticle))
@@ -435,7 +436,34 @@ export default class ArticleDetail extends React.Component {
435436

436437
handleTogglePreviewButtonClick (e) {
437438
if (this.state.article.mode === 'markdown') {
438-
this.setState({previewMode: !this.state.previewMode})
439+
if (!this.state.previewMode) {
440+
let cursorPosition = this.refs.code.getCursorPosition()
441+
let firstVisibleRow = this.refs.code.getFirstVisibleRow()
442+
this.setState({
443+
previewMode: true,
444+
cursorPosition,
445+
firstVisibleRow
446+
}, function () {
447+
let previewEl = ReactDOM.findDOMNode(this.refs.preview)
448+
let anchors = previewEl.querySelectorAll('.lineAnchor')
449+
for (let i = 0; i < anchors.length; i++) {
450+
if (parseInt(anchors[i].dataset.key, 10) > cursorPosition.row || i === anchors.length - 1) {
451+
var targetAnchor = anchors[i > 0 ? i - 1 : 0]
452+
previewEl.scrollTop = targetAnchor.offsetTop - 100
453+
break
454+
}
455+
}
456+
})
457+
} else {
458+
this.setState({
459+
previewMode: false
460+
}, function () {
461+
console.log(this.state.cursorPosition)
462+
this.refs.code.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column)
463+
this.refs.code.scrollToLine(this.state.firstVisibleRow)
464+
this.refs.code.editor.focus()
465+
})
466+
}
439467
}
440468
}
441469

@@ -524,7 +552,7 @@ export default class ArticleDetail extends React.Component {
524552
</div>
525553

526554
{this.state.previewMode
527-
? <MarkdownPreview content={this.state.article.content}/>
555+
? <MarkdownPreview ref='preview' content={this.state.article.content}/>
528556
: (<CodeEditor
529557
ref='code'
530558
onChange={(e, value) => this.handleContentChange(e, value)}

browser/styles/mixins/marked.styl

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
marked()
2-
h1, h2, h3, h4, h5, h6, p
3-
&:first-child
4-
margin-top 0
52
hr
63
border-top none
74
border-bottom solid 1px borderColor
85
margin 15px 0
6+
h1, h2, h3, h4, h5, h6
7+
margin 0 0 15px
8+
font-weight 600
9+
* + h1, * + h2, * + h3, * + h4, * + h5, * + h6
10+
margin-top 25px
911
h1
1012
font-size 2em
1113
border-bottom solid 2px borderColor
12-
margin 0.33em auto 0.67em
14+
line-height 2.333em
1315
h2
14-
font-size 1.5em
15-
margin 0.42em auto 0.83em
16+
font-size 1.66em
17+
line-height 2.07em
1618
h3
17-
font-size 1.17em
18-
margin 0.5em auto 1em
19+
font-size 1.33em
20+
line-height 1.6625em
1921
h4
20-
font-size 1em
21-
margin 0.67em auto 1.33em
22+
font-size 1.15em
23+
line-height 1.4375em
2224
h5
23-
font-size 0.83em
24-
margin 0.84em auto 1.67em
25+
font-size 1em
26+
line-height 1.25em
2527
h6
26-
font-size 0.67em
27-
margin 1.16em auto 2.33em
28-
h1, h2, h3, h4, h5, h6
29-
font-weight 700
30-
line-height 1.8em
28+
font-size 0.8em
29+
line-height 1em
30+
31+
* + p, * + blockquote, * + ul, * + ol, * + pre
32+
margin-top 15px
3133
p
32-
line-height 1.8em
33-
margin 15px 0 25px
34+
line-height 1.9em
35+
margin 0 0 15px
3436
img
3537
max-width 100%
3638
strong
@@ -41,26 +43,30 @@ marked()
4143
text-decoration line-through
4244
blockquote
4345
border-left solid 4px brandBorderColor
44-
margin 15px 0 25px
46+
margin 0 0 15px
4547
padding 0 25px
4648
ul
4749
list-style-type disc
4850
padding-left 35px
49-
margin-bottom 35px
51+
margin-bottom 15px
5052
li
5153
display list-item
5254
line-height 1.8em
55+
&>li>ul, &>li>ol
56+
margin 0
5357
&>li>ul
5458
list-style-type circle
5559
&>li>ul
5660
list-style-type square
5761
ol
5862
list-style-type decimal
5963
padding-left 35px
60-
margin-bottom 35px
64+
margin-bottom 15px
6165
li
6266
display list-item
6367
line-height 1.8em
68+
&>li>ul, &>li>ol
69+
margin 0
6470
code
6571
font-family Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace;
6672
padding 2px 4px
@@ -70,15 +76,19 @@ marked()
7076
color black
7177
text-decoration none
7278
background-color #F6F6F6
79+
margin-right 2px
80+
* + code
81+
margin-left 2px
7382
pre
7483
padding 5px
7584
border solid 1px borderColor
7685
border-radius 5px
7786
overflow-x auto
78-
margin 15px 0 25px
87+
margin 0 0 15px
7988
background-color #F6F6F6
8089
line-height 1.35em
8190
&>code
91+
margin 0
8292
padding 0
8393
border none
8494
border-radius 0

builder-config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"osx" : {
3+
"title": "Boost Installer",
4+
// "background": "resources/background.png",
5+
"icon": "resources/app.icns",
6+
"icon-size": 80,
7+
"contents": [
8+
{ "x": 438, "y": 344, "type": "link", "path": "/Applications" },
9+
{ "x": 192, "y": 344, "type": "file" }
10+
]
11+
}
12+
}

lib/activityRecord.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import keygen from 'boost/keygen'
44
import dataStore from 'boost/dataStore'
55
import { request, WEB_URL } from 'boost/api'
66

7+
const electron = require('electron')
8+
const version = electron.remote.app.getVersion()
9+
710
function isSameDate (a, b) {
811
a = moment(a).utcOffset(+540).format('YYYYMMDD')
912
b = moment(b).utcOffset(+540).format('YYYYMMDD')
@@ -16,6 +19,7 @@ export function init () {
1619
if (records == null) {
1720
saveAllRecords([])
1821
}
22+
emit(null)
1923

2024
postRecords()
2125
if (window != null) {
@@ -81,7 +85,7 @@ export function postRecords (data) {
8185
})
8286
}
8387

84-
export function emit (type, data) {
88+
export function emit (type, data = {}) {
8589
let records = getAllRecords()
8690

8791
let index = _.findIndex(records, record => {
@@ -94,7 +98,6 @@ export function emit (type, data) {
9498
records.push(todayRecord)
9599
}
96100
else todayRecord = records[index]
97-
console.log(type)
98101
switch (type) {
99102
case 'ARTICLE_CREATE':
100103
case 'ARTICLE_UPDATE':
@@ -104,16 +107,34 @@ export function emit (type, data) {
104107
case 'FOLDER_DESTROY':
105108
case 'FINDER_OPEN':
106109
case 'FINDER_COPY':
110+
case 'MAIN_DETAIL_COPY':
107111
todayRecord[type] = todayRecord[type] == null
108112
? 1
109113
: todayRecord[type] + 1
110114

111115
break
112116
}
113117

118+
// Count ARTICLE_CREATE and ARTICLE_UPDATE again by syntax
119+
if ((type === 'ARTICLE_CREATE' || type === 'ARTICLE_UPDATE') && data.mode != null) {
120+
let recordKey = type + '_BY_SYNTAX'
121+
if (todayRecord[recordKey] == null) todayRecord[recordKey] = {}
122+
123+
todayRecord[recordKey][data.mode] = todayRecord[recordKey][data.mode] == null
124+
? 1
125+
: todayRecord[recordKey][data.mode] + 1
126+
}
127+
114128
let storeData = dataStore.getData()
115129
todayRecord.FOLDER_COUNT = _.isArray(storeData.folders) ? storeData.folders.length : 0
116130
todayRecord.ARTICLE_COUNT = _.isArray(storeData.articles) ? storeData.articles.length : 0
131+
todayRecord.CLIENT_VERSION = version
132+
133+
todayRecord.SYNTAX_COUNT = storeData.articles.reduce((sum, article) => {
134+
if (sum[article.mode] == null) sum[article.mode] = 1
135+
else sum[article.mode]++
136+
return sum
137+
}, {})
117138

118139
saveAllRecords(records)
119140
}

lib/components/CodeEditor.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = React.createClass({
3030
editor.renderer.setShowGutter(true)
3131
editor.setTheme('ace/theme/xcode')
3232
editor.clearSelection()
33+
editor.moveCursorTo(0, 0)
3334

3435
editor.setReadOnly(!!this.props.readOnly)
3536

@@ -50,23 +51,33 @@ module.exports = React.createClass({
5051
this.props.onChange(e, value)
5152
}
5253
}.bind(this))
53-
54-
this.setState({editor: editor})
5554
},
5655
componentDidUpdate: function (prevProps) {
57-
if (this.state.editor.getValue() !== this.props.code) {
58-
this.state.editor.setValue(this.props.code)
59-
this.state.editor.clearSelection()
56+
if (this.editor.getValue() !== this.props.code) {
57+
this.editor.setValue(this.props.code)
58+
this.editor.clearSelection()
6059
}
6160
if (prevProps.mode !== this.props.mode) {
62-
var session = this.state.editor.getSession()
61+
var session = this.editor.getSession()
6362
let mode = _.findWhere(modes, {name: this.props.mode})
6463
let syntaxMode = mode != null
6564
? mode.mode
6665
: 'text'
6766
session.setMode('ace/mode/' + syntaxMode)
6867
}
6968
},
69+
getFirstVisibleRow: function () {
70+
return this.editor.getFirstVisibleRow()
71+
},
72+
getCursorPosition: function () {
73+
return this.editor.getCursorPosition()
74+
},
75+
moveCursorTo: function (row, col) {
76+
this.editor.moveCursorTo(row, col)
77+
},
78+
scrollToLine: function (num) {
79+
this.editor.scrollToLine(num, false, false)
80+
},
7081
render: function () {
7182
return (
7283
<div ref='target' className={this.props.className == null ? 'CodeEditor' : 'CodeEditor ' + this.props.className}></div>

lib/components/ModeSelect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ export default class ModeSelect extends React.Component {
161161
let filteredOptions = modes
162162
.filter(mode => {
163163
let search = this.state.search
164-
let nameMatched = mode.name.match(search)
165-
let aliasMatched = _.some(mode.alias, alias => alias.match(search))
164+
let nameMatched = mode.name.match(_.escapeRegExp(search))
165+
let aliasMatched = _.some(mode.alias, alias => alias.match(_.escapeRegExp(search)))
166166
return nameMatched || aliasMatched
167167
})
168168
.map((mode, index) => {

lib/markdown.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,31 @@ var md = markdownit({
88
highlight: function (str, lang) {
99
if (lang && hljs.getLanguage(lang)) {
1010
try {
11-
return hljs.highlight(lang, str).value;
11+
return hljs.highlight(lang, str).value
1212
} catch (__) {}
1313
}
1414

1515
try {
16-
return hljs.highlightAuto(str).value;
16+
return hljs.highlightAuto(str).value
1717
} catch (__) {}
1818

19-
return ''; // use external default escaping
19+
return ''
2020
}
2121
})
2222
md.use(emoji)
2323

24+
let originalRenderToken = md.renderer.renderToken
25+
md.renderer.renderToken = function renderToken (tokens, idx, options) {
26+
let token = tokens[idx]
27+
let result = originalRenderToken.call(md.renderer, tokens, idx, options)
28+
if (token.map != null) {
29+
return result + '<a class=\'lineAnchor\' data-key=\'' + token.map[0] + '\'></a>'
30+
}
31+
return result
32+
}
33+
2434
export default function markdown (content) {
2535
if (content == null) content = ''
36+
2637
return md.render(content.toString())
2738
}

lib/vars/modes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const modes = [
6868
{
6969
name: 'csharp',
7070
label: 'C#',
71-
alias: ['cs'],
71+
alias: ['cs', 'c#'],
7272
mode: 'csharp'
7373
},
7474
{

0 commit comments

Comments
 (0)