Skip to content

Commit

Permalink
Merge pull request #3136 from hikerpig/feature/scrollbarAppearance
Browse files Browse the repository at this point in the history
tweak MarkdownPreview style to optimize overflow scrollbar display
  • Loading branch information
Rokt33r authored Sep 2, 2019
2 parents e9975d1 + 9a704a2 commit 1332b33
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions browser/components/MarkdownPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,31 @@ const CSS_FILES = [
`${appPath}/node_modules/react-image-carousel/lib/css/main.min.css`
]

function buildStyle (
fontFamily,
fontSize,
codeBlockFontFamily,
lineNumber,
scrollPastEnd,
theme,
allowCustomCSS,
customCSS
) {
/**
* @param {Object} opts
* @param {String} opts.fontFamily
* @param {Numberl} opts.fontSize
* @param {String} opts.codeBlockFontFamily
* @param {String} opts.theme
* @param {Boolean} [opts.lineNumber] Should show line number
* @param {Boolean} [opts.scrollPastEnd]
* @param {Boolean} [opts.optimizeOverflowScroll] Should tweak body style to optimize overflow scrollbar display
* @param {Boolean} [opts.allowCustomCSS] Should add custom css
* @param {String} [opts.customCSS] Will be added to bottom, only if `opts.allowCustomCSS` is truthy
* @returns {String}
*/
function buildStyle (opts) {
const {
fontFamily,
fontSize,
codeBlockFontFamily,
lineNumber,
scrollPastEnd,
optimizeOverflowScroll,
theme,
allowCustomCSS,
customCSS
} = opts
return `
@font-face {
font-family: 'Lato';
Expand Down Expand Up @@ -81,12 +96,14 @@ function buildStyle (
url('${appPath}/resources/fonts/MaterialIcons-Regular.woff') format('woff'),
url('${appPath}/resources/fonts/MaterialIcons-Regular.ttf') format('truetype');
}
${markdownStyle}
body {
font-family: '${fontFamily.join("','")}';
font-size: ${fontSize}px;
${scrollPastEnd && 'padding-bottom: 90vh;'}
${scrollPastEnd ? 'padding-bottom: 90vh;' : ''}
${optimizeOverflowScroll ? 'height: 100%;' : ''}
}
@media print {
body {
Expand Down Expand Up @@ -312,7 +329,7 @@ export default class MarkdownPreview extends React.Component {
customCSS
} = this.getStyleParams()

const inlineStyles = buildStyle(
const inlineStyles = buildStyle({
fontFamily,
fontSize,
codeBlockFontFamily,
Expand All @@ -321,7 +338,7 @@ export default class MarkdownPreview extends React.Component {
theme,
allowCustomCSS,
customCSS
)
})
let body = this.markdown.render(noteContent)
body = attachmentManagement.fixLocalURLS(
body,
Expand Down Expand Up @@ -652,16 +669,18 @@ export default class MarkdownPreview extends React.Component {
this.getWindow().document.getElementById(
'codeTheme'
).href = this.getCodeThemeLink(codeBlockTheme)
this.getWindow().document.getElementById('style').innerHTML = buildStyle(
this.getWindow().document.getElementById('style').innerHTML = buildStyle({
fontFamily,
fontSize,
codeBlockFontFamily,
lineNumber,
scrollPastEnd,
optimizeOverflowScroll: true,
theme,
allowCustomCSS,
customCSS
)
})
this.getWindow().document.documentElement.style.overflowY = 'hidden'
}

getCodeThemeLink (name) {
Expand Down

0 comments on commit 1332b33

Please sign in to comment.