From 8d5c9742f826e3cd4a6749bc4414cf43319f23d9 Mon Sep 17 00:00:00 2001 From: Wade Johnson Date: Sat, 9 Dec 2017 21:14:10 -0800 Subject: [PATCH 1/3] Add ability to scroll pasted last line of editor --- browser/components/CodeEditor.js | 5 ++++ browser/components/MarkdownEditor.js | 2 ++ browser/finder/NoteDetail.js | 1 + browser/main/Detail/SnippetNoteDetail.js | 24 +------------------ browser/main/lib/ConfigManager.js | 3 ++- browser/main/modals/PreferencesModal/UiTab.js | 14 ++++++++++- lib/main.html | 1 + 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 1323c514..5ef2b904 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -59,6 +59,7 @@ export default class CodeEditor extends React.Component { tabSize: this.props.indentSize, indentWithTabs: this.props.indentType !== 'space', keyMap: this.props.keyMap, + scrollPastEnd: this.props.scrollPastEnd, inputStyle: 'textarea', dragDrop: false, extraKeys: { @@ -153,6 +154,10 @@ export default class CodeEditor extends React.Component { this.editor.setOption('indentWithTabs', this.props.indentType !== 'space') } + if (prevProps.scrollPastEnd !== this.props.scrollPastEnd) { + this.editor.setOption('scrollPastEnd', this.props.scrollPastEnd); + } + if (needRefresh) { this.editor.refresh() } diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index d4fa6e89..e329d281 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -242,6 +242,7 @@ class MarkdownEditor extends React.Component { fontSize={editorFontSize} indentType={config.editor.indentType} indentSize={editorIndentSize} + scrollPastEnd={config.editor.scrollPastEnd} storageKey={storageKey} onChange={(e) => this.handleChange(e)} onBlur={(e) => this.handleBlur(e)} @@ -259,6 +260,7 @@ class MarkdownEditor extends React.Component { codeBlockFontFamily={config.editor.fontFamily} lineNumber={config.preview.lineNumber} indentSize={editorIndentSize} + scrollPastEnd={config.editor.scrollPastEnd} ref='preview' onContextMenu={(e) => this.handleContextMenu(e)} tabIndex='0' diff --git a/browser/finder/NoteDetail.js b/browser/finder/NoteDetail.js index 9d2f8da4..4c59ea30 100644 --- a/browser/finder/NoteDetail.js +++ b/browser/finder/NoteDetail.js @@ -157,6 +157,7 @@ class NoteDetail extends React.Component { indentType={config.editor.indentType} indentSize={editorIndentSize} keyMap={config.editor.keyMap} + scrollPastEnd={config.editor.scrollPastEnd} readOnly ref={'code-' + index} /> diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index 6b18a5a0..093e9edf 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -236,27 +236,6 @@ class SnippetNoteDetail extends React.Component { }) } - handleTabDragStart (e, index) { - e.dataTransfer.setData('text/plain', index) - } - - handleTabDrop (e, index) { - const oldIndex = parseInt(e.dataTransfer.getData('text')) - - const snippets = this.state.note.snippets.slice() - const draggedSnippet = snippets[oldIndex] - snippets[oldIndex] = snippets[index] - snippets[index] = draggedSnippet - const snippetIndex = index - - const note = Object.assign({}, this.state.note, {snippets}) - this.setState({ note, snippetIndex }, () => { - this.save() - this.refs['code-' + index].reload() - this.refs['code-' + oldIndex].reload() - }) - } - handleTabDeleteButtonClick (e, index) { if (this.state.note.snippets.length > 1) { if (this.state.note.snippets[index].content.trim().length > 0) { @@ -532,8 +511,6 @@ class SnippetNoteDetail extends React.Component { onDelete={(e) => this.handleTabDeleteButtonClick(e, index)} onRename={(name) => this.renameSnippetByIndex(index, name)} isDeletable={note.snippets.length > 1} - onDragStart={(e) => this.handleTabDragStart(e, index)} - onDrop={(e) => this.handleTabDrop(e, index)} /> }) @@ -565,6 +542,7 @@ class SnippetNoteDetail extends React.Component { indentType={config.editor.indentType} indentSize={editorIndentSize} keyMap={config.editor.keyMap} + scrollPastEnd={config.editor.scrollPastEnd} onChange={(e) => this.handleCodeChange(index)(e)} ref={'code-' + index} /> diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index e8f7253e..3c075aa2 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -34,7 +34,8 @@ export const DEFAULT_CONFIG = { fontFamily: win ? 'Segoe UI' : 'Monaco, Consolas', indentType: 'space', indentSize: '2', - switchPreview: 'BLUR' // Available value: RIGHTCLICK, BLUR + switchPreview: 'BLUR', // Available value: RIGHTCLICK, BLUR + scrollPastEnd: false }, preview: { fontSize: '14', diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index b85eafdb..8447452d 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -73,7 +73,8 @@ class UiTab extends React.Component { indentType: this.refs.editorIndentType.value, indentSize: this.refs.editorIndentSize.value, switchPreview: this.refs.editorSwitchPreview.value, - keyMap: this.refs.editorKeyMap.value + keyMap: this.refs.editorKeyMap.value, + scrollPastEnd: this.refs.scrollPastEnd.checked }, preview: { fontSize: this.refs.previewFontSize.value, @@ -278,6 +279,17 @@ class UiTab extends React.Component { +
+ +
+
Preview
diff --git a/lib/main.html b/lib/main.html index 735f8120..69a47900 100644 --- a/lib/main.html +++ b/lib/main.html @@ -82,6 +82,7 @@ + From b742a3a4cde1778910a5a6591fd72419a052e871 Mon Sep 17 00:00:00 2001 From: Wade Johnson Date: Sun, 10 Dec 2017 17:58:06 -0800 Subject: [PATCH 2/3] Put this back?? --- browser/main/Detail/SnippetNoteDetail.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index 093e9edf..bec6573b 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -236,6 +236,27 @@ class SnippetNoteDetail extends React.Component { }) } + handleTabDragStart (e, index) { + e.dataTransfer.setData('text/plain', index) + } + + handleTabDrop (e, index) { + const oldIndex = parseInt(e.dataTransfer.getData('text')) + + const snippets = this.state.note.snippets.slice() + const draggedSnippet = snippets[oldIndex] + snippets[oldIndex] = snippets[index] + snippets[index] = draggedSnippet + const snippetIndex = index + + const note = Object.assign({}, this.state.note, {snippets}) + this.setState({ note, snippetIndex }, () => { + this.save() + this.refs['code-' + index].reload() + this.refs['code-' + oldIndex].reload() + }) + } + handleTabDeleteButtonClick (e, index) { if (this.state.note.snippets.length > 1) { if (this.state.note.snippets[index].content.trim().length > 0) { @@ -511,6 +532,8 @@ class SnippetNoteDetail extends React.Component { onDelete={(e) => this.handleTabDeleteButtonClick(e, index)} onRename={(name) => this.renameSnippetByIndex(index, name)} isDeletable={note.snippets.length > 1} + onDragStart={(e) => this.handleTabDragStart(e, index)} + onDrop={(e) => this.handleTabDrop(e, index)} /> }) From 667f0220862360cda4172731f29047c689511631 Mon Sep 17 00:00:00 2001 From: Wade Johnson Date: Sun, 10 Dec 2017 21:13:21 -0800 Subject: [PATCH 3/3] Remove semicolon --- browser/components/CodeEditor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 5ef2b904..b5e06a66 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -155,7 +155,7 @@ export default class CodeEditor extends React.Component { } if (prevProps.scrollPastEnd !== this.props.scrollPastEnd) { - this.editor.setOption('scrollPastEnd', this.props.scrollPastEnd); + this.editor.setOption('scrollPastEnd', this.props.scrollPastEnd) } if (needRefresh) {