Skip to content
Merged
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
3 changes: 3 additions & 0 deletions browser/components/MarkdownPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ export default class MarkdownPreview extends React.Component {
}

handleContextMenu (e) {
if (!this.props.onContextMenu) return
this.props.onContextMenu(e)
}

handleMouseDown (e) {
if (!this.props.onMouseDown) return
if (e.target != null) {
switch (e.target.tagName) {
case 'A':
Expand All @@ -159,6 +161,7 @@ export default class MarkdownPreview extends React.Component {
}

handleMouseUp (e) {
if (!this.props.onMouseUp) return
if (e.target != null && e.target.tagName === 'A') {
return null
}
Expand Down
87 changes: 87 additions & 0 deletions browser/components/MarkdownSplitEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react'
import CodeEditor from 'browser/components/CodeEditor'
import MarkdownPreview from 'browser/components/MarkdownPreview'
import { findStorage } from 'browser/lib/findStorage'

import styles from './MarkdownSplitEditor.styl'
import CSSModules from 'browser/lib/CSSModules'

class MarkdownSplitEditor extends React.Component {
constructor (props) {
super(props)
this.value = props.value
this.focus = () => this.refs.code.focus()
this.reload = () => this.refs.code.reload()
}

handleOnChange () {
this.value = this.refs.code.value
this.props.onChange()
}

handleCheckboxClick (e) {
e.preventDefault()
e.stopPropagation()
const idMatch = /checkbox-([0-9]+)/
const checkedMatch = /\[x\]/i
const uncheckedMatch = /\[ \]/
if (idMatch.test(e.target.getAttribute('id'))) {
const lineIndex = parseInt(e.target.getAttribute('id').match(idMatch)[1], 10) - 1
const lines = this.refs.code.value
.split('\n')

const targetLine = lines[lineIndex]

if (targetLine.match(checkedMatch)) {
lines[lineIndex] = targetLine.replace(checkedMatch, '[ ]')
}
if (targetLine.match(uncheckedMatch)) {
lines[lineIndex] = targetLine.replace(uncheckedMatch, '[x]')
}
this.refs.code.setValue(lines.join('\n'))
}
}

render () {
const { config, value, storageKey } = this.props
const storage = findStorage(storageKey)
const previewStyle = {}
if (this.props.ignorePreviewPointerEvents) previewStyle.pointerEvents = 'none'
return (
<div styleName='root'>
<CodeEditor
styleName='codeEditor'
ref='code'
mode='GitHub Flavored Markdown'
value={value}
theme={config.editor.theme}
keyMap={config.editor.keyMap}
fontFamily={config.editor.fontFamily}
indentType={config.editor.indentType}
scrollPastEnd={config.editor.scrollPastEnd}
storageKey={storageKey}
onChange={this.handleOnChange.bind(this)}
/>
<MarkdownPreview
style={previewStyle}
styleName='preview'
theme={config.ui.theme}
keyMap={config.editor.keyMap}
fontSize={config.preview.fontSize}
fontFamily={config.preview.fontFamily}
codeBlockTheme={config.preview.codeBlockTheme}
codeBlockFontFamily={config.editor.fontFamily}
lineNumber={config.preview.lineNumber}
ref='preview'
tabInde='0'
value={value}
onCheckboxClick={(e) => this.handleCheckboxClick(e)}
showCopyNotification={config.ui.showCopyNotification}
storagePath={storage.path}
/>
</div>
)
}
}

export default CSSModules(MarkdownSplitEditor, styles)
9 changes: 9 additions & 0 deletions browser/components/MarkdownSplitEditor.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.root
width 100%
height 100%
font-size 30px
display flex
.codeEditor
width 50%
.preview
width 50%
4 changes: 3 additions & 1 deletion browser/components/markdown.styl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ hr
margin 15px 0
h1, h2, h3, h4, h5, h6
font-weight bold
word-wrap break-word
h1
font-size 2.55em
padding-bottom 0.3em
Expand Down Expand Up @@ -157,6 +158,7 @@ p
line-height 1.6em
margin 0 0 1em
white-space pre-line
word-wrap break-word
img
max-width 100%
strong, b
Expand Down Expand Up @@ -338,4 +340,4 @@ body[data-theme="dark"]
body[data-theme="solarized-dark"]
color $ui-solarized-dark-text-color
border-color themeDarkBorder
background-color $ui-solarized-dark-noteDetail-backgroundColor
background-color $ui-solarized-dark-noteDetail-backgroundColor
64 changes: 46 additions & 18 deletions browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
import CSSModules from 'browser/lib/CSSModules'
import styles from './MarkdownNoteDetail.styl'
import MarkdownEditor from 'browser/components/MarkdownEditor'
import MarkdownSplitEditor from 'browser/components/MarkdownSplitEditor'
import TodoListPercentage from 'browser/components/TodoListPercentage'
import StarButton from './StarButton'
import TagSelect from './TagSelect'
Expand All @@ -15,6 +16,7 @@ import StatusBar from '../StatusBar'
import _ from 'lodash'
import { findNoteTitle } from 'browser/lib/findNoteTitle'
import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig'
import ConfigManager from 'browser/main/lib/ConfigManager'
import TrashButton from './TrashButton'
import PermanentDeleteButton from './PermanentDeleteButton'
import InfoButton from './InfoButton'
Expand All @@ -39,7 +41,8 @@ class MarkdownNoteDetail extends React.Component {
content: ''
}, props.note),
isLockButtonShown: false,
isLocked: false
isLocked: false,
editorType: props.config.editor.type
}
this.dispatchTimer = null

Expand Down Expand Up @@ -233,7 +236,7 @@ class MarkdownNoteDetail extends React.Component {
}

getToggleLockButton () {
return this.state.isLocked ? '../resources/icon/icon-edit-lock.svg' : '../resources/icon/icon-edit.svg'
return this.state.isLocked ? '../resources/icon/icon-previewoff-on.svg' : '../resources/icon/icon-previewoff-off.svg'
}

handleDeleteKeyDown (e) {
Expand Down Expand Up @@ -262,9 +265,42 @@ class MarkdownNoteDetail extends React.Component {
ee.emit('print')
}

render () {
const { data, config, location } = this.props
handleSwitchMode (type) {
this.setState({ editorType: type }, () => {
const newConfig = Object.assign({}, this.props.config)
newConfig.editor.type = type
ConfigManager.set(newConfig)
})
}

renderEditor () {
const { config, ignorePreviewPointerEvents } = this.props
const { note } = this.state
if (this.state.editorType === 'EDITOR_PREVIEW') {
return <MarkdownEditor
ref='content'
styleName='body-noteEditor'
config={config}
value={note.content}
storageKey={note.storage}
onChange={(e) => this.handleChange(e)}
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
/>
} else {
return <MarkdownSplitEditor
ref='content'
config={config}
value={note.content}
storageKey={note.storage}
onChange={(e) => this.handleChange(e)}
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
/>
}
}

render () {
const { data, location } = this.props
const { note, editorType } = this.state
const storageKey = note.storage
const folderKey = note.folder

Expand Down Expand Up @@ -320,11 +356,11 @@ class MarkdownNoteDetail extends React.Component {
/>

<div styleName='mode-tab'>
<div styleName='active'>
<img styleName='item-star' src='../resources/icon/icon-WYSIWYG-on.svg' />
<div styleName={editorType === 'SPLIT' ? 'active' : 'non-active'} onClick={() => this.handleSwitchMode('SPLIT')}>
<img styleName='item-star' src='../resources/icon/icon-mode-split-on.svg' />
</div>
<div>
<img styleName='item-star' src='../resources/icon/icon-code-off.svg' />
<div styleName={editorType === 'EDITOR_PREVIEW' ? 'active' : 'non-active'} onClick={() => this.handleSwitchMode('EDITOR_PREVIEW')}>
<img styleName='item-star' src='../resources/icon/icon-mode-markdown-off.svg' />
</div>
</div>

Expand Down Expand Up @@ -360,7 +396,7 @@ class MarkdownNoteDetail extends React.Component {
<button styleName='control-fullScreenButton'
onMouseDown={(e) => this.handleFullScreenButton(e)}
>
<img styleName='iconInfo' src='../resources/icon/icon-sidebar.svg' />
<img styleName='iconInfo' src='../resources/icon/icon-full.svg' />
</button>

<TrashButton onClick={(e) => this.handleTrashButtonClick(e)} />
Expand Down Expand Up @@ -390,15 +426,7 @@ class MarkdownNoteDetail extends React.Component {
{location.pathname === '/trashed' ? trashTopBar : detailTopBar}

<div styleName='body'>
<MarkdownEditor
ref='content'
styleName='body-noteEditor'
config={config}
value={this.state.note.content}
storageKey={this.state.note.storage}
onChange={(e) => this.handleChange(e)}
ignorePreviewPointerEvents={this.props.ignorePreviewPointerEvents}
/>
{this.renderEditor()}
</div>

<StatusBar
Expand Down
2 changes: 0 additions & 2 deletions browser/main/Detail/MarkdownNoteDetail.styl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
cursor pointer
&:first-child
border-right 1px solid #eee
img
transform scale(0.7)
.active
background-color #fff
box-shadow 2px 0px 7px #eee
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 @@ -35,7 +35,8 @@ export const DEFAULT_CONFIG = {
indentType: 'space',
indentSize: '2',
switchPreview: 'BLUR', // Available value: RIGHTCLICK, BLUR
scrollPastEnd: false
scrollPastEnd: false,
type: 'SPLIT'
},
preview: {
fontSize: '14',
Expand Down
27 changes: 0 additions & 27 deletions resources/icon/icon-WYSIWYG-off.svg

This file was deleted.

16 changes: 0 additions & 16 deletions resources/icon/icon-WYSIWYG-on.svg

This file was deleted.

21 changes: 16 additions & 5 deletions resources/icon/icon-edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions resources/icon/icon-full.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading