From 657806c8cf278720e4806c26840bb05fb97c0626 Mon Sep 17 00:00:00 2001 From: Baptiste Augrain Date: Mon, 20 Aug 2018 20:14:45 +0200 Subject: [PATCH 1/3] add smart table editor --- browser/components/CodeEditor.js | 183 ++++++++++++------ browser/components/MarkdownEditor.js | 3 +- browser/components/MarkdownSplitEditor.js | 1 + browser/lib/TextEditorInterface.js | 170 +++++++++++----- browser/main/Detail/SnippetNoteDetail.js | 1 + browser/main/lib/ConfigManager.js | 3 +- browser/main/modals/PreferencesModal/UiTab.js | 14 +- locales/en.json | 3 +- locales/fr.json | 3 +- 9 files changed, 269 insertions(+), 112 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index f16cc53c..36779e4f 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -141,61 +141,9 @@ export default class CodeEditor extends React.Component { triples: '```"""\'\'\'', explode: '[]{}``$$', override: true - }, - extraKeys: { - Tab: function (cm) { - const cursor = cm.getCursor() - const line = cm.getLine(cursor.line) - const cursorPosition = cursor.ch - const charBeforeCursor = line.substr(cursorPosition - 1, 1) - if (cm.somethingSelected()) cm.indentSelection('add') - else { - const tabs = cm.getOption('indentWithTabs') - if (line.trimLeft().match(/^(-|\*|\+) (\[( |x)] )?$/)) { - cm.execCommand('goLineStart') - if (tabs) { - cm.execCommand('insertTab') - } else { - cm.execCommand('insertSoftTab') - } - cm.execCommand('goLineEnd') - } else if ( - !charBeforeCursor.match(/\t|\s|\r|\n/) && - cursor.ch > 1 - ) { - // text expansion on tab key if the char before is alphabet - const snippets = JSON.parse( - fs.readFileSync(consts.SNIPPET_FILE, 'utf8') - ) - if (expandSnippet(line, cursor, cm, snippets) === false) { - if (tabs) { - cm.execCommand('insertTab') - } else { - cm.execCommand('insertSoftTab') - } - } - } else { - if (tabs) { - cm.execCommand('insertTab') - } else { - cm.execCommand('insertSoftTab') - } - } - } - }, - 'Cmd-T': function (cm) { - // Do nothing - }, - Enter: 'boostNewLineAndIndentContinueMarkdownList', - 'Ctrl-C': cm => { - if (cm.getOption('keyMap').substr(0, 3) === 'vim') { - document.execCommand('copy') - } - return CodeMirror.Pass - } } }) - + this.setMode(this.props.mode) this.editor.on('focus', this.focusHandler) @@ -216,8 +164,135 @@ export default class CodeEditor extends React.Component { CodeMirror.Vim.defineEx('qw', 'qw', this.quitEditor) CodeMirror.Vim.map('ZZ', ':q', 'normal') this.setState({ isReady: true }) - this.tableEditor = new TableEditor(new TextEditorInterface(this.editor)) + + const editorIntf = new TextEditorInterface(this.editor) + this.tableEditor = new TableEditor(editorIntf) eventEmitter.on('code:format-table', this.formatTable) + + const defaultKeyMap = CodeMirror.normalizeKeyMap({ + Tab: function (cm) { + const cursor = cm.getCursor() + const line = cm.getLine(cursor.line) + const cursorPosition = cursor.ch + const charBeforeCursor = line.substr(cursorPosition - 1, 1) + if (cm.somethingSelected()) cm.indentSelection('add') + else { + const tabs = cm.getOption('indentWithTabs') + if (line.trimLeft().match(/^(-|\*|\+) (\[( |x)] )?$/)) { + cm.execCommand('goLineStart') + if (tabs) { + cm.execCommand('insertTab') + } else { + cm.execCommand('insertSoftTab') + } + cm.execCommand('goLineEnd') + } else if ( + !charBeforeCursor.match(/\t|\s|\r|\n/) && + cursor.ch > 1 + ) { + // text expansion on tab key if the char before is alphabet + const snippets = JSON.parse( + fs.readFileSync(consts.SNIPPET_FILE, 'utf8') + ) + if (expandSnippet(line, cursor, cm, snippets) === false) { + if (tabs) { + cm.execCommand('insertTab') + } else { + cm.execCommand('insertSoftTab') + } + } + } else { + if (tabs) { + cm.execCommand('insertTab') + } else { + cm.execCommand('insertSoftTab') + } + } + } + }, + 'Cmd-T': function (cm) { + // Do nothing + }, + Enter: 'boostNewLineAndIndentContinueMarkdownList', + 'Ctrl-C': cm => { + if (cm.getOption('keyMap').substr(0, 3) === 'vim') { + document.execCommand('copy') + } + return CodeMirror.Pass + } + }) + + if(this.props.enableTableEditor) { + const opts = options({ + smartCursor: true + }) + + const editorKeyMap = CodeMirror.normalizeKeyMap({ + 'Tab' : () => { this.tableEditor.nextCell(opts) }, + 'Shift-Tab' : () => { this.tableEditor.previousCell(opts) }, + 'Enter' : () => { this.tableEditor.nextRow(opts) }, + 'Ctrl-Enter' : () => { this.tableEditor.escape(opts) }, + 'Cmd-Enter' : () => { this.tableEditor.escape(opts) }, + 'Shift-Ctrl-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-Cmd-Right' : () => { this.tableEditor.alignColumn(Alignment.RIGHT, opts) }, + 'Shift-Ctrl-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-Cmd-Down' : () => { this.tableEditor.alignColumn(Alignment.NONE, opts) }, + 'Ctrl-Left' : () => { this.tableEditor.moveFocus(0, -1, opts) }, + 'Cmd-Left' : () => { this.tableEditor.moveFocus(0, -1, opts) }, + 'Ctrl-Right' : () => { this.tableEditor.moveFocus(0, 1, opts) }, + 'Cmd-Right' : () => { this.tableEditor.moveFocus(0, 1, opts) }, + 'Ctrl-Up' : () => { this.tableEditor.moveFocus(-1, 0, opts) }, + 'Cmd-Up' : () => { this.tableEditor.moveFocus(-1, 0, opts) }, + 'Ctrl-Down' : () => { this.tableEditor.moveFocus(1, 0, opts) }, + 'Cmd-Down' : () => { this.tableEditor.moveFocus(1, 0, opts) }, + 'Ctrl-K Ctrl-I' : () => { this.tableEditor.insertRow(opts) }, + 'Cmd-K Cmd-I' : () => { this.tableEditor.insertRow(opts) }, + 'Ctrl-L Ctrl-I' : () => { this.tableEditor.deleteRow(opts) }, + 'Cmd-L Cmd-I' : () => { this.tableEditor.deleteRow(opts) }, + 'Ctrl-K Ctrl-J' : () => { this.tableEditor.insertColumn(opts) }, + 'Cmd-K Cmd-J' : () => { this.tableEditor.insertColumn(opts) }, + 'Ctrl-L Ctrl-J' : () => { this.tableEditor.deleteColumn(opts) }, + 'Cmd-L Cmd-J' : () => { this.tableEditor.deleteColumn(opts) }, + 'Alt-Shift-Ctrl-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-Cmd-Right' : () => { this.tableEditor.moveColumn(1, opts) }, + 'Alt-Shift-Ctrl-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-Cmd-Down' : () => { this.tableEditor.moveRow(1, opts) } + }) + + const updateActiveState = () => { + const active = this.tableEditor.cursorIsInTable(opts) + if (active) { + this.editor.setOption('extraKeys', editorKeyMap) + } else { + this.editor.setOption('extraKeys', defaultKeyMap) + this.tableEditor.resetSmartCursor() + } + } + + this.editor.on('cursorActivity', () => { + if (!editorIntf.transaction) { + updateActiveState() + } + }) + this.editor.on('changes', () => { + if (!editorIntf.transaction) { + updateActiveState() + } + }) + editorIntf.onDidFinishTransaction = () => { + updateActiveState() + } + } else { + this.editor.setOption('extraKeys', defaultKeyMap) + } } expandSnippet (line, cursor, cm, snippets) { diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index 2b388f90..a9a041df 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -235,7 +235,7 @@ class MarkdownEditor extends React.Component { if (this.props.ignorePreviewPointerEvents) previewStyle.pointerEvents = 'none' const storage = findStorage(storageKey) - + return (
this.handleChange(e)} onBlur={(e) => this.handleBlur(e)} /> diff --git a/browser/components/MarkdownSplitEditor.js b/browser/components/MarkdownSplitEditor.js index 8fa3cc07..ddc9d7e0 100644 --- a/browser/components/MarkdownSplitEditor.js +++ b/browser/components/MarkdownSplitEditor.js @@ -158,6 +158,7 @@ class MarkdownSplitEditor extends React.Component { rulers={config.editor.rulers} scrollPastEnd={config.editor.scrollPastEnd} fetchUrlTitle={config.editor.fetchUrlTitle} + enableTableEditor={config.editor.enableTableEditor} storageKey={storageKey} noteKey={noteKey} onChange={this.handleOnChange.bind(this)} diff --git a/browser/lib/TextEditorInterface.js b/browser/lib/TextEditorInterface.js index 53ae2337..8e80c313 100644 --- a/browser/lib/TextEditorInterface.js +++ b/browser/lib/TextEditorInterface.js @@ -1,53 +1,117 @@ -import { Point } from '@susisu/mte-kernel' - -export default class TextEditorInterface { - constructor (editor) { - this.editor = editor - } - - getCursorPosition () { - const pos = this.editor.getCursor() - return new Point(pos.line, pos.ch) - } - - setCursorPosition (pos) { - this.editor.setCursor({line: pos.row, ch: pos.column}) - } - - setSelectionRange (range) { - this.editor.setSelection({ - anchor: {line: range.start.row, ch: range.start.column}, - head: {line: range.end.row, ch: range.end.column} - }) - } - - getLastRow () { - return this.editor.lastLine() - } - - acceptsTableEdit (row) { - return true - } - - getLine (row) { - return this.editor.getLine(row) - } - - insertLine (row, line) { - this.editor.replaceRange(line, {line: row, ch: 0}) - } - - deleteLine (row) { - this.editor.replaceRange('', {line: row, ch: 0}, {line: row, ch: this.editor.getLine(row).length}) - } - - replaceLines (startRow, endRow, lines) { - endRow-- // because endRow is a first line after a table. - const endRowCh = this.editor.getLine(endRow).length - this.editor.replaceRange(lines, {line: startRow, ch: 0}, {line: endRow, ch: endRowCh}) - } - - transact (func) { - func() - } -} +import { Point } from '@susisu/mte-kernel' + +export default class TextEditorInterface { + constructor (editor) { + this.editor = editor + this.doc = editor.getDoc() + this.transaction = false + } + + getCursorPosition() { + const { line, ch } = this.doc.getCursor() + return new Point(line, ch) + } + + setCursorPosition(pos) { + this.doc.setCursor({ + line: pos.row, + ch: pos.column + }) + } + + setSelectionRange(range) { + this.doc.setSelection( + { line: range.start.row, ch: range.start.column }, + { line: range.end.row, ch: range.end.column } + ) + } + + getLastRow() { + return this.doc.lineCount() - 1 + } + + acceptsTableEdit() { + return true + } + + getLine(row) { + return this.doc.getLine(row) + } + + insertLine(row, line) { + const lastRow = this.getLastRow() + if (row > lastRow) { + const lastLine = this.getLine(lastRow) + this.doc.replaceRange( + '\n' + line, + { line: lastRow, ch: lastLine.length }, + { line: lastRow, ch: lastLine.length } + ) + } + else { + this.doc.replaceRange( + line + '\n', + { line: row, ch: 0 }, + { line: row, ch: 0 } + ) + } + } + + deleteLine(row) { + const lastRow = this.getLastRow() + if (row >= lastRow) { + if (lastRow > 0) { + const preLastLine = this.getLine(lastRow - 1) + const lastLine = this.getLine(lastRow) + this.doc.replaceRange( + '', + { line: lastRow - 1, ch: preLastLine.length }, + { line: lastRow, ch: lastLine.length } + ) + } + else { + const lastLine = this.getLine(lastRow) + this.doc.replaceRange( + '', + { line: lastRow, ch: 0 }, + { line: lastRow, ch: lastLine.length } + ) + } + } + else { + this.doc.replaceRange( + '', + { line: row, ch: 0 }, + { line: row + 1, ch: 0 } + ) + } + } + + replaceLines(startRow, endRow, lines) { + const lastRow = this.getLastRow() + if (endRow > lastRow) { + const lastLine = this.getLine(lastRow) + this.doc.replaceRange( + lines.join('\n'), + { line: startRow, ch: 0 }, + { line: lastRow, ch: lastLine.length } + ) + } + else { + this.doc.replaceRange( + lines.join('\n') + '\n', + { line: startRow, ch: 0 }, + { line: endRow, ch: 0 } + ) + } + } + + transact(func) { + this.transaction = true + func() + this.transaction = false + if (this.onDidFinishTransaction) { + this.onDidFinishTransaction.call(undefined) + } + } +} diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index 652d1f53..2fe96420 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -691,6 +691,7 @@ class SnippetNoteDetail extends React.Component { keyMap={config.editor.keyMap} scrollPastEnd={config.editor.scrollPastEnd} fetchUrlTitle={config.editor.fetchUrlTitle} + enableTableEditor={config.editor.enableTableEditor} onChange={(e) => this.handleCodeChange(index)(e)} ref={'code-' + index} /> diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 434b0d22..2c601b57 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -46,7 +46,8 @@ export const DEFAULT_CONFIG = { switchPreview: 'BLUR', // Available value: RIGHTCLICK, BLUR scrollPastEnd: false, type: 'SPLIT', - fetchUrlTitle: true + fetchUrlTitle: true, + enableTableEditor: false }, preview: { fontSize: '14', diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index aa3568e7..f8a9ab11 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -86,7 +86,8 @@ class UiTab extends React.Component { switchPreview: this.refs.editorSwitchPreview.value, keyMap: this.refs.editorKeyMap.value, scrollPastEnd: this.refs.scrollPastEnd.checked, - fetchUrlTitle: this.refs.editorFetchUrlTitle.checked + fetchUrlTitle: this.refs.editorFetchUrlTitle.checked, + enableTableEditor: this.refs.enableTableEditor.checked }, preview: { fontSize: this.refs.previewFontSize.value, @@ -419,6 +420,17 @@ class UiTab extends React.Component { {i18n.__('Bring in web page title when pasting URL on editor')}
+ +
+ +
{i18n.__('Preview')}
diff --git a/locales/en.json b/locales/en.json index a9767492..6b12c1e7 100644 --- a/locales/en.json +++ b/locales/en.json @@ -175,5 +175,6 @@ "Allow styles": "Allow styles", "Allow dangerous html tags": "Allow dangerous html tags", "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.", - "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠" + "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠", + "Enable smart table editor": "Enable smart table editor" } diff --git a/locales/fr.json b/locales/fr.json index 8b880aa6..e9b2c168 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -152,5 +152,6 @@ "Allow styles": "Accepter les styles", "Allow dangerous html tags": "Accepter les tags html dangereux", "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convertir des flèches textuelles en jolis signes. ⚠ Cela va interferérer avec les éventuels commentaires HTML dans votre Markdown.", - "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ Vous avez collé un lien qui référence une pièce-jointe qui n'a pas pu être récupéré dans le dossier de stockage de la note. Coller des liens qui font référence à des pièces-jointes ne fonctionne que si la source et la destination et la même. Veuillez plutôt utiliser du Drag & Drop ! ⚠" + "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ Vous avez collé un lien qui référence une pièce-jointe qui n'a pas pu être récupéré dans le dossier de stockage de la note. Coller des liens qui font référence à des pièces-jointes ne fonctionne que si la source et la destination et la même. Veuillez plutôt utiliser du Drag & Drop ! ⚠", + "Enable smart table editor": "Activer l'intelligent éditeur de tableaux" } From 7cf9dda82108b69b34e3ebe7e1494712701f2e04 Mon Sep 17 00:00:00 2001 From: Baptiste Augrain Date: Mon, 20 Aug 2018 20:29:10 +0200 Subject: [PATCH 2/3] fix lint errors --- browser/components/CodeEditor.js | 90 +++++++++---------- browser/components/MarkdownEditor.js | 2 +- browser/lib/TextEditorInterface.js | 32 +++---- browser/main/modals/PreferencesModal/UiTab.js | 2 +- 4 files changed, 61 insertions(+), 65 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 36779e4f..b2301c08 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -5,7 +5,7 @@ import CodeMirror from 'codemirror' import 'codemirror-mode-elixir' import attachmentManagement from 'browser/main/lib/dataApi/attachmentManagement' 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 eventEmitter from 'browser/main/lib/eventEmitter' import iconv from 'iconv-lite' @@ -143,7 +143,7 @@ export default class CodeEditor extends React.Component { override: true } }) - + this.setMode(this.props.mode) 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.map('ZZ', ':q', 'normal') this.setState({ isReady: true }) - + const editorIntf = new TextEditorInterface(this.editor) this.tableEditor = new TableEditor(editorIntf) eventEmitter.on('code:format-table', this.formatTable) - + const defaultKeyMap = CodeMirror.normalizeKeyMap({ Tab: function (cm) { const cursor = cm.getCursor() @@ -221,52 +221,52 @@ export default class CodeEditor extends React.Component { return CodeMirror.Pass } }) - - if(this.props.enableTableEditor) { + + if (this.props.enableTableEditor) { const opts = options({ smartCursor: true }) - + const editorKeyMap = CodeMirror.normalizeKeyMap({ - 'Tab' : () => { this.tableEditor.nextCell(opts) }, - 'Shift-Tab' : () => { this.tableEditor.previousCell(opts) }, - 'Enter' : () => { this.tableEditor.nextRow(opts) }, - 'Ctrl-Enter' : () => { this.tableEditor.escape(opts) }, - 'Cmd-Enter' : () => { this.tableEditor.escape(opts) }, - 'Shift-Ctrl-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-Cmd-Right' : () => { this.tableEditor.alignColumn(Alignment.RIGHT, opts) }, - 'Shift-Ctrl-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-Cmd-Down' : () => { this.tableEditor.alignColumn(Alignment.NONE, opts) }, - 'Ctrl-Left' : () => { this.tableEditor.moveFocus(0, -1, opts) }, - 'Cmd-Left' : () => { this.tableEditor.moveFocus(0, -1, opts) }, - 'Ctrl-Right' : () => { this.tableEditor.moveFocus(0, 1, opts) }, - 'Cmd-Right' : () => { this.tableEditor.moveFocus(0, 1, opts) }, - 'Ctrl-Up' : () => { this.tableEditor.moveFocus(-1, 0, opts) }, - 'Cmd-Up' : () => { this.tableEditor.moveFocus(-1, 0, opts) }, - 'Ctrl-Down' : () => { this.tableEditor.moveFocus(1, 0, opts) }, - 'Cmd-Down' : () => { this.tableEditor.moveFocus(1, 0, opts) }, - 'Ctrl-K Ctrl-I' : () => { this.tableEditor.insertRow(opts) }, - 'Cmd-K Cmd-I' : () => { this.tableEditor.insertRow(opts) }, - 'Ctrl-L Ctrl-I' : () => { this.tableEditor.deleteRow(opts) }, - 'Cmd-L Cmd-I' : () => { this.tableEditor.deleteRow(opts) }, - 'Ctrl-K Ctrl-J' : () => { this.tableEditor.insertColumn(opts) }, - 'Cmd-K Cmd-J' : () => { this.tableEditor.insertColumn(opts) }, - 'Ctrl-L Ctrl-J' : () => { this.tableEditor.deleteColumn(opts) }, - 'Cmd-L Cmd-J' : () => { this.tableEditor.deleteColumn(opts) }, - 'Alt-Shift-Ctrl-Left' : () => { this.tableEditor.moveColumn(-1, opts) }, - 'Alt-Shift-Cmd-Left' : () => { this.tableEditor.moveColumn(-1, opts) }, + 'Tab': () => { this.tableEditor.nextCell(opts) }, + 'Shift-Tab': () => { this.tableEditor.previousCell(opts) }, + 'Enter': () => { this.tableEditor.nextRow(opts) }, + 'Ctrl-Enter': () => { this.tableEditor.escape(opts) }, + 'Cmd-Enter': () => { this.tableEditor.escape(opts) }, + 'Shift-Ctrl-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-Cmd-Right': () => { this.tableEditor.alignColumn(Alignment.RIGHT, opts) }, + 'Shift-Ctrl-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-Cmd-Down': () => { this.tableEditor.alignColumn(Alignment.NONE, opts) }, + 'Ctrl-Left': () => { this.tableEditor.moveFocus(0, -1, opts) }, + 'Cmd-Left': () => { this.tableEditor.moveFocus(0, -1, opts) }, + 'Ctrl-Right': () => { this.tableEditor.moveFocus(0, 1, opts) }, + 'Cmd-Right': () => { this.tableEditor.moveFocus(0, 1, opts) }, + 'Ctrl-Up': () => { this.tableEditor.moveFocus(-1, 0, opts) }, + 'Cmd-Up': () => { this.tableEditor.moveFocus(-1, 0, opts) }, + 'Ctrl-Down': () => { this.tableEditor.moveFocus(1, 0, opts) }, + 'Cmd-Down': () => { this.tableEditor.moveFocus(1, 0, opts) }, + 'Ctrl-K Ctrl-I': () => { this.tableEditor.insertRow(opts) }, + 'Cmd-K Cmd-I': () => { this.tableEditor.insertRow(opts) }, + 'Ctrl-L Ctrl-I': () => { this.tableEditor.deleteRow(opts) }, + 'Cmd-L Cmd-I': () => { this.tableEditor.deleteRow(opts) }, + 'Ctrl-K Ctrl-J': () => { this.tableEditor.insertColumn(opts) }, + 'Cmd-K Cmd-J': () => { this.tableEditor.insertColumn(opts) }, + 'Ctrl-L Ctrl-J': () => { this.tableEditor.deleteColumn(opts) }, + 'Cmd-L Cmd-J': () => { this.tableEditor.deleteColumn(opts) }, + 'Alt-Shift-Ctrl-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-Cmd-Right' : () => { this.tableEditor.moveColumn(1, opts) }, - 'Alt-Shift-Ctrl-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-Cmd-Down' : () => { this.tableEditor.moveRow(1, opts) } + 'Alt-Shift-Cmd-Right': () => { this.tableEditor.moveColumn(1, opts) }, + 'Alt-Shift-Ctrl-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-Cmd-Down': () => { this.tableEditor.moveRow(1, opts) } }) - + const updateActiveState = () => { const active = this.tableEditor.cursorIsInTable(opts) if (active) { @@ -276,7 +276,7 @@ export default class CodeEditor extends React.Component { this.tableEditor.resetSmartCursor() } } - + this.editor.on('cursorActivity', () => { if (!editorIntf.transaction) { updateActiveState() diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index a9a041df..c9db7eff 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -235,7 +235,7 @@ class MarkdownEditor extends React.Component { if (this.props.ignorePreviewPointerEvents) previewStyle.pointerEvents = 'none' const storage = findStorage(storageKey) - + return (
lastRow) { const lastLine = this.getLine(lastRow) @@ -47,8 +47,7 @@ export default class TextEditorInterface { { line: lastRow, ch: lastLine.length }, { line: lastRow, ch: lastLine.length } ) - } - else { + } else { this.doc.replaceRange( line + '\n', { line: row, ch: 0 }, @@ -57,7 +56,7 @@ export default class TextEditorInterface { } } - deleteLine(row) { + deleteLine (row) { const lastRow = this.getLastRow() if (row >= lastRow) { if (lastRow > 0) { @@ -68,8 +67,7 @@ export default class TextEditorInterface { { line: lastRow - 1, ch: preLastLine.length }, { line: lastRow, ch: lastLine.length } ) - } - else { + } else { const lastLine = this.getLine(lastRow) this.doc.replaceRange( '', @@ -77,8 +75,7 @@ export default class TextEditorInterface { { line: lastRow, ch: lastLine.length } ) } - } - else { + } else { this.doc.replaceRange( '', { line: row, ch: 0 }, @@ -87,7 +84,7 @@ export default class TextEditorInterface { } } - replaceLines(startRow, endRow, lines) { + replaceLines (startRow, endRow, lines) { const lastRow = this.getLastRow() if (endRow > lastRow) { const lastLine = this.getLine(lastRow) @@ -96,8 +93,7 @@ export default class TextEditorInterface { { line: startRow, ch: 0 }, { line: lastRow, ch: lastLine.length } ) - } - else { + } else { this.doc.replaceRange( lines.join('\n') + '\n', { line: startRow, ch: 0 }, @@ -106,7 +102,7 @@ export default class TextEditorInterface { } } - transact(func) { + transact (func) { this.transaction = true func() this.transaction = false diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index f8a9ab11..6fda7c3a 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -420,7 +420,7 @@ class UiTab extends React.Component { {i18n.__('Bring in web page title when pasting URL on editor')}
- +