1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

fix lint errors

This commit is contained in:
Baptiste Augrain
2018-08-20 20:29:10 +02:00
parent 657806c8cf
commit 7cf9dda821
4 changed files with 61 additions and 65 deletions

View File

@@ -5,7 +5,7 @@ import CodeMirror from 'codemirror'
import 'codemirror-mode-elixir' import 'codemirror-mode-elixir'
import attachmentManagement from 'browser/main/lib/dataApi/attachmentManagement' import attachmentManagement from 'browser/main/lib/dataApi/attachmentManagement'
import convertModeName from 'browser/lib/convertModeName' import convertModeName from 'browser/lib/convertModeName'
import { options, TableEditor } from '@susisu/mte-kernel' import { options, TableEditor, Alignment } from '@susisu/mte-kernel'
import TextEditorInterface from 'browser/lib/TextEditorInterface' import TextEditorInterface from 'browser/lib/TextEditorInterface'
import eventEmitter from 'browser/main/lib/eventEmitter' import eventEmitter from 'browser/main/lib/eventEmitter'
import iconv from 'iconv-lite' import iconv from 'iconv-lite'
@@ -143,7 +143,7 @@ export default class CodeEditor extends React.Component {
override: true override: true
} }
}) })
this.setMode(this.props.mode) this.setMode(this.props.mode)
this.editor.on('focus', this.focusHandler) this.editor.on('focus', this.focusHandler)
@@ -164,11 +164,11 @@ export default class CodeEditor extends React.Component {
CodeMirror.Vim.defineEx('qw', 'qw', this.quitEditor) CodeMirror.Vim.defineEx('qw', 'qw', this.quitEditor)
CodeMirror.Vim.map('ZZ', ':q', 'normal') CodeMirror.Vim.map('ZZ', ':q', 'normal')
this.setState({ isReady: true }) this.setState({ isReady: true })
const editorIntf = new TextEditorInterface(this.editor) const editorIntf = new TextEditorInterface(this.editor)
this.tableEditor = new TableEditor(editorIntf) this.tableEditor = new TableEditor(editorIntf)
eventEmitter.on('code:format-table', this.formatTable) eventEmitter.on('code:format-table', this.formatTable)
const defaultKeyMap = CodeMirror.normalizeKeyMap({ const defaultKeyMap = CodeMirror.normalizeKeyMap({
Tab: function (cm) { Tab: function (cm) {
const cursor = cm.getCursor() const cursor = cm.getCursor()
@@ -221,52 +221,52 @@ export default class CodeEditor extends React.Component {
return CodeMirror.Pass return CodeMirror.Pass
} }
}) })
if(this.props.enableTableEditor) { if (this.props.enableTableEditor) {
const opts = options({ const opts = options({
smartCursor: true smartCursor: true
}) })
const editorKeyMap = CodeMirror.normalizeKeyMap({ const editorKeyMap = CodeMirror.normalizeKeyMap({
'Tab' : () => { this.tableEditor.nextCell(opts) }, 'Tab': () => { this.tableEditor.nextCell(opts) },
'Shift-Tab' : () => { this.tableEditor.previousCell(opts) }, 'Shift-Tab': () => { this.tableEditor.previousCell(opts) },
'Enter' : () => { this.tableEditor.nextRow(opts) }, 'Enter': () => { this.tableEditor.nextRow(opts) },
'Ctrl-Enter' : () => { this.tableEditor.escape(opts) }, 'Ctrl-Enter': () => { this.tableEditor.escape(opts) },
'Cmd-Enter' : () => { this.tableEditor.escape(opts) }, 'Cmd-Enter': () => { this.tableEditor.escape(opts) },
'Shift-Ctrl-Left' : () => { this.tableEditor.alignColumn(Alignment.LEFT, opts) }, 'Shift-Ctrl-Left': () => { this.tableEditor.alignColumn(Alignment.LEFT, opts) },
'Shift-Cmd-Left' : () => { this.tableEditor.alignColumn(Alignment.LEFT, opts) }, 'Shift-Cmd-Left': () => { this.tableEditor.alignColumn(Alignment.LEFT, opts) },
'Shift-Ctrl-Right' : () => { this.tableEditor.alignColumn(Alignment.RIGHT, opts) }, 'Shift-Ctrl-Right': () => { this.tableEditor.alignColumn(Alignment.RIGHT, opts) },
'Shift-Cmd-Right' : () => { this.tableEditor.alignColumn(Alignment.RIGHT, opts) }, 'Shift-Cmd-Right': () => { this.tableEditor.alignColumn(Alignment.RIGHT, opts) },
'Shift-Ctrl-Up' : () => { this.tableEditor.alignColumn(Alignment.CENTER, opts) }, 'Shift-Ctrl-Up': () => { this.tableEditor.alignColumn(Alignment.CENTER, opts) },
'Shift-Cmd-Up' : () => { this.tableEditor.alignColumn(Alignment.CENTER, opts) }, 'Shift-Cmd-Up': () => { this.tableEditor.alignColumn(Alignment.CENTER, opts) },
'Shift-Ctrl-Down' : () => { this.tableEditor.alignColumn(Alignment.NONE, opts) }, 'Shift-Ctrl-Down': () => { this.tableEditor.alignColumn(Alignment.NONE, opts) },
'Shift-Cmd-Down' : () => { this.tableEditor.alignColumn(Alignment.NONE, opts) }, 'Shift-Cmd-Down': () => { this.tableEditor.alignColumn(Alignment.NONE, opts) },
'Ctrl-Left' : () => { this.tableEditor.moveFocus(0, -1, opts) }, 'Ctrl-Left': () => { this.tableEditor.moveFocus(0, -1, opts) },
'Cmd-Left' : () => { this.tableEditor.moveFocus(0, -1, opts) }, 'Cmd-Left': () => { this.tableEditor.moveFocus(0, -1, opts) },
'Ctrl-Right' : () => { this.tableEditor.moveFocus(0, 1, opts) }, 'Ctrl-Right': () => { this.tableEditor.moveFocus(0, 1, opts) },
'Cmd-Right' : () => { this.tableEditor.moveFocus(0, 1, opts) }, 'Cmd-Right': () => { this.tableEditor.moveFocus(0, 1, opts) },
'Ctrl-Up' : () => { this.tableEditor.moveFocus(-1, 0, opts) }, 'Ctrl-Up': () => { this.tableEditor.moveFocus(-1, 0, opts) },
'Cmd-Up' : () => { this.tableEditor.moveFocus(-1, 0, opts) }, 'Cmd-Up': () => { this.tableEditor.moveFocus(-1, 0, opts) },
'Ctrl-Down' : () => { this.tableEditor.moveFocus(1, 0, opts) }, 'Ctrl-Down': () => { this.tableEditor.moveFocus(1, 0, opts) },
'Cmd-Down' : () => { this.tableEditor.moveFocus(1, 0, opts) }, 'Cmd-Down': () => { this.tableEditor.moveFocus(1, 0, opts) },
'Ctrl-K Ctrl-I' : () => { this.tableEditor.insertRow(opts) }, 'Ctrl-K Ctrl-I': () => { this.tableEditor.insertRow(opts) },
'Cmd-K Cmd-I' : () => { this.tableEditor.insertRow(opts) }, 'Cmd-K Cmd-I': () => { this.tableEditor.insertRow(opts) },
'Ctrl-L Ctrl-I' : () => { this.tableEditor.deleteRow(opts) }, 'Ctrl-L Ctrl-I': () => { this.tableEditor.deleteRow(opts) },
'Cmd-L Cmd-I' : () => { this.tableEditor.deleteRow(opts) }, 'Cmd-L Cmd-I': () => { this.tableEditor.deleteRow(opts) },
'Ctrl-K Ctrl-J' : () => { this.tableEditor.insertColumn(opts) }, 'Ctrl-K Ctrl-J': () => { this.tableEditor.insertColumn(opts) },
'Cmd-K Cmd-J' : () => { this.tableEditor.insertColumn(opts) }, 'Cmd-K Cmd-J': () => { this.tableEditor.insertColumn(opts) },
'Ctrl-L Ctrl-J' : () => { this.tableEditor.deleteColumn(opts) }, 'Ctrl-L Ctrl-J': () => { this.tableEditor.deleteColumn(opts) },
'Cmd-L Cmd-J' : () => { this.tableEditor.deleteColumn(opts) }, 'Cmd-L Cmd-J': () => { this.tableEditor.deleteColumn(opts) },
'Alt-Shift-Ctrl-Left' : () => { this.tableEditor.moveColumn(-1, opts) }, 'Alt-Shift-Ctrl-Left': () => { this.tableEditor.moveColumn(-1, opts) },
'Alt-Shift-Cmd-Left' : () => { this.tableEditor.moveColumn(-1, opts) }, 'Alt-Shift-Cmd-Left': () => { this.tableEditor.moveColumn(-1, opts) },
'Alt-Shift-Ctrl-Right': () => { this.tableEditor.moveColumn(1, opts) }, 'Alt-Shift-Ctrl-Right': () => { this.tableEditor.moveColumn(1, opts) },
'Alt-Shift-Cmd-Right' : () => { this.tableEditor.moveColumn(1, opts) }, 'Alt-Shift-Cmd-Right': () => { this.tableEditor.moveColumn(1, opts) },
'Alt-Shift-Ctrl-Up' : () => { this.tableEditor.moveRow(-1, opts) }, 'Alt-Shift-Ctrl-Up': () => { this.tableEditor.moveRow(-1, opts) },
'Alt-Shift-Cmd-Up' : () => { this.tableEditor.moveRow(-1, opts) }, 'Alt-Shift-Cmd-Up': () => { this.tableEditor.moveRow(-1, opts) },
'Alt-Shift-Ctrl-Down' : () => { this.tableEditor.moveRow(1, opts) }, 'Alt-Shift-Ctrl-Down': () => { this.tableEditor.moveRow(1, opts) },
'Alt-Shift-Cmd-Down' : () => { this.tableEditor.moveRow(1, opts) } 'Alt-Shift-Cmd-Down': () => { this.tableEditor.moveRow(1, opts) }
}) })
const updateActiveState = () => { const updateActiveState = () => {
const active = this.tableEditor.cursorIsInTable(opts) const active = this.tableEditor.cursorIsInTable(opts)
if (active) { if (active) {
@@ -276,7 +276,7 @@ export default class CodeEditor extends React.Component {
this.tableEditor.resetSmartCursor() this.tableEditor.resetSmartCursor()
} }
} }
this.editor.on('cursorActivity', () => { this.editor.on('cursorActivity', () => {
if (!editorIntf.transaction) { if (!editorIntf.transaction) {
updateActiveState() updateActiveState()

View File

@@ -235,7 +235,7 @@ class MarkdownEditor extends React.Component {
if (this.props.ignorePreviewPointerEvents) previewStyle.pointerEvents = 'none' if (this.props.ignorePreviewPointerEvents) previewStyle.pointerEvents = 'none'
const storage = findStorage(storageKey) const storage = findStorage(storageKey)
return ( return (
<div className={className == null <div className={className == null
? 'MarkdownEditor' ? 'MarkdownEditor'

View File

@@ -7,38 +7,38 @@ export default class TextEditorInterface {
this.transaction = false this.transaction = false
} }
getCursorPosition() { getCursorPosition () {
const { line, ch } = this.doc.getCursor() const { line, ch } = this.doc.getCursor()
return new Point(line, ch) return new Point(line, ch)
} }
setCursorPosition(pos) { setCursorPosition (pos) {
this.doc.setCursor({ this.doc.setCursor({
line: pos.row, line: pos.row,
ch: pos.column ch: pos.column
}) })
} }
setSelectionRange(range) { setSelectionRange (range) {
this.doc.setSelection( this.doc.setSelection(
{ line: range.start.row, ch: range.start.column }, { line: range.start.row, ch: range.start.column },
{ line: range.end.row, ch: range.end.column } { line: range.end.row, ch: range.end.column }
) )
} }
getLastRow() { getLastRow () {
return this.doc.lineCount() - 1 return this.doc.lineCount() - 1
} }
acceptsTableEdit() { acceptsTableEdit () {
return true return true
} }
getLine(row) { getLine (row) {
return this.doc.getLine(row) return this.doc.getLine(row)
} }
insertLine(row, line) { insertLine (row, line) {
const lastRow = this.getLastRow() const lastRow = this.getLastRow()
if (row > lastRow) { if (row > lastRow) {
const lastLine = this.getLine(lastRow) const lastLine = this.getLine(lastRow)
@@ -47,8 +47,7 @@ export default class TextEditorInterface {
{ line: lastRow, ch: lastLine.length }, { line: lastRow, ch: lastLine.length },
{ line: lastRow, ch: lastLine.length } { line: lastRow, ch: lastLine.length }
) )
} } else {
else {
this.doc.replaceRange( this.doc.replaceRange(
line + '\n', line + '\n',
{ line: row, ch: 0 }, { line: row, ch: 0 },
@@ -57,7 +56,7 @@ export default class TextEditorInterface {
} }
} }
deleteLine(row) { deleteLine (row) {
const lastRow = this.getLastRow() const lastRow = this.getLastRow()
if (row >= lastRow) { if (row >= lastRow) {
if (lastRow > 0) { if (lastRow > 0) {
@@ -68,8 +67,7 @@ export default class TextEditorInterface {
{ line: lastRow - 1, ch: preLastLine.length }, { line: lastRow - 1, ch: preLastLine.length },
{ line: lastRow, ch: lastLine.length } { line: lastRow, ch: lastLine.length }
) )
} } else {
else {
const lastLine = this.getLine(lastRow) const lastLine = this.getLine(lastRow)
this.doc.replaceRange( this.doc.replaceRange(
'', '',
@@ -77,8 +75,7 @@ export default class TextEditorInterface {
{ line: lastRow, ch: lastLine.length } { line: lastRow, ch: lastLine.length }
) )
} }
} } else {
else {
this.doc.replaceRange( this.doc.replaceRange(
'', '',
{ line: row, ch: 0 }, { line: row, ch: 0 },
@@ -87,7 +84,7 @@ export default class TextEditorInterface {
} }
} }
replaceLines(startRow, endRow, lines) { replaceLines (startRow, endRow, lines) {
const lastRow = this.getLastRow() const lastRow = this.getLastRow()
if (endRow > lastRow) { if (endRow > lastRow) {
const lastLine = this.getLine(lastRow) const lastLine = this.getLine(lastRow)
@@ -96,8 +93,7 @@ export default class TextEditorInterface {
{ line: startRow, ch: 0 }, { line: startRow, ch: 0 },
{ line: lastRow, ch: lastLine.length } { line: lastRow, ch: lastLine.length }
) )
} } else {
else {
this.doc.replaceRange( this.doc.replaceRange(
lines.join('\n') + '\n', lines.join('\n') + '\n',
{ line: startRow, ch: 0 }, { line: startRow, ch: 0 },
@@ -106,7 +102,7 @@ export default class TextEditorInterface {
} }
} }
transact(func) { transact (func) {
this.transaction = true this.transaction = true
func() func()
this.transaction = false this.transaction = false

View File

@@ -420,7 +420,7 @@ class UiTab extends React.Component {
{i18n.__('Bring in web page title when pasting URL on editor')} {i18n.__('Bring in web page title when pasting URL on editor')}
</label> </label>
</div> </div>
<div styleName='group-checkBoxSection'> <div styleName='group-checkBoxSection'>
<label> <label>
<input onChange={(e) => this.handleUIChange(e)} <input onChange={(e) => this.handleUIChange(e)}