Skip to content
Open
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
10 changes: 10 additions & 0 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,24 @@ export default class CodeEditor extends React.Component {
leading: false,
trailing: true
})
this.state = {
editorFocused: false
}
this.changeHandler = (editor, changeObject) =>
this.handleChange(editor, changeObject)
this.highlightHandler = (editor, changeObject) =>
this.handleHighlight(editor, changeObject)
this.focusHandler = () => {
ipcRenderer.send('editor:focused', true)
this.setState({ editorFocused: true })
}
const debouncedDeletionOfAttachments = _.debounce(
attachmentManagement.deleteAttachmentsNotPresentInNote,
30000
)
this.blurHandler = (editor, e) => {
ipcRenderer.send('editor:focused', false)
this.setState({ editorFocused: false })
if (e == null) return null
let el = e.relatedTarget
while (el != null) {
Expand Down Expand Up @@ -580,6 +585,11 @@ export default class CodeEditor extends React.Component {
if (prevProps.keyMap !== this.props.keyMap) {
needRefresh = true
}
const { editorFocused } = this.state
const { value } = this.props
if (prevProps.value !== value && !editorFocused) {
this.editor.setValue(this.props.value)
}
if (prevProps.RTL !== this.props.RTL) {
this.editor.setOption('direction', this.props.RTL ? 'rtl' : 'ltr')
this.editor.setOption('rtlMoveVisually', this.props.RTL)
Expand Down
7 changes: 1 addition & 6 deletions browser/components/MarkdownPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,9 +1224,4 @@ MarkdownPreview.propTypes = {
breaks: PropTypes.bool
}

export default connect(
null,
null,
null,
{ forwardRef: true }
)(MarkdownPreview)
export default connect(null, null, null, { forwardRef: true })(MarkdownPreview)
16 changes: 4 additions & 12 deletions browser/lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ class Markdown {
flowchart: token => {
return `<pre class="fence" data-line="${token.map[0]}">
<span class="filename">${token.fileName}</span>
<div class="flowchart" data-height="${token.parameters.height}">${
token.content
}</div>
<div class="flowchart" data-height="${token.parameters.height}">${token.content}</div>
</pre>`
},
gallery: token => {
Expand All @@ -299,25 +297,19 @@ class Markdown {

return `<pre class="fence" data-line="${token.map[0]}">
<span class="filename">${token.fileName}</span>
<div class="gallery" data-autoplay="${
token.parameters.autoplay
}" data-height="${token.parameters.height}">${content}</div>
<div class="gallery" data-autoplay="${token.parameters.autoplay}" data-height="${token.parameters.height}">${content}</div>
</pre>`
},
mermaid: token => {
return `<pre class="fence" data-line="${token.map[0]}">
<span class="filename">${token.fileName}</span>
<div class="mermaid" data-height="${token.parameters.height}">${
token.content
}</div>
<div class="mermaid" data-height="${token.parameters.height}">${token.content}</div>
</pre>`
},
sequence: token => {
return `<pre class="fence" data-line="${token.map[0]}">
<span class="filename">${token.fileName}</span>
<div class="sequence" data-height="${token.parameters.height}">${
token.content
}</div>
<div class="sequence" data-height="${token.parameters.height}">${token.content}</div>
</pre>`
}
},
Expand Down
25 changes: 24 additions & 1 deletion browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { confirmDeleteNote } from 'browser/lib/confirmDeleteNote'
import markdownToc from 'browser/lib/markdown-toc-generator'
import queryString from 'query-string'
import { replace } from 'connected-react-router'
import { ipcRenderer } from 'electron'
import ToggleDirectionButton from 'browser/main/Detail/ToggleDirectionButton'

class MarkdownNoteDetail extends React.Component {
Expand All @@ -58,6 +59,15 @@ class MarkdownNoteDetail extends React.Component {
this.dispatchTimer = null

this.toggleLockButton = this.handleToggleLockButton.bind(this)
const { showFullScreen } = this.props.data

if (showFullScreen !== false) {
// Main window, check for updates from children
ipcRenderer.on('update-note-state', (_, noteData) => {
const { note } = this.state
if (noteData.key === note.key) this.setState({ note: noteData })
})
}
this.generateToc = this.handleGenerateToc.bind(this)
this.handleUpdateContent = this.handleUpdateContent.bind(this)
}
Expand Down Expand Up @@ -163,6 +173,11 @@ class MarkdownNoteDetail extends React.Component {
type: 'UPDATE_NOTE',
note: note
})
const { showFullScreen } = this.props.data
if (showFullScreen === false) {
// Window is not main window, send update event to main window
ipcRenderer.send('update-note-state', note)
}
AwsMobileAnalyticsConfig.recordDynamicCustomEvent('EDIT_NOTE')
})
}
Expand Down Expand Up @@ -470,6 +485,12 @@ class MarkdownNoteDetail extends React.Component {
const storageKey = note.storage
const folderKey = note.folder

let renderFullScreenButton = true
const { showFullScreen } = this.props.data
if (showFullScreen === false) {
renderFullScreenButton = false
}

const options = []
data.storageMap.forEach((storage, index) => {
storage.folders.forEach(folder => {
Expand Down Expand Up @@ -578,7 +599,9 @@ class MarkdownNoteDetail extends React.Component {
return this.state.isLockButtonShown ? lockButtonComponent : ''
})()}

<FullscreenButton onClick={e => this.handleFullScreenButton(e)} />
{renderFullScreenButton ? (
<FullscreenButton onClick={e => this.handleFullScreenButton(e)} />
) : null}

<TrashButton onClick={e => this.handleTrashButtonClick(e)} />

Expand Down
26 changes: 25 additions & 1 deletion browser/main/Detail/SnippetNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { replace } from 'connected-react-router'

const electron = require('electron')
const { remote } = electron
const { ipcRenderer } = electron
const { dialog } = remote

class SnippetNoteDetail extends React.Component {
Expand Down Expand Up @@ -61,6 +62,16 @@ class SnippetNoteDetail extends React.Component {

this.scrollToNextTabThreshold = 0.7
this.generateToc = () => this.handleGenerateToc()

const { showFullScreen } = this.props.data

if (showFullScreen !== false) {
// Main window, check for updates from children
ipcRenderer.on('update-note-state', (_, noteData) => {
const { note } = this.state
if (noteData.key === note.key) this.setState({ note: noteData })
})
}
}

componentDidMount() {
Expand Down Expand Up @@ -162,6 +173,11 @@ class SnippetNoteDetail extends React.Component {
type: 'UPDATE_NOTE',
note: note
})
const { showFullScreen } = this.props.data
if (showFullScreen === false) {
// Window is not main window, send update event to main window
ipcRenderer.send('update-note-state', note)
}
AwsMobileAnalyticsConfig.recordDynamicCustomEvent('EDIT_NOTE')
})
}
Expand Down Expand Up @@ -796,6 +812,12 @@ class SnippetNoteDetail extends React.Component {
const storageKey = note.storage
const folderKey = note.folder

let renderFullScreenButton = true
const { showFullScreen } = this.props.data
if (showFullScreen === false) {
renderFullScreenButton = false
}

const autoDetect = config.editor.snippetDefaultLanguage === 'Auto Detect'

let editorFontSize = parseInt(config.editor.fontSize, 10)
Expand Down Expand Up @@ -950,7 +972,9 @@ class SnippetNoteDetail extends React.Component {
isActive={note.isStarred}
/>

<FullscreenButton onClick={e => this.handleFullScreenButton(e)} />
{renderFullScreenButton ? (
<FullscreenButton onClick={e => this.handleFullScreenButton(e)} />
) : null}

<TrashButton onClick={e => this.handleTrashButtonClick(e)} />

Expand Down
31 changes: 28 additions & 3 deletions browser/main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { push } from 'connected-react-router'

const path = require('path')
const electron = require('electron')
const { remote } = electron
const { remote, ipcRenderer } = electron

class Main extends React.Component {
constructor(props) {
Expand All @@ -40,9 +40,15 @@ class Main extends React.Component {
isLeftSliderFocused: false,
fullScreen: false,
noteDetailWidth: 0,
mainBodyWidth: 0
mainBodyWidth: 0,
isMainWindow: true
}

ipcRenderer.on('set-current-note', (_, result) => {
this.setState({ isMainWindow: false })
this.setState({ currentNoteKey: result.key })
})

this.toggleFullScreen = () => this.handleFullScreenButton()
}

Expand Down Expand Up @@ -320,7 +326,26 @@ class Main extends React.Component {

render() {
const { config } = this.props

if (!this.state.isMainWindow) {
const detailProps = _.pick(this.props, [
'dispatch',
'data',
'config',
'match',
'location'
])

detailProps.location.search = `?key=${this.state.currentNoteKey}`
detailProps.data.showFullScreen = false

return (
<Detail
style={{ left: 0 }}
{...detailProps}
ignorePreviewPointerEvents={this.state.isRightSliderFocused}
/>
)
}
// the width of the navigation bar when it is folded/collapsed
const foldedNavigationWidth = 44

Expand Down
20 changes: 20 additions & 0 deletions browser/main/NoteList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import i18n from 'browser/lib/i18n'
import { confirmDeleteNote } from 'browser/lib/confirmDeleteNote'
import context from 'browser/lib/context'
import queryString from 'query-string'
import { ipcRenderer } from 'electron'

const { remote } = require('electron')
const { dialog } = remote
const WP_POST_PATH = '/wp/v2/posts'
const singleNoteWindow = require('../../../lib/note-window')

const regexMatchStartingTitleNumber = new RegExp('^([0-9]*.?[0-9]+).*$')

Expand Down Expand Up @@ -654,6 +656,7 @@ class NoteList extends React.Component {
const publishLabel = i18n.__('Publish Blog')
const updateLabel = i18n.__('Update Blog')
const openBlogLabel = i18n.__('Open Blog')
const openInNewWindow = i18n.__('Open in new window')

const templates = []

Expand All @@ -675,6 +678,7 @@ class NoteList extends React.Component {
click: this.pinToTop
})
}

templates.push(
{
label: deleteLabel,
Expand All @@ -687,8 +691,13 @@ class NoteList extends React.Component {
{
label: copyNoteLink,
click: this.copyNoteLink.bind(this, note)
},
{
label: openInNewWindow,
click: this.openInNewWindow.bind(this, note)
}
)

if (note.type === 'MARKDOWN_NOTE') {
if (note.blog && note.blog.blogLink && note.blog.blogId) {
templates.push(
Expand All @@ -712,6 +721,17 @@ class NoteList extends React.Component {
context.popup(templates)
}

openInNewWindow(note) {
const { dispatch } = this.props
singleNoteWindow.createNewWindow(window.boostnoteBasePath, note)
ipcRenderer.on('update-note-state', (_, noteData) => {
dispatch({
type: 'UPDATE_NOTE',
note: noteData
})
})
}

updateSelectedNotes(updateFunc, cleanSelection = true) {
const { selectedNoteKeys } = this.state
const { dispatch } = this.props
Expand Down
5 changes: 1 addition & 4 deletions browser/main/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,7 @@ const store = createStore(
reducer,
undefined,
process.env.NODE_ENV === 'development'
? compose(
applyMiddleware(routerMiddleware(history)),
DevTools.instrument()
)
? compose(applyMiddleware(routerMiddleware(history)), DevTools.instrument())
: applyMiddleware(routerMiddleware(history))
)

Expand Down
8 changes: 8 additions & 0 deletions lib/main-window.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const { ipcMain } = electron
const path = require('path')
const Config = require('electron-config')
const config = new Config()
Expand Down Expand Up @@ -63,6 +64,9 @@ const url = path.resolve(

mainWindow.loadURL('file://' + url)
mainWindow.setMenuBarVisibility(false)
mainWindow.webContents.executeJavaScript(
`window.boostnoteBasePath = '${__dirname}';`
)

mainWindow.webContents.on('new-window', function(e) {
e.preventDefault()
Expand Down Expand Up @@ -108,6 +112,10 @@ function storeWindowSize() {
}
}

ipcMain.on('update-note-state', (_, currentNote) => {
mainWindow.webContents.send('update-note-state', currentNote)
})

app.on('activate', function() {
if (mainWindow == null) return null
mainWindow.show()
Expand Down
Loading