Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom background - Editor #3280

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { isMarkdownTitleURL } from 'browser/lib/utils'
import styles from '../components/CodeEditor.styl'
const { ipcRenderer, remote, clipboard } = require('electron')
import normalizeEditorFontFamily from 'browser/lib/normalizeEditorFontFamily'
import normalizeBackgroundImage from 'browser/lib/normalizeBackgroundImage'
const spellcheck = require('browser/lib/spellcheck')
const buildEditorContextMenu = require('browser/lib/contextMenuBuilder').buildEditorContextMenu
import { createTurndownService } from '../lib/turndown'
Expand Down Expand Up @@ -274,6 +275,7 @@ export default class CodeEditor extends React.Component {

componentDidMount () {
const { rulers, enableRulers, enableMarkdownLint } = this.props
const backgroundPath = normalizeBackgroundImage(this.props.backgroundPath)
eventEmitter.on('line:jump', this.scrollToLineHandeler)

snippetManager.init()
Expand Down Expand Up @@ -304,10 +306,12 @@ export default class CodeEditor extends React.Component {
override: true
},
extraKeys: this.defaultKeyMap,
prettierConfig: this.props.prettierConfig
prettierConfig: this.props.prettierConfig,
backgroundPath: this.props.backgroundPath
})

document.querySelector('.CodeMirror-lint-markers').style.display = enableMarkdownLint ? 'inline-block' : 'none'
document.querySelector('.CodeMirror.CodeMirror-wrap').style.backgroundImage = backgroundPath

if (!this.props.mode && this.props.value && this.props.autoDetect) {
this.autoDetectLanguage(this.props.value)
Expand Down Expand Up @@ -552,6 +556,10 @@ export default class CodeEditor extends React.Component {
if (prevProps.fontFamily !== this.props.fontFamily) {
needRefresh = true
}
if (prevProps.backgroundPath !== this.props.backgroundPath) {
document.querySelector('.CodeMirror.CodeMirror-wrap').style.backgroundImage = normalizeBackgroundImage(this.props.backgroundPath)
needRefresh = true
}
if (prevProps.keyMap !== this.props.keyMap) {
needRefresh = true
}
Expand Down Expand Up @@ -1219,7 +1227,8 @@ CodeEditor.propTypes = {
spellCheck: PropTypes.bool,
enableMarkdownLint: PropTypes.bool,
customMarkdownLintConfig: PropTypes.string,
deleteUnusedAttachments: PropTypes.bool
deleteUnusedAttachments: PropTypes.bool,
backgroundPath: PropTypes.string
}

CodeEditor.defaultProps = {
Expand All @@ -1235,5 +1244,6 @@ CodeEditor.defaultProps = {
enableMarkdownLint: DEFAULT_CONFIG.editor.enableMarkdownLint,
customMarkdownLintConfig: DEFAULT_CONFIG.editor.customMarkdownLintConfig,
prettierConfig: DEFAULT_CONFIG.editor.prettierConfig,
deleteUnusedAttachments: DEFAULT_CONFIG.editor.deleteUnusedAttachments
deleteUnusedAttachments: DEFAULT_CONFIG.editor.deleteUnusedAttachments,
backgroundPath: DEFAULT_CONFIG.editor.backgroundPath
}
1 change: 1 addition & 0 deletions browser/components/MarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class MarkdownEditor extends React.Component {
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
prettierConfig={config.editor.prettierConfig}
deleteUnusedAttachments={config.editor.deleteUnusedAttachments}
backgroundPath={config.editor.backgroundPath}
/>
<MarkdownPreview styleName={this.state.status === 'PREVIEW'
? 'preview'
Expand Down
1 change: 1 addition & 0 deletions browser/components/MarkdownSplitEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class MarkdownSplitEditor extends React.Component {
enableMarkdownLint={config.editor.enableMarkdownLint}
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
deleteUnusedAttachments={config.editor.deleteUnusedAttachments}
backgroundPath={config.editor.backgroundPath}
/>
<div styleName='slider' style={{left: this.state.codeEditorWidthInPercent + '%'}} onMouseDown={e => this.handleMouseDown(e)} >
<div styleName='slider-hitbox' />
Expand Down
9 changes: 9 additions & 0 deletions browser/lib/normalizeBackgroundImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import isString from 'lodash/isString'

export default function normalizeBackgroundImage (backgroundPath) {
const defaultEditorBackground = 'none'
let value = isString(backgroundPath) && backgroundPath.trim().length > 0
? 'url(' + backgroundPath + ')'
: defaultEditorBackground
return value
}
5 changes: 5 additions & 0 deletions browser/main/global.styl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ body[data-theme="dark"]
font-family inherit !important
line-height 1.4em
height 100%
&.CodeMirror-wrap
background-blend-mode overlay
background-repeat no-repeat
background-position center
background-size cover
.CodeMirror > div > textarea
margin-bottom -1em
.CodeMirror-focused .CodeMirror-selected
Expand Down
3 changes: 2 additions & 1 deletion browser/main/lib/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export const DEFAULT_CONFIG = {
"semi": false,
"singleQuote": true
}`,
deleteUnusedAttachments: true
deleteUnusedAttachments: true,
backgroundPath: ''
},
preview: {
fontSize: '14',
Expand Down
3 changes: 3 additions & 0 deletions browser/main/modals/PreferencesModal/ConfigTab.styl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
.note-for-keymap
font-size: 12px

.note-for-backgroundImage
font-size: 12px

.code-mirror
width 400px
height 120px
Expand Down
16 changes: 15 additions & 1 deletion browser/main/modals/PreferencesModal/UiTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class UiTab extends React.Component {
enableMarkdownLint: this.refs.enableMarkdownLint.checked,
customMarkdownLintConfig: this.customMarkdownLintConfigCM.getCodeMirror().getValue(),
prettierConfig: this.prettierConfigCM.getCodeMirror().getValue(),
deleteUnusedAttachments: this.refs.deleteUnusedAttachments.checked
deleteUnusedAttachments: this.refs.deleteUnusedAttachments.checked,
backgroundPath: this.refs.customBackgroundPathEditor.value
},
preview: {
fontSize: this.refs.previewFontSize.value,
Expand Down Expand Up @@ -698,6 +699,19 @@ class UiTab extends React.Component {
</div>
</div>
</div>
<div styleName='group-section'>
<div styleName='group-section-label'>
{i18n.__('Custom Background - Editor')}
</div>
<div styleName='group-section-control'>
<input styleName='group-section-control-input'
ref='customBackgroundPathEditor'
value={config.editor.backgroundPath}
onChange={(e) => this.handleUIChange(e)}
type='text'
/>
</div>
</div>

<div styleName='group-header2'>{i18n.__('Preview')}</div>
<div styleName='group-section'>
Expand Down
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"default": "default",
"vim": "vim",
"emacs": "emacs",
"Custom CSS": "Custom CSS",
"Custom Background - Editor": "Custom Background - Editor",
"⚠️ Please restart boostnote after you change the keymap": "⚠️ Please restart boostnote after you change the keymap",
"Show line numbers in the editor": "Show line numbers in the editor",
"Allow editor to scroll past the last line": "Allow editor to scroll past the last line",
Expand Down
1 change: 1 addition & 0 deletions locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"default": "預設",
"vim": "vim",
"emacs": "emacs",
"Custom Background - Editor": "自訂背景 - 文字編輯器",
"⚠️ Please restart boostnote after you change the keymap": "⚠️ 修改鍵盤配置請重新開啟 Boostnote ",
"Show line numbers in the editor": "在編輯器中顯示行號",
"Allow editor to scroll past the last line": "允許編輯器捲軸捲動超過最後一行",
Expand Down