Skip to content

Commit c34a556

Browse files
committed
add disable plugin, emoji replacement
1 parent 8f06753 commit c34a556

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

lib/keys.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var KEYS = {
2323
188: 'comma',
2424
190: '.',
2525
191: '/',
26+
220: '\\',
2627
219: '[',
2728
221: ']'
2829
}

plugins/disable/:w

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
import React from 'react'
3+
import {StyleSheet, css} from 'aphrodite'
4+
5+
module.exports = {
6+
title: 'Disable',
7+
8+
keys: {
9+
'toggle disabled': {
10+
normal: '\\',
11+
visual: '\\',
12+
},
13+
},
14+
15+
store: {
16+
actions: {
17+
toggleDisabled(id) {
18+
if (!arguments.length) id = this.view.active
19+
this.set(id, 'disabled', !this.db.nodes[id].disabled)
20+
},
21+
},
22+
},
23+
24+
node: {
25+
classes(node, state) {
26+
return node.disabled ? css(styles.disabled) : ''
27+
},
28+
},
29+
}
30+
31+
const styles = StyleSheet.create({
32+
disabled: {
33+
fontSize: '80%',
34+
color: '#aaa',
35+
borderLeft: '10px solid #aaa',
36+
},
37+
})
38+

plugins/disable/index.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
import React from 'react'
3+
import {StyleSheet, css} from 'aphrodite'
4+
5+
module.exports = {
6+
title: 'Disable',
7+
8+
keys: {
9+
'toggle disabled': {
10+
normal: '\\',
11+
visual: '\\',
12+
},
13+
},
14+
15+
store: {
16+
actions: {
17+
toggleDisabled(id) {
18+
if (!arguments.length) id = this.view.active
19+
this.set(id, 'disabled', !this.db.nodes[id].disabled)
20+
},
21+
},
22+
},
23+
24+
node: {
25+
classes(node, state) {
26+
return node.disabled ? css(styles.disabled) : ''
27+
},
28+
},
29+
}
30+
31+
const styles = StyleSheet.create({
32+
disabled: {
33+
fontSize: '80%',
34+
color: '#aaa',
35+
},
36+
})
37+

util/ensure-in-view.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ function ensureInView(item) {
4040
return
4141
}
4242
var dest
43-
if (itemBox.top < parentBox.top) {
43+
if (itemBox.top < parentBox.top + margin) {
4444
dest = parent.scrollTop - (parentBox.top - itemBox.top + margin)
45-
} else if (itemBox.bottom > parentBox.bottom) {
45+
} else if (itemBox.bottom > parentBox.bottom - margin) {
4646
dest = parent.scrollTop + itemBox.bottom - parentBox.bottom + margin
4747
} else {
4848
return

views/body/default-renderer.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ renderer.link = function (href, title, text) {
99
return '<a href="' + href + '" target="_blank" title="' + title + '">' + text + '</a>';
1010
}
1111

12+
function escapeRegExp(str) {
13+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
14+
}
15+
1216
marked.setOptions({
1317
gfm: true,
1418
// sanitize: true,
@@ -20,6 +24,35 @@ marked.setOptions({
2024
renderer: renderer
2125
})
2226

27+
const emojis = {
28+
':?:': '❓',
29+
':t:': '💭',
30+
':":': '❝',
31+
':i:': '💡',
32+
':?!:': '🗣',
33+
':)': '🙂',
34+
':P': '😛',
35+
':D': '😀',
36+
':/': '😕',
37+
':(': '🙁',
38+
';)': '😉',
39+
'>.<': '😣',
40+
':p:': '🎉',
41+
}
42+
43+
const emoji_names = {
44+
party: '🎉',
45+
}
46+
47+
const emojiRegexes = Object.keys(emojis)
48+
.map(k => [new RegExp('\\B' + escapeRegExp(k) + '\\B', 'g'), emojis[k]]);
49+
50+
const replaceReduce = (text, [rx, emo]) => text.replace(rx, emo)
51+
52+
const replaceEmojis = text => {
53+
return emojiRegexes.reduce(replaceReduce, text)
54+
}
55+
2356
var DefaultRenderer = React.createClass({
2457
_onClick(e) {
2558
if (e.target.nodeName === 'A') return
@@ -29,7 +62,7 @@ var DefaultRenderer = React.createClass({
2962
return <span className="treed_body_rendered"
3063
onClick={this._onClick}
3164
dangerouslySetInnerHTML={{
32-
__html: this.props.content ? marked(this.props.content + '') : ''
65+
__html: this.props.content ? marked(replaceEmojis(this.props.content + '')) : ''
3366
}}/>
3467
}
3568
})

0 commit comments

Comments
 (0)