Skip to content

Commit 301f03d

Browse files
authored
Merge branch 'master' into master
2 parents 0722c25 + 53c48d8 commit 301f03d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+868
-274
lines changed

browser/components/CodeEditor.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ export default class CodeEditor extends React.Component {
663663
const checkMarkdownNoteIsOpen = mode === 'Boost Flavored Markdown'
664664

665665
return checkMarkdownNoteIsOpen ? {
666-
'getAnnotations': this.validatorOfMarkdown,
667-
'async': true
666+
getAnnotations: this.validatorOfMarkdown,
667+
async: true
668668
} : false
669669
}
670670

@@ -679,10 +679,10 @@ export default class CodeEditor extends React.Component {
679679
return
680680
}
681681
const lintOptions = {
682-
'strings': {
683-
'content': text
682+
strings: {
683+
content: text
684684
},
685-
'config': lintConfigJson
685+
config: lintConfigJson
686686
}
687687

688688
return markdownlint(lintOptions, (err, result) => {

browser/components/MarkdownEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class MarkdownEditor extends React.Component {
119119
status: 'PREVIEW'
120120
}, () => {
121121
this.refs.preview.focus()
122-
this.refs.preview.scrollTo(cursorPosition.line)
122+
this.refs.preview.scrollToRow(cursorPosition.line)
123123
})
124124
eventEmitter.emit('topbar:togglelockbutton', this.state.status)
125125
}

browser/components/MarkdownPreview.js

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import yaml from 'js-yaml'
2121
import { render } from 'react-dom'
2222
import Carousel from 'react-image-carousel'
2323
import ConfigManager from '../main/lib/ConfigManager'
24+
import i18n from 'browser/lib/i18n'
2425

2526
const { remote, shell } = require('electron')
2627
const attachmentManagement = require('../main/lib/dataApi/attachmentManagement')
@@ -50,7 +51,6 @@ const CSS_FILES = [
5051
* @param {String} opts.theme
5152
* @param {Boolean} [opts.lineNumber] Should show line number
5253
* @param {Boolean} [opts.scrollPastEnd]
53-
* @param {Boolean} [opts.optimizeOverflowScroll] Should tweak body style to optimize overflow scrollbar display
5454
* @param {Boolean} [opts.allowCustomCSS] Should add custom css
5555
* @param {String} [opts.customCSS] Will be added to bottom, only if `opts.allowCustomCSS` is truthy
5656
* @returns {String}
@@ -62,7 +62,6 @@ function buildStyle (opts) {
6262
codeBlockFontFamily,
6363
lineNumber,
6464
scrollPastEnd,
65-
optimizeOverflowScroll,
6665
theme,
6766
allowCustomCSS,
6867
customCSS,
@@ -103,7 +102,12 @@ ${markdownStyle}
103102
body {
104103
font-family: '${fontFamily.join("','")}';
105104
font-size: ${fontSize}px;
106-
${scrollPastEnd ? 'padding-bottom: 90vh;' : ''}
105+
106+
${scrollPastEnd ? `
107+
padding-bottom: 90vh;
108+
box-sizing: border-box;
109+
`
110+
: ''}
107111
${optimizeOverflowScroll ? 'height: 100%;' : ''}
108112
${RTL ? 'direction: rtl;' : ''}
109113
${RTL ? 'text-align: right;' : ''}
@@ -184,6 +188,10 @@ const scrollBarStyle = `
184188
::-webkit-scrollbar-thumb {
185189
background-color: rgba(0, 0, 0, 0.15);
186190
}
191+
192+
::-webkit-scrollbar-track-piece {
193+
background-color: inherit;
194+
}
187195
`
188196
const scrollBarDarkStyle = `
189197
::-webkit-scrollbar {
@@ -193,6 +201,10 @@ const scrollBarDarkStyle = `
193201
::-webkit-scrollbar-thumb {
194202
background-color: rgba(0, 0, 0, 0.3);
195203
}
204+
205+
::-webkit-scrollbar-track-piece {
206+
background-color: inherit;
207+
}
196208
`
197209

198210
const OSX = global.process.platform === 'darwin'
@@ -241,6 +253,7 @@ export default class MarkdownPreview extends React.Component {
241253
this.saveAsHtmlHandler = () => this.handleSaveAsHtml()
242254
this.saveAsPdfHandler = () => this.handleSaveAsPdf()
243255
this.printHandler = () => this.handlePrint()
256+
this.resizeHandler = _.throttle(this.handleResize.bind(this), 100)
244257

245258
this.linkClickHandler = this.handleLinkClick.bind(this)
246259
this.initMarkdown = this.initMarkdown.bind(this)
@@ -346,7 +359,7 @@ export default class MarkdownPreview extends React.Component {
346359
customCSS,
347360
RTL
348361
})
349-
let body = this.markdown.render(noteContent)
362+
let body = this.refs.root.contentWindow.document.body.innerHTML
350363
body = attachmentManagement.fixLocalURLS(
351364
body,
352365
this.props.storagePath
@@ -366,7 +379,7 @@ export default class MarkdownPreview extends React.Component {
366379

367380
let styles = ''
368381
files.forEach(file => {
369-
styles += `<link rel="stylesheet" href="css/${path.basename(file)}">`
382+
styles += `<link rel="stylesheet" href="../css/${path.basename(file)}">`
370383
})
371384

372385
return `<html>
@@ -421,7 +434,8 @@ export default class MarkdownPreview extends React.Component {
421434
.then(res => {
422435
dialog.showMessageBox(remote.getCurrentWindow(), {
423436
type: 'info',
424-
message: `Exported to ${filename}`
437+
message: `Exported to ${filename}`,
438+
buttons: [i18n.__('Ok')]
425439
})
426440
})
427441
.catch(err => {
@@ -536,6 +550,10 @@ export default class MarkdownPreview extends React.Component {
536550
'scroll',
537551
this.scrollHandler
538552
)
553+
this.refs.root.contentWindow.addEventListener(
554+
'resize',
555+
this.resizeHandler
556+
)
539557
eventEmitter.on('export:save-text', this.saveAsTextHandler)
540558
eventEmitter.on('export:save-md', this.saveAsMdHandler)
541559
eventEmitter.on('export:save-html', this.saveAsHtmlHandler)
@@ -574,6 +592,10 @@ export default class MarkdownPreview extends React.Component {
574592
'scroll',
575593
this.scrollHandler
576594
)
595+
this.refs.root.contentWindow.removeEventListener(
596+
'resize',
597+
this.resizeHandler
598+
)
577599
eventEmitter.off('export:save-text', this.saveAsTextHandler)
578600
eventEmitter.off('export:save-md', this.saveAsMdHandler)
579601
eventEmitter.off('export:save-html', this.saveAsHtmlHandler)
@@ -619,7 +641,7 @@ export default class MarkdownPreview extends React.Component {
619641

620642
// Should scroll to top after selecting another note
621643
if (prevProps.noteKey !== this.props.noteKey) {
622-
this.getWindow().scrollTo(0, 0)
644+
this.scrollTo(0, 0)
623645
}
624646
}
625647

@@ -686,13 +708,11 @@ export default class MarkdownPreview extends React.Component {
686708
codeBlockFontFamily,
687709
lineNumber,
688710
scrollPastEnd,
689-
optimizeOverflowScroll: true,
690711
theme,
691712
allowCustomCSS,
692713
customCSS,
693714
RTL
694715
})
695-
this.getWindow().document.documentElement.style.overflowY = 'hidden'
696716
}
697717

698718
getCodeThemeLink (name) {
@@ -1000,6 +1020,15 @@ export default class MarkdownPreview extends React.Component {
10001020
}
10011021
}
10021022

1023+
handleResize () {
1024+
_.forEach(
1025+
this.refs.root.contentWindow.document.querySelectorAll('svg[ratio]'),
1026+
el => {
1027+
el.setAttribute('height', el.clientWidth / el.getAttribute('ratio'))
1028+
}
1029+
)
1030+
}
1031+
10031032
focus () {
10041033
this.refs.root.focus()
10051034
}
@@ -1008,7 +1037,11 @@ export default class MarkdownPreview extends React.Component {
10081037
return this.refs.root.contentWindow
10091038
}
10101039

1011-
scrollTo (targetRow) {
1040+
/**
1041+
* @public
1042+
* @param {Number} targetRow
1043+
*/
1044+
scrollToRow (targetRow) {
10121045
const blocks = this.getWindow().document.querySelectorAll(
10131046
'body>[data-line]'
10141047
)
@@ -1018,12 +1051,21 @@ export default class MarkdownPreview extends React.Component {
10181051
const row = parseInt(block.getAttribute('data-line'))
10191052
if (row > targetRow || index === blocks.length - 1) {
10201053
block = blocks[index - 1]
1021-
block != null && this.getWindow().scrollTo(0, block.offsetTop)
1054+
block != null && this.scrollTo(0, block.offsetTop)
10221055
break
10231056
}
10241057
}
10251058
}
10261059

1060+
/**
1061+
* `document.body.scrollTo`
1062+
* @param {Number} x
1063+
* @param {Number} y
1064+
*/
1065+
scrollTo (x, y) {
1066+
this.getWindow().document.body.scrollTo(x, y)
1067+
}
1068+
10271069
preventImageDroppedHandler (e) {
10281070
e.preventDefault()
10291071
e.stopPropagation()
@@ -1061,12 +1103,12 @@ export default class MarkdownPreview extends React.Component {
10611103
if (posOfHash > -1) {
10621104
const extractedId = linkHash.slice(posOfHash + 1)
10631105
const targetId = mdurl.encode(extractedId)
1064-
const targetElement = this.refs.root.contentWindow.document.getElementById(
1106+
const targetElement = this.getWindow().document.getElementById(
10651107
targetId
10661108
)
10671109

10681110
if (targetElement != null) {
1069-
this.getWindow().scrollTo(0, targetElement.offsetTop)
1111+
this.scrollTo(0, targetElement.offsetTop)
10701112
}
10711113
return
10721114
}

browser/components/NoteItem.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PropTypes from 'prop-types'
55
import React from 'react'
66
import { isArray, sortBy } from 'lodash'
77
import invertColor from 'invert-color'
8+
import Emoji from 'react-emoji-render'
89
import CSSModules from 'browser/lib/CSSModules'
910
import { getTodoStatus } from 'browser/lib/getTodoStatus'
1011
import styles from './NoteItem.styl'
@@ -87,7 +88,7 @@ const NoteItem = ({
8788
: <i styleName='item-title-icon' className='fa fa-fw fa-file-text-o' />}
8889
<div styleName='item-title'>
8990
{note.title.trim().length > 0
90-
? note.title
91+
? <Emoji text={note.title} />
9192
: <span styleName='item-title-empty'>{i18n.__('Empty note')}</span>}
9293
</div>
9394
<div styleName='item-middle'>

0 commit comments

Comments
 (0)