Skip to content

Commit 4915c54

Browse files
authored
Merge branch 'master' into fixIssue2534
2 parents e1c95fb + 5f56d3e commit 4915c54

23 files changed

+602
-221
lines changed

ISSUE_TEMPLATE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ Let us know what is currently happening.
55
66
Please include some **screenshots** with the **developer tools** open (console tab) when you report a bug.
77
8-
If your issue is regarding Boostnote mobile, please open an issue in the Boostnote Mobile repo 👉 https://github.com/BoostIO/boostnote-mobile.
8+
If your issue is regarding the new Boost Note.next, please open an issue in the new repo 👉 https://github.com/BoostIO/BoostNote.next/issues.
99
-->
1010

1111
# Expected behavior
1212

1313
<!--
14-
Let us know what you think should happen!
14+
Let us know what you think should happen.
1515
-->
1616

1717
# Steps to reproduce
1818

1919
<!--
20-
Please be thorough, issues we can reproduce are easier to fix!
20+
Please be thorough, issues we can reproduce are easier to fix.
2121
-->
2222

2323
1.
@@ -26,8 +26,8 @@ Please be thorough, issues we can reproduce are easier to fix!
2626

2727
# Environment
2828

29-
- Version :
30-
- OS Version and name :
29+
- Boostnote version: <!-- 0.x.x -->
30+
- OS version and name: <!-- Windows 10 / Ubuntu 18.04 / etc -->
3131

3232
<!--
3333
Love Boostnote? Please consider supporting us on IssueHunt:

PULL_REQUEST_TEMPLATE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ Before submitting this PR, please make sure that:
33
- You have read and understand the contributing.md
44
- You have checked docs/code_style.md for information on code style
55
-->
6+
67
## Description
8+
79
<!--
810
Tell us what your PR does.
911
Please attach a screenshot/ video/gif image describing your PR if possible.
1012
-->
1113

1214
## Issue fixed
15+
1316
<!--
1417
Please list out all issue fixed with this PR here.
1518
-->
@@ -20,6 +23,7 @@ your PR will be reviewed faster if we know exactly what it does.
2023
2124
Change :white_circle: to :radio_button: in all the options that apply
2225
-->
26+
2327
## Type of changes
2428

2529
- :white_circle: Bug fix (Change that fixed an issue)
@@ -34,3 +38,5 @@ Change :white_circle: to :radio_button: in all the options that apply
3438
- :white_circle: I have written test for my code and it has been tested
3539
- :white_circle: All existing tests have been passed
3640
- :white_circle: I have attached a screenshot/video to visualize my change if possible
41+
- :white_circle: This PR will modify the UI or affects the UX
42+
- :white_circle: This PR will add/update/delete a keybinding

browser/components/MarkdownEditor.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable camelcase */
12
import PropTypes from 'prop-types'
23
import React from 'react'
34
import CSSModules from 'browser/lib/CSSModules'
@@ -29,20 +30,23 @@ class MarkdownEditor extends React.Component {
2930
isLocked: props.isLocked
3031
}
3132

32-
this.lockEditorCode = () => this.handleLockEditor()
33+
this.lockEditorCode = this.handleLockEditor.bind(this)
34+
this.focusEditor = this.focusEditor.bind(this)
35+
36+
this.previewRef = React.createRef()
3337
}
3438

3539
componentDidMount() {
3640
this.value = this.refs.code.value
3741
eventEmitter.on('editor:lock', this.lockEditorCode)
38-
eventEmitter.on('editor:focus', this.focusEditor.bind(this))
42+
eventEmitter.on('editor:focus', this.focusEditor)
3943
}
4044

4145
componentDidUpdate() {
4246
this.value = this.refs.code.value
4347
}
4448

45-
componentWillReceiveProps(props) {
49+
UNSAFE_componentWillReceiveProps(props) {
4650
if (props.value !== this.props.value) {
4751
this.queueRendering(props.value)
4852
}
@@ -51,7 +55,7 @@ class MarkdownEditor extends React.Component {
5155
componentWillUnmount() {
5256
this.cancelQueue()
5357
eventEmitter.off('editor:lock', this.lockEditorCode)
54-
eventEmitter.off('editor:focus', this.focusEditor.bind(this))
58+
eventEmitter.off('editor:focus', this.focusEditor)
5559
}
5660

5761
focusEditor() {
@@ -60,6 +64,9 @@ class MarkdownEditor extends React.Component {
6064
status: 'CODE'
6165
},
6266
() => {
67+
if (this.refs.code == null) {
68+
return
69+
}
6370
this.refs.code.focus()
6471
}
6572
)
@@ -104,7 +111,7 @@ class MarkdownEditor extends React.Component {
104111
if (newStatus === 'CODE') {
105112
this.refs.code.focus()
106113
} else {
107-
this.refs.preview.focus()
114+
this.previewRef.current.focus()
108115
}
109116
eventEmitter.emit('topbar:togglelockbutton', this.state.status)
110117

@@ -131,8 +138,8 @@ class MarkdownEditor extends React.Component {
131138
status: 'PREVIEW'
132139
},
133140
() => {
134-
this.refs.preview.focus()
135-
this.refs.preview.scrollToRow(cursorPosition.line)
141+
this.previewRef.current.focus()
142+
this.previewRef.current.scrollToRow(cursorPosition.line)
136143
}
137144
)
138145
eventEmitter.emit('topbar:togglelockbutton', this.state.status)
@@ -379,6 +386,7 @@ class MarkdownEditor extends React.Component {
379386
RTL={RTL}
380387
/>
381388
<MarkdownPreview
389+
ref={this.previewRef}
382390
styleName={
383391
this.state.status === 'PREVIEW' ? 'preview' : 'preview--hide'
384392
}
@@ -397,7 +405,6 @@ class MarkdownEditor extends React.Component {
397405
breaks={config.preview.breaks}
398406
sanitize={config.preview.sanitize}
399407
mermaidHTMLLabel={config.preview.mermaidHTMLLabel}
400-
ref='preview'
401408
onContextMenu={e => this.handleContextMenu(e)}
402409
onDoubleClick={e => this.handleDoubleClick(e)}
403410
tabIndex='0'

browser/components/MarkdownPreview.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PropTypes from 'prop-types'
22
import React from 'react'
3+
import { connect } from 'react-redux'
34
import Markdown from 'browser/lib/markdown'
45
import _ from 'lodash'
56
import CodeMirror from 'codemirror'
@@ -21,6 +22,7 @@ import { escapeHtmlCharacters } from 'browser/lib/utils'
2122
import yaml from 'js-yaml'
2223
import { render } from 'react-dom'
2324
import Carousel from 'react-image-carousel'
25+
import { push } from 'connected-react-router'
2426
import ConfigManager from '../main/lib/ConfigManager'
2527
import uiThemes from 'browser/lib/ui-themes'
2628
import i18n from 'browser/lib/i18n'
@@ -252,7 +254,7 @@ function getSourceLineNumberByElement(element) {
252254
return parent.dataset.line !== undefined ? parseInt(parent.dataset.line) : -1
253255
}
254256

255-
export default class MarkdownPreview extends React.Component {
257+
class MarkdownPreview extends React.Component {
256258
constructor(props) {
257259
super(props)
258260

@@ -1116,6 +1118,7 @@ export default class MarkdownPreview extends React.Component {
11161118
e.stopPropagation()
11171119

11181120
const rawHref = e.target.getAttribute('href')
1121+
const { dispatch } = this.props
11191122
if (!rawHref) return // not checked href because parser will create file://... string for [empty link]()
11201123

11211124
const parser = document.createElement('a')
@@ -1169,6 +1172,13 @@ export default class MarkdownPreview extends React.Component {
11691172
return
11701173
}
11711174

1175+
const regexIsTagLink = /^:tag:([\w]+)$/
1176+
if (regexIsTagLink.test(rawHref)) {
1177+
const tag = rawHref.match(regexIsTagLink)[1]
1178+
dispatch(push(`/tags/${encodeURIComponent(tag)}`))
1179+
return
1180+
}
1181+
11721182
// other case
11731183
this.openExternal(href)
11741184
}
@@ -1213,3 +1223,10 @@ MarkdownPreview.propTypes = {
12131223
smartArrows: PropTypes.bool,
12141224
breaks: PropTypes.bool
12151225
}
1226+
1227+
export default connect(
1228+
null,
1229+
null,
1230+
null,
1231+
{ forwardRef: true }
1232+
)(MarkdownPreview)

browser/components/MarkdownSplitEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class MarkdownSplitEditor extends React.Component {
215215
<div styleName='slider-hitbox' />
216216
</div>
217217
<MarkdownPreview
218+
ref='preview'
218219
style={previewStyle}
219220
theme={config.ui.theme}
220221
keyMap={config.editor.keyMap}
@@ -229,7 +230,6 @@ class MarkdownSplitEditor extends React.Component {
229230
breaks={config.preview.breaks}
230231
sanitize={config.preview.sanitize}
231232
mermaidHTMLLabel={config.preview.mermaidHTMLLabel}
232-
ref='preview'
233233
tabInde='0'
234234
value={value}
235235
onCheckboxClick={e => this.handleCheckboxClick(e)}

browser/components/StorageItem.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const FolderIcon = ({ className, color, isActive }) => {
2121

2222
/**
2323
* @param {boolean} isActive
24+
* @param {object} tooltipRef,
2425
* @param {Function} handleButtonClick
26+
* @param {Function} handleMouseEnter
2527
* @param {Function} handleContextMenu
2628
* @param {string} folderName
2729
* @param {string} folderColor
@@ -35,7 +37,9 @@ const FolderIcon = ({ className, color, isActive }) => {
3537
const StorageItem = ({
3638
styles,
3739
isActive,
40+
tooltipRef,
3841
handleButtonClick,
42+
handleMouseEnter,
3943
handleContextMenu,
4044
folderName,
4145
folderColor,
@@ -49,6 +53,7 @@ const StorageItem = ({
4953
<button
5054
styleName={isActive ? 'folderList-item--active' : 'folderList-item'}
5155
onClick={handleButtonClick}
56+
onMouseEnter={handleMouseEnter}
5257
onContextMenu={handleContextMenu}
5358
onDrop={handleDrop}
5459
onDragEnter={handleDragEnter}
@@ -75,15 +80,19 @@ const StorageItem = ({
7580
<span styleName='folderList-item-noteCount'>{noteCount}</span>
7681
)}
7782
{isFolded && (
78-
<span styleName='folderList-item-tooltip'>{folderName}</span>
83+
<span styleName='folderList-item-tooltip' ref={tooltipRef}>
84+
{folderName}
85+
</span>
7986
)}
8087
</button>
8188
)
8289
}
8390

8491
StorageItem.propTypes = {
8592
isActive: PropTypes.bool.isRequired,
93+
tooltipRef: PropTypes.object,
8694
handleButtonClick: PropTypes.func,
95+
handleMouseEnter: PropTypes.func,
8796
handleContextMenu: PropTypes.func,
8897
folderName: PropTypes.string.isRequired,
8998
folderColor: PropTypes.string,

browser/components/StorageItem.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
border-bottom-right-radius 2px
6161
height 34px
6262
line-height 32px
63+
transition-property opacity
6364

6465
.folderList-item:hover, .folderList-item--active:hover
6566
.folderList-item-tooltip

browser/components/StorageList.styl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.storageList
2-
margin-bottom 37px
2+
absolute left right
3+
bottom 37px
4+
top 180px
35
overflow-y auto
46

57
.storageList-folded

browser/finder/NoteDetail.js

Whitespace-only changes.

browser/main/Detail/MarkdownNoteDetail.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable camelcase */
12
import PropTypes from 'prop-types'
23
import React from 'react'
34
import CSSModules from 'browser/lib/CSSModules'
@@ -57,7 +58,8 @@ class MarkdownNoteDetail extends React.Component {
5758
this.dispatchTimer = null
5859

5960
this.toggleLockButton = this.handleToggleLockButton.bind(this)
60-
this.generateToc = () => this.handleGenerateToc()
61+
this.generateToc = this.handleGenerateToc.bind(this)
62+
this.handleUpdateContent = this.handleUpdateContent.bind(this)
6163
}
6264

6365
focus() {
@@ -76,7 +78,7 @@ class MarkdownNoteDetail extends React.Component {
7678
ee.on('code:generate-toc', this.generateToc)
7779
}
7880

79-
componentWillReceiveProps(nextProps) {
81+
UNSAFE_componentWillReceiveProps(nextProps) {
8082
const isNewNote = nextProps.note.key !== this.props.note.key
8183
const hasDeletedTags =
8284
nextProps.note.tags.length < this.props.note.tags.length
@@ -392,6 +394,9 @@ class MarkdownNoteDetail extends React.Component {
392394
}
393395

394396
handleSwitchDirection() {
397+
if (!this.props.config.editor.rtlEnabled) {
398+
return
399+
}
395400
// If in split mode, hide the lock button
396401
const direction = this.state.RTL
397402
this.setState({ RTL: !direction })
@@ -436,10 +441,10 @@ class MarkdownNoteDetail extends React.Component {
436441
storageKey={note.storage}
437442
noteKey={note.key}
438443
linesHighlighted={note.linesHighlighted}
439-
onChange={this.handleUpdateContent.bind(this)}
444+
onChange={this.handleUpdateContent}
440445
isLocked={this.state.isLocked}
441446
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
442-
RTL={this.state.RTL}
447+
RTL={config.editor.rtlEnabled && this.state.RTL}
443448
/>
444449
)
445450
} else {
@@ -451,9 +456,9 @@ class MarkdownNoteDetail extends React.Component {
451456
storageKey={note.storage}
452457
noteKey={note.key}
453458
linesHighlighted={note.linesHighlighted}
454-
onChange={this.handleUpdateContent.bind(this)}
459+
onChange={this.handleUpdateContent}
455460
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
456-
RTL={this.state.RTL}
461+
RTL={config.editor.rtlEnabled && this.state.RTL}
457462
/>
458463
)
459464
}
@@ -536,10 +541,12 @@ class MarkdownNoteDetail extends React.Component {
536541
onClick={e => this.handleSwitchMode(e)}
537542
editorType={editorType}
538543
/>
539-
<ToggleDirectionButton
540-
onClick={e => this.handleSwitchDirection(e)}
541-
isRTL={this.state.RTL}
542-
/>
544+
{this.props.config.editor.rtlEnabled && (
545+
<ToggleDirectionButton
546+
onClick={e => this.handleSwitchDirection(e)}
547+
isRTL={this.state.RTL}
548+
/>
549+
)}
543550
<StarButton
544551
onClick={e => this.handleStarButtonClick(e)}
545552
isActive={note.isStarred}

0 commit comments

Comments
 (0)