Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4242e0d
Add missing translation for zh-tw
opw0011 Oct 13, 2018
28007a3
Add missing translation for zh-cn
opw0011 Oct 13, 2018
43bd0b0
Merge branch 'master' of https://github.com/BoostIO/Boostnote
ZeroX-DG Oct 18, 2018
7fb1a06
Add ~ and _ to autoclosing brackets
danmou Oct 27, 2018
d6fe0df
Add ~ and _ to autoclosing brackets
danmou Oct 27, 2018
817b74c
Update locales/zh-TW.json
IvanIFChen Nov 11, 2018
0904c62
Update locales/zh-CN.json
IvanIFChen Nov 11, 2018
e4a6ff4
Merge branch 'master' of https://github.com/ZeroX-DG/Boostnote
ZeroX-DG Nov 30, 2018
2ccb541
Merge branch 'master' of https://github.com/BoostIO/Boostnote
ZeroX-DG Nov 30, 2018
7c1cd50
Add structure for exporting PDFs
AgentEpsilon Dec 3, 2018
c1deeaf
Added PDF error to SnippetNoteDetail
AgentEpsilon Dec 3, 2018
33d0a9d
extract html contentformatter
AgentEpsilon Dec 3, 2018
0a7fd02
Use promises for outputFormatter
AgentEpsilon Dec 3, 2018
660a278
Generate PDF through an Electron BrowserWindow
AgentEpsilon Dec 3, 2018
dceed7d
Fixes exportFolder by making it actually wait for each exportNote
AgentEpsilon Dec 3, 2018
ce9f76f
fixed code style error
AgentEpsilon Dec 3, 2018
b546b9c
InfoPanel automatically adjusts its width
AgentEpsilon Dec 3, 2018
a095e8b
Merge branch 'master' of https://github.com/BoostIO/Boostnote
ZeroX-DG Dec 10, 2018
b5763ec
Merge branch 'master' of https://github.com/BoostIO/Boostnote
ZeroX-DG Dec 15, 2018
9ad0f58
Merge branch 'master' of https://github.com/BoostIO/Boostnote
ZeroX-DG Jan 6, 2019
c6c5e33
Merge branch 'master' of https://github.com/BoostIO/Boostnote
ZeroX-DG Jan 11, 2019
a7ad56b
Merge branch 'master' of https://github.com/BoostIO/Boostnote
ZeroX-DG Jan 19, 2019
a2e050b
added jump to line on click preview
ZeroX-DG Jan 19, 2019
5d38937
scroll selected line to middle of the editor
ZeroX-DG Jan 22, 2019
5920b35
Merge branch 'master' into zh-locale
opw0011 Jan 27, 2019
d144a58
fix for issue #2859: Cloning a note will now also copy the properties…
Feb 6, 2019
4d727b0
destroy window after printing
AgentEpsilon Feb 11, 2019
bc24acd
add targetDir parameter to outputFormatter
AgentEpsilon Feb 11, 2019
177888b
disable webSecurity to render files to pdf
AgentEpsilon Feb 11, 2019
2977504
Merge branch 'master' into patch-1
danmou Mar 4, 2019
1162443
Add ~ and _ to autoclosing brackets
danmou Mar 4, 2019
2a0906d
Rehid printout BrowserWindow
AgentEpsilon Mar 18, 2019
46ecf0a
Merge pull request #2868 from dredav/issue-2859
Rokt33r Mar 20, 2019
bbbbe9a
Merge pull request #2493 from opw0011/zh-locale
Rokt33r Mar 20, 2019
9f13645
Merge pull request #2545 from Danmou/patch-1
Rokt33r Mar 20, 2019
2b29d96
Merge pull request #2678 from AgentEpsilon/export-pdf
Rokt33r Mar 20, 2019
3f7f0e6
Merge pull request #2819 from ZeroX-DG/feature/edit-from-preview
Rokt33r Mar 20, 2019
b5b56f7
Refactor code editor by moving the expand snippet out to a separate f…
ZeroX-DG Mar 20, 2019
bff081a
fixed copy button (#2914)
ZeroX-DG Mar 20, 2019
fee9669
Fix wrong binding (#2940)
Rokt33r Mar 22, 2019
2f00cec
Upgrade Travis CI node and npm versions
serima Mar 16, 2019
70e57cf
jumpNoteByHashHandler will now try to find the location for the note …
dredav Mar 21, 2019
91d04b9
change filter function to find, find will match the first note with r…
dredav Mar 22, 2019
5b99132
Adjust find function
ZeroX-DG Mar 23, 2019
22d494d
README: removed mobile app mention (#2828)
mxschmitt Feb 24, 2019
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: node_js
node_js:
- 7
- 8
script:
- npm run lint && npm run test
- yarn jest
- 'if [[ ${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} = "master" ]]; then npm install -g grunt npm@5.2 && grunt pre-build; fi'
- 'if [[ ${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} = "master" ]]; then npm install -g grunt npm@6.4 && grunt pre-build; fi'
after_success:
- openssl aes-256-cbc -K $encrypted_440d7f9a3c38_key -iv $encrypted_440d7f9a3c38_iv
-in .snapcraft/travis_snapcraft.cfg -out .snapcraft/snapcraft.cfg -d
Expand Down
177 changes: 18 additions & 159 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ import {
import TextEditorInterface from 'browser/lib/TextEditorInterface'
import eventEmitter from 'browser/main/lib/eventEmitter'
import iconv from 'iconv-lite'
import crypto from 'crypto'
import consts from 'browser/lib/consts'
import styles from '../components/CodeEditor.styl'
import fs from 'fs'
const { ipcRenderer, remote, clipboard } = require('electron')
import normalizeEditorFontFamily from 'browser/lib/normalizeEditorFontFamily'
const spellcheck = require('browser/lib/spellcheck')
const buildEditorContextMenu = require('browser/lib/contextMenuBuilder')
import TurndownService from 'turndown'
import {
gfm
} from 'turndown-plugin-gfm'
import {languageMaps} from '../lib/CMLanguageList'
import snippetManager from '../lib/SnippetManager'

CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'

Expand All @@ -38,85 +34,6 @@ function translateHotkey (hotkey) {
return hotkey.replace(/\s*\+\s*/g, '-').replace(/Command/g, 'Cmd').replace(/Control/g, 'Ctrl')
}

const languageMaps = {
brainfuck: 'Brainfuck',
cpp: 'C++',
cs: 'C#',
clojure: 'Clojure',
'clojure-repl': 'ClojureScript',
cmake: 'CMake',
coffeescript: 'CoffeeScript',
crystal: 'Crystal',
css: 'CSS',
d: 'D',
dart: 'Dart',
delphi: 'Pascal',
diff: 'Diff',
django: 'Django',
dockerfile: 'Dockerfile',
ebnf: 'EBNF',
elm: 'Elm',
erlang: 'Erlang',
'erlang-repl': 'Erlang',
fortran: 'Fortran',
fsharp: 'F#',
gherkin: 'Gherkin',
go: 'Go',
groovy: 'Groovy',
haml: 'HAML',
haskell: 'Haskell',
haxe: 'Haxe',
http: 'HTTP',
ini: 'toml',
java: 'Java',
javascript: 'JavaScript',
json: 'JSON',
julia: 'Julia',
kotlin: 'Kotlin',
less: 'LESS',
livescript: 'LiveScript',
lua: 'Lua',
markdown: 'Markdown',
mathematica: 'Mathematica',
nginx: 'Nginx',
nsis: 'NSIS',
objectivec: 'Objective-C',
ocaml: 'Ocaml',
perl: 'Perl',
php: 'PHP',
powershell: 'PowerShell',
properties: 'Properties files',
protobuf: 'ProtoBuf',
python: 'Python',
puppet: 'Puppet',
q: 'Q',
r: 'R',
ruby: 'Ruby',
rust: 'Rust',
sas: 'SAS',
scala: 'Scala',
scheme: 'Scheme',
scss: 'SCSS',
shell: 'Shell',
smalltalk: 'Smalltalk',
sml: 'SML',
sql: 'SQL',
stylus: 'Stylus',
swift: 'Swift',
tcl: 'Tcl',
tex: 'LaTex',
typescript: 'TypeScript',
twig: 'Twig',
vbnet: 'VB.NET',
vbscript: 'VBScript',
verilog: 'Verilog',
vhdl: 'VHDL',
xml: 'HTML',
xquery: 'XQuery',
yaml: 'YAML',
elixir: 'Elixir'
}

export default class CodeEditor extends React.Component {
constructor (props) {
super(props)
Expand Down Expand Up @@ -228,7 +145,8 @@ export default class CodeEditor extends React.Component {

updateDefaultKeyMap () {
const { hotkey } = this.props
const expandSnippet = this.expandSnippet.bind(this)
const self = this
const expandSnippet = snippetManager.expandSnippet

this.defaultKeyMap = CodeMirror.normalizeKeyMap({
Tab: function (cm) {
Expand All @@ -252,10 +170,12 @@ export default class CodeEditor extends React.Component {
cursor.ch > 1
) {
// text expansion on tab key if the char before is alphabet
const snippets = JSON.parse(
fs.readFileSync(consts.SNIPPET_FILE, 'utf8')
const wordBeforeCursor = self.getWordBeforeCursor(
line,
cursor.line,
cursor.ch
)
if (expandSnippet(line, cursor, cm, snippets) === false) {
if (expandSnippet(wordBeforeCursor, cursor, cm) === false) {
if (tabs) {
cm.execCommand('insertTab')
} else {
Expand Down Expand Up @@ -310,22 +230,7 @@ export default class CodeEditor extends React.Component {
const { rulers, enableRulers } = this.props
eventEmitter.on('line:jump', this.scrollToLineHandeler)

const defaultSnippet = [
{
id: crypto.randomBytes(16).toString('hex'),
name: 'Dummy text',
prefix: ['lorem', 'ipsum'],
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
}
]
if (!fs.existsSync(consts.SNIPPET_FILE)) {
fs.writeFileSync(
consts.SNIPPET_FILE,
JSON.stringify(defaultSnippet, null, 4),
'utf8'
)
}

snippetManager.init()
this.updateDefaultKeyMap()

this.value = this.props.value
Expand Down Expand Up @@ -520,61 +425,12 @@ export default class CodeEditor extends React.Component {
this.initialHighlighting()
}

expandSnippet (line, cursor, cm, snippets) {
const wordBeforeCursor = this.getWordBeforeCursor(
line,
cursor.line,
cursor.ch
)
const templateCursorString = ':{}'
for (let i = 0; i < snippets.length; i++) {
if (snippets[i].prefix.indexOf(wordBeforeCursor.text) !== -1) {
if (snippets[i].content.indexOf(templateCursorString) !== -1) {
const snippetLines = snippets[i].content.split('\n')
let cursorLineNumber = 0
let cursorLinePosition = 0

let cursorIndex
for (let j = 0; j < snippetLines.length; j++) {
cursorIndex = snippetLines[j].indexOf(templateCursorString)

if (cursorIndex !== -1) {
cursorLineNumber = j
cursorLinePosition = cursorIndex

break
}
}

cm.replaceRange(
snippets[i].content.replace(templateCursorString, ''),
wordBeforeCursor.range.from,
wordBeforeCursor.range.to
)
cm.setCursor({
line: cursor.line + cursorLineNumber,
ch: cursorLinePosition + cursor.ch - wordBeforeCursor.text.length
})
} else {
cm.replaceRange(
snippets[i].content,
wordBeforeCursor.range.from,
wordBeforeCursor.range.to
)
}
return true
}
}

return false
}

getWordBeforeCursor (line, lineNumber, cursorPosition) {
let wordBeforeCursor = ''
const originCursorPosition = cursorPosition
const emptyChars = /\t|\s|\r|\n/

// to prevent the word to expand is long that will crash the whole app
// to prevent the word is long that will crash the whole app
// the safeStop is there to stop user to expand words that longer than 20 chars
const safeStop = 20

Expand All @@ -584,7 +440,7 @@ export default class CodeEditor extends React.Component {
if (!emptyChars.test(currentChar)) {
wordBeforeCursor = currentChar + wordBeforeCursor
} else if (wordBeforeCursor.length >= safeStop) {
throw new Error('Your snippet trigger is too long !')
throw new Error('Stopped after 20 loops for safety reason !')
} else {
break
}
Expand Down Expand Up @@ -747,14 +603,14 @@ export default class CodeEditor extends React.Component {
}

incrementLines (start, linesAdded, linesRemoved, editor) {
let highlightedLines = editor.options.linesHighlighted
const highlightedLines = editor.options.linesHighlighted

const totalHighlightedLines = highlightedLines.length

let offset = linesAdded - linesRemoved
const offset = linesAdded - linesRemoved

// Store new items to be added as we're changing the lines
let newLines = []
const newLines = []

let i = totalHighlightedLines

Expand Down Expand Up @@ -835,6 +691,9 @@ export default class CodeEditor extends React.Component {
ch: 1
}
this.editor.setCursor(cursor)
const top = this.editor.charCoords({line: num, ch: 0}, 'local').top
const middleHeight = this.editor.getScrollerElement().offsetHeight / 2
this.editor.scrollTo(null, top - middleHeight - 5)
}

focus () {
Expand Down
10 changes: 10 additions & 0 deletions browser/components/MarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MarkdownEditor extends React.Component {
componentDidMount () {
this.value = this.refs.code.value
eventEmitter.on('editor:lock', this.lockEditorCode)
eventEmitter.on('editor:focus', this.focusEditor.bind(this))
}

componentDidUpdate () {
Expand All @@ -47,6 +48,15 @@ class MarkdownEditor extends React.Component {
componentWillUnmount () {
this.cancelQueue()
eventEmitter.off('editor:lock', this.lockEditorCode)
eventEmitter.off('editor:focus', this.focusEditor.bind(this))
}

focusEditor () {
this.setState({
status: 'CODE'
}, () => {
this.refs.code.focus()
})
}

queueRendering (value) {
Expand Down
Loading