mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 10:16:26 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fe83a0583 | ||
|
|
ce74e69480 | ||
|
|
ddea2aeb22 | ||
|
|
7bbe69cce9 | ||
|
|
e921e30d64 | ||
|
|
cd4f9d8bb4 | ||
|
|
a0553788b6 | ||
|
|
1a183d78af | ||
|
|
cabcaa892c | ||
|
|
01c9d62a2b | ||
|
|
ba76df863c | ||
|
|
81441a0895 | ||
|
|
da0222f213 | ||
|
|
fb8a2eb2e0 | ||
|
|
cde2e27e04 |
@@ -35,6 +35,41 @@ export default class CodeEditor extends React.Component {
|
||||
|
||||
if (this.props.onBlur) this.props.onBlur(e)
|
||||
}
|
||||
|
||||
this.killedBuffer = ''
|
||||
this.execHandler = (e) => {
|
||||
console.log(e.command.name)
|
||||
switch (e.command.name) {
|
||||
case 'gotolineend':
|
||||
e.preventDefault()
|
||||
let position = this.editor.getCursorPosition()
|
||||
this.editor.navigateTo(position.row, this.editor.getSession().getLine(position.row).length)
|
||||
break
|
||||
case 'removetolineend':
|
||||
e.preventDefault()
|
||||
let range = this.editor.getSelectionRange()
|
||||
let session = this.editor.getSession()
|
||||
if (range.isEmpty()) {
|
||||
range.setEnd(range.start.row, session.getLine(range.start.row).length)
|
||||
this.killedBuffer = session.getTextRange(range)
|
||||
if (this.killedBuffer.length > 0) {
|
||||
console.log('remove to lineend')
|
||||
session.remove(range)
|
||||
} else {
|
||||
if (session.getLength() === range.start.row) {
|
||||
return
|
||||
}
|
||||
range.setStart(range.start.row, range.end.col)
|
||||
range.setEnd(range.start.row + 1, 0)
|
||||
this.killedBuffer = '\n'
|
||||
session.remove(range)
|
||||
}
|
||||
} else {
|
||||
this.killedBuffer = session.getTextRange(range)
|
||||
session.remove(range)
|
||||
}
|
||||
}
|
||||
}
|
||||
this.afterExecHandler = (e) => {
|
||||
switch (e.command.name) {
|
||||
case 'find':
|
||||
@@ -42,6 +77,7 @@ export default class CodeEditor extends React.Component {
|
||||
el.removeEventListener('blur', this.blurHandler)
|
||||
el.addEventListener('blur', this.blurHandler)
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,15 +119,28 @@ export default class CodeEditor extends React.Component {
|
||||
},
|
||||
readOnly: true
|
||||
})
|
||||
editor.commands.addCommand({
|
||||
name: 'Emacs cursor up',
|
||||
bindKey: {mac: 'Ctrl-Y'},
|
||||
exec: function (editor) {
|
||||
editor.insert(this.killedBuffer)
|
||||
}.bind(this),
|
||||
readOnly: true
|
||||
})
|
||||
editor.commands.addCommand({
|
||||
name: 'Focus title',
|
||||
bindKey: {win: 'Esc', mac: 'Esc'},
|
||||
exec: function (editor, e) {
|
||||
remote.getCurrentWebContents().send('list-focus')
|
||||
let currentWindow = remote.getCurrentWebContents()
|
||||
if (config['switch-preview'] === 'rightclick') {
|
||||
currentWindow.send('detail-preview')
|
||||
}
|
||||
currentWindow.send('list-focus')
|
||||
},
|
||||
readOnly: true
|
||||
})
|
||||
|
||||
editor.commands.on('exec', this.execHandler)
|
||||
editor.commands.on('afterExec', this.afterExecHandler)
|
||||
|
||||
var session = editor.getSession()
|
||||
@@ -116,6 +165,7 @@ export default class CodeEditor extends React.Component {
|
||||
ipc.removeListener('config-apply', this.configApplyHandler)
|
||||
this.editor.getSession().removeListener('change', this.changeHandler)
|
||||
this.editor.removeListener('blur', this.blurHandler)
|
||||
this.editor.commands.removeListener('exec', this.execHandler)
|
||||
this.editor.commands.removeListener('afterExec', this.afterExecHandler)
|
||||
}
|
||||
|
||||
|
||||
@@ -49,13 +49,13 @@ const sanitizeOpts = {
|
||||
}
|
||||
|
||||
function handleAnchorClick (e) {
|
||||
if (e.target.attributes.href && e.target.attributes.href.nodeValue.match(/#.+/)) {
|
||||
if (this.attributes.href && this.attributes.href.nodeValue.match(/^#.+/)) {
|
||||
return
|
||||
}
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
let href = e.target.href
|
||||
if (href.match(/^http:\/\/|https:\/\/|mailto:\/\//)) {
|
||||
let href = this.href
|
||||
if (href && href.match(/^http:\/\/|https:\/\/|mailto:\/\//)) {
|
||||
shell.openExternal(href)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ export function emit (type, data = {}) {
|
||||
}
|
||||
|
||||
// Count ARTICLE_CREATE and ARTICLE_UPDATE again by syntax
|
||||
if ((type === 'ARTICLE_CREATE' || type === 'ARTICLE_UPDATE') && data.mode != null) {
|
||||
if (type === 'ARTICLE_UPDATE' && data.mode != null) {
|
||||
let recordKey = type + '_BY_SYNTAX'
|
||||
if (todayRecord[recordKey] == null) todayRecord[recordKey] = {}
|
||||
|
||||
|
||||
@@ -5,6 +5,17 @@ const jetpack = require('fs-jetpack')
|
||||
const userDataPath = remote.app.getPath('userData')
|
||||
const configFile = 'config.json'
|
||||
|
||||
export default function fetchConfig () {
|
||||
return Object.assign({}, JSON.parse(jetpack.cwd(userDataPath).read(configFile, 'utf-8')))
|
||||
const defaultConfig = {
|
||||
'editor-font-size': '14',
|
||||
'editor-font-family': 'Monaco, Consolas',
|
||||
'editor-indent-type': 'space',
|
||||
'editor-indent-size': '4',
|
||||
'preview-font-size': '14',
|
||||
'preview-font-family': 'Lato',
|
||||
'switch-preview': 'blur',
|
||||
'disable-direct-write': false
|
||||
}
|
||||
|
||||
export default function fetchConfig () {
|
||||
return Object.assign({}, defaultConfig, JSON.parse(jetpack.cwd(userDataPath).read(configFile, 'utf-8')))
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ var md = markdownit({
|
||||
return hljs.highlight(lang, str).value
|
||||
} catch (e) {}
|
||||
}
|
||||
return str
|
||||
return str.replace(/\&/g, '&').replace(/\</g, '<').replace(/\>/g, '>').replace(/\"/g, '"')
|
||||
}
|
||||
})
|
||||
md.use(emoji, {
|
||||
|
||||
@@ -32,7 +32,6 @@ export default class ArticleEditor extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
console.log(this.state.switchPreview)
|
||||
ipc.on('config-apply', this.configApplyHandler)
|
||||
}
|
||||
|
||||
@@ -65,6 +64,7 @@ export default class ArticleEditor extends React.Component {
|
||||
}
|
||||
|
||||
switchPreviewMode (isTemporary = false) {
|
||||
if (this.props.article.mode !== 'markdown') return true
|
||||
let cursorPosition = this.refs.editor.getCursorPosition()
|
||||
let firstVisibleRow = this.refs.editor.getFirstVisibleRow()
|
||||
this.setState({
|
||||
|
||||
@@ -4,10 +4,7 @@ import moment from 'moment'
|
||||
import _ from 'lodash'
|
||||
import {
|
||||
switchFolder,
|
||||
updateArticle,
|
||||
// cacheArticle,
|
||||
// saveArticle,
|
||||
// uncacheArticle
|
||||
updateArticle
|
||||
} from '../../actions'
|
||||
import linkState from 'browser/lib/linkState'
|
||||
import TagSelect from 'browser/components/TagSelect'
|
||||
@@ -19,22 +16,6 @@ import ArticleEditor from './ArticleEditor'
|
||||
const electron = require('electron')
|
||||
const ipc = electron.ipcRenderer
|
||||
|
||||
// const remote = electron.remote
|
||||
// const { Menu, MenuItem } = remote
|
||||
// const othersMenu = new Menu()
|
||||
// othersMenu.append(new MenuItem({
|
||||
// label: 'Delete Post',
|
||||
// click: function () {
|
||||
// remote.getCurrentWebContents().send('detail-delete')
|
||||
// }
|
||||
// }))
|
||||
// othersMenu.append(new MenuItem({
|
||||
// label: 'Discard Change',
|
||||
// click: function (item) {
|
||||
// remote.getCurrentWebContents().send('detail-uncache')
|
||||
// }
|
||||
// }))
|
||||
|
||||
const BRAND_COLOR = '#18AF90'
|
||||
const OSX = global.process.platform === 'darwin'
|
||||
|
||||
@@ -80,10 +61,6 @@ export default class ArticleDetail extends React.Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
|
||||
this.saveHandler = e => {
|
||||
if (isModalOpen()) return true
|
||||
this.handleSaveButtonClick()
|
||||
}
|
||||
this.deleteHandler = e => {
|
||||
if (isModalOpen()) return true
|
||||
this.handleDeleteButtonClick()
|
||||
@@ -102,6 +79,10 @@ export default class ArticleDetail extends React.Component {
|
||||
if (isModalOpen()) return true
|
||||
if (this.refs.editor) this.refs.editor.switchEditMode()
|
||||
}
|
||||
this.previewHandler = e => {
|
||||
if (isModalOpen()) return true
|
||||
if (this.refs.editor) this.refs.editor.switchPreviewMode()
|
||||
}
|
||||
|
||||
this.state = {
|
||||
article: Object.assign({content: ''}, props.activeArticle),
|
||||
@@ -115,21 +96,21 @@ export default class ArticleDetail extends React.Component {
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
// ipc.on('detail-save', this.saveHandler)
|
||||
ipc.on('detail-delete', this.deleteHandler)
|
||||
ipc.on('detail-uncache', this.uncacheHandler)
|
||||
ipc.on('detail-title', this.titleHandler)
|
||||
ipc.on('detail-edit', this.editHandler)
|
||||
ipc.on('detail-preview', this.previewHandler)
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
clearInterval(this.refreshTimer)
|
||||
|
||||
// ipc.removeListener('detail-save', this.saveHandler)
|
||||
ipc.removeListener('detail-delete', this.deleteHandler)
|
||||
ipc.removeListener('detail-uncache', this.uncacheHandler)
|
||||
ipc.removeListener('detail-title', this.titleHandler)
|
||||
ipc.removeListener('detail-edit', this.editHandler)
|
||||
ipc.removeListener('detail-preview', this.previewHandler)
|
||||
}
|
||||
|
||||
componentDidUpdate (prevProps, prevState) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import ExternalLink from 'browser/components/ExternalLink'
|
||||
import { setSearchFilter, clearSearch, toggleTutorial, saveArticle, switchFolder } from '../actions'
|
||||
import { isModalOpen } from 'browser/lib/modal'
|
||||
import keygen from 'browser/lib/keygen'
|
||||
import activityRecord from 'browser/lib/activityRecord'
|
||||
|
||||
const electron = require('electron')
|
||||
const remote = electron.remote
|
||||
@@ -167,6 +168,7 @@ export default class ArticleTopBar extends React.Component {
|
||||
dispatch(saveArticle(newArticle.key, newArticle, true))
|
||||
if (isFolderFilterApplied) dispatch(switchFolder(targetFolders[0].name))
|
||||
remote.getCurrentWebContents().send('detail-title')
|
||||
activityRecord.emit('ARTICLE_CREATE')
|
||||
}
|
||||
|
||||
handleTutorialButtonClick (e) {
|
||||
|
||||
@@ -26,6 +26,8 @@ marked()
|
||||
margin -5px
|
||||
transition .1s
|
||||
display inline-block
|
||||
img
|
||||
vertical-align sub
|
||||
&:hover
|
||||
color lighten(brandColor, 5%)
|
||||
text-decoration underline
|
||||
@@ -48,12 +50,12 @@ marked()
|
||||
*:not(a.lineAnchor) + h1, *:not(a.lineAnchor) + h2, *:not(a.lineAnchor) + h3, *:not(a.lineAnchor) + h4, *:not(a.lineAnchor) + h5, *:not(a.lineAnchor) + h6
|
||||
margin-top 25px
|
||||
h1
|
||||
font-size 2em
|
||||
font-size 1.8em
|
||||
border-bottom solid 2px borderColor
|
||||
line-height 2.333em
|
||||
line-height 2em
|
||||
h2
|
||||
font-size 1.66em
|
||||
line-height 2.07em
|
||||
line-height 1.8em
|
||||
h3
|
||||
font-size 1.33em
|
||||
line-height 1.6625em
|
||||
|
||||
@@ -6,6 +6,7 @@ const globalShortcut = electron.globalShortcut
|
||||
const jetpack = require('fs-jetpack')
|
||||
const mainWindow = require('./main-window')
|
||||
const nodeIpc = require('@rokt33r/node-ipc')
|
||||
const _ = require('lodash')
|
||||
|
||||
const OSX = global.process.platform === 'darwin'
|
||||
|
||||
@@ -73,28 +74,36 @@ function toggleMain () {
|
||||
// Init
|
||||
global.keymap = Object.assign({}, defaultKeymap, getKeymap())
|
||||
|
||||
function registerKey (name, callback, broadcast) {
|
||||
if (broadcast == null) broadcast = true
|
||||
|
||||
try {
|
||||
function registerKey (name, callback) {
|
||||
if (_.isString(global.keymap[name]) && global.keymap[name].trim().length > 0) {
|
||||
globalShortcut.register(global.keymap[name], callback)
|
||||
if (broadcast) {
|
||||
mainWindow.webContents.send('APP_SETTING_DONE', {})
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
if (broadcast) {
|
||||
mainWindow.webContents.send('APP_SETTING_ERROR', {
|
||||
message: 'Failed to apply hotkey: Invalid format'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function registerAllKeys (broadcast) {
|
||||
if (broadcast == null) broadcast = true
|
||||
registerKey('toggleFinder', toggleFinder, broadcast)
|
||||
registerKey('toggleMain', toggleMain, broadcast)
|
||||
|
||||
var errors = []
|
||||
try {
|
||||
registerKey('toggleFinder', toggleFinder)
|
||||
} catch (err) {
|
||||
errors.push('toggleFinder')
|
||||
}
|
||||
try {
|
||||
registerKey('toggleMain', toggleMain)
|
||||
} catch (err) {
|
||||
errors.push('toggleMain')
|
||||
}
|
||||
|
||||
if (broadcast) {
|
||||
if (errors.length === 0) {
|
||||
mainWindow.webContents.send('APP_SETTING_DONE', {})
|
||||
} else {
|
||||
mainWindow.webContents.send('APP_SETTING_ERROR', {
|
||||
message: 'Failed to apply hotkey: ' + errors.join(' ')
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerAllKeys(false)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "boost",
|
||||
"version": "0.5.2",
|
||||
"version": "0.5.4",
|
||||
"description": "Boostnote",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Submodule submodules/ace updated: 3fb55e8e37...e94cb3c7ff
Reference in New Issue
Block a user