From fbb7839f83d383dc77f89dc38b93ef49da3c26d2 Mon Sep 17 00:00:00 2001 From: Yu-Hung Ou Date: Tue, 20 Mar 2018 20:43:23 +1100 Subject: [PATCH 1/6] added Editor Rulers field in Preferences --- browser/main/lib/ConfigManager.js | 1 + browser/main/modals/PreferencesModal/UiTab.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 40b89198..2c896eb9 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -35,6 +35,7 @@ export const DEFAULT_CONFIG = { fontFamily: win ? 'Segoe UI' : 'Monaco, Consolas', indentType: 'space', indentSize: '2', + rulers: [80, 120], displayLineNumbers: true, switchPreview: 'BLUR', // Available value: RIGHTCLICK, BLUR scrollPastEnd: false, diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index 81e29746..f3584bbc 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -75,6 +75,7 @@ class UiTab extends React.Component { fontFamily: this.refs.editorFontFamily.value, indentType: this.refs.editorIndentType.value, indentSize: this.refs.editorIndentSize.value, + rulers: this.refs.editorRulers.value.replace(/[^0-9,]/g, '').split(','), displayLineNumbers: this.refs.editorDisplayLineNumbers.checked, switchPreview: this.refs.editorSwitchPreview.value, keyMap: this.refs.editorKeyMap.value, @@ -303,6 +304,20 @@ class UiTab extends React.Component { +
+
+ {i18n.__('Editor Rulers')} +
+
+ this.handleUIChange(e)} + type='text' + /> +
+
+
{i18n.__('Switch to Preview')} From 281fb2afd32e7ffa005f480d6b6dca58220b6be9 Mon Sep 17 00:00:00 2001 From: Yu-Hung Ou Date: Tue, 20 Mar 2018 20:44:44 +1100 Subject: [PATCH 2/6] added CodeMirror ruler support --- browser/components/CodeEditor.js | 8 ++++++++ browser/components/MarkdownEditor.js | 1 + browser/components/MarkdownSplitEditor.js | 1 + lib/main.html | 1 + 4 files changed, 11 insertions(+) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 0ad4f39a..fe7a0b10 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -14,6 +14,7 @@ const { ipcRenderer } = require('electron') CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js' const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace'] +const buildCMRulers = rulers => rulers.map(ruler => ({ column: ruler })) function pass (name) { switch (name) { @@ -91,9 +92,11 @@ export default class CodeEditor extends React.Component { } componentDidMount () { + const { rulers } = this.props this.value = this.props.value this.editor = CodeMirror(this.refs.root, { + rulers: buildCMRulers(rulers), value: this.props.value, lineNumbers: this.props.displayLineNumbers, lineWrapping: true, @@ -198,6 +201,10 @@ export default class CodeEditor extends React.Component { needRefresh = true } + if (prevProps.rulers !== this.props.rulers) { + this.editor.setOption('rulers', buildCMRulers(this.props.rulers)) + } + if (prevProps.indentSize !== this.props.indentSize) { this.editor.setOption('indentUnit', this.props.indentSize) this.editor.setOption('tabSize', this.props.indentSize) @@ -407,6 +414,7 @@ export default class CodeEditor extends React.Component { CodeEditor.propTypes = { value: PropTypes.string, + rulers: PropTypes.arrayOf(Number), mode: PropTypes.string, className: PropTypes.string, onBlur: PropTypes.func, diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index d0e2f505..e35c4c21 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -258,6 +258,7 @@ class MarkdownEditor extends React.Component { fontSize={editorFontSize} indentType={config.editor.indentType} indentSize={editorIndentSize} + rulers={config.editor.rulers} displayLineNumbers={config.editor.displayLineNumbers} scrollPastEnd={config.editor.scrollPastEnd} storageKey={storageKey} diff --git a/browser/components/MarkdownSplitEditor.js b/browser/components/MarkdownSplitEditor.js index 0aa2d16c..3b8cd768 100644 --- a/browser/components/MarkdownSplitEditor.js +++ b/browser/components/MarkdownSplitEditor.js @@ -110,6 +110,7 @@ class MarkdownSplitEditor extends React.Component { displayLineNumbers={config.editor.displayLineNumbers} indentType={config.editor.indentType} indentSize={editorIndentSize} + rulers={config.editor.rulers} scrollPastEnd={config.editor.scrollPastEnd} fetchUrlTitle={config.editor.fetchUrlTitle} storageKey={storageKey} diff --git a/lib/main.html b/lib/main.html index dbb61b75..24accf36 100644 --- a/lib/main.html +++ b/lib/main.html @@ -89,6 +89,7 @@ + From 29888c89ada0f8d9e9dd0d25f7dc4d8009332ff3 Mon Sep 17 00:00:00 2001 From: Yu-Hung Ou Date: Tue, 20 Mar 2018 21:02:29 +1100 Subject: [PATCH 3/6] added CSS style for rulers to make it fit most of the themes --- lib/main.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/main.html b/lib/main.html index 24accf36..830d3b48 100644 --- a/lib/main.html +++ b/lib/main.html @@ -57,6 +57,10 @@ opacity: 1 !important; pointer-events: auto !important; } + .CodeMirror-ruler { + border-left-color: rgba(142, 142, 142, 0.5); + mix-blend-mode: difference; + } From 8b11b57ec534a5223d1024c04598ce0ca1eb8f41 Mon Sep 17 00:00:00 2001 From: Yu-Hung Ou Date: Wed, 21 Mar 2018 22:31:46 +1100 Subject: [PATCH 4/6] allow users to enable/disable editor rulers. default: disable --- browser/components/CodeEditor.js | 13 ++++++++----- browser/components/MarkdownEditor.js | 1 + browser/components/MarkdownSplitEditor.js | 1 + browser/main/lib/ConfigManager.js | 1 + browser/main/modals/PreferencesModal/UiTab.js | 16 ++++++++++++++++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index fe7a0b10..eeb1a930 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -14,7 +14,8 @@ const { ipcRenderer } = require('electron') CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js' const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace'] -const buildCMRulers = rulers => rulers.map(ruler => ({ column: ruler })) +const buildCMRulers = (rulers, enableRulers) => + enableRulers ? rulers.map(ruler => ({ column: ruler })) : [] function pass (name) { switch (name) { @@ -92,11 +93,11 @@ export default class CodeEditor extends React.Component { } componentDidMount () { - const { rulers } = this.props + const { rulers, enableRulers } = this.props this.value = this.props.value this.editor = CodeMirror(this.refs.root, { - rulers: buildCMRulers(rulers), + rulers: buildCMRulers(rulers, enableRulers), value: this.props.value, lineNumbers: this.props.displayLineNumbers, lineWrapping: true, @@ -184,6 +185,7 @@ export default class CodeEditor extends React.Component { componentDidUpdate (prevProps, prevState) { let needRefresh = false + const { rulers, enableRulers } = this.props if (prevProps.mode !== this.props.mode) { this.setMode(this.props.mode) } @@ -201,8 +203,8 @@ export default class CodeEditor extends React.Component { needRefresh = true } - if (prevProps.rulers !== this.props.rulers) { - this.editor.setOption('rulers', buildCMRulers(this.props.rulers)) + if (prevProps.enableRulers !== enableRulers || prevProps.rulers !== rulers) { + this.editor.setOption('rulers', buildCMRulers(rulers, enableRulers)) } if (prevProps.indentSize !== this.props.indentSize) { @@ -414,6 +416,7 @@ export default class CodeEditor extends React.Component { CodeEditor.propTypes = { value: PropTypes.string, + enableRulers: PropTypes.bool, rulers: PropTypes.arrayOf(Number), mode: PropTypes.string, className: PropTypes.string, diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index e35c4c21..7459b14f 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -258,6 +258,7 @@ class MarkdownEditor extends React.Component { fontSize={editorFontSize} indentType={config.editor.indentType} indentSize={editorIndentSize} + enableRulers={config.editor.enableRulers} rulers={config.editor.rulers} displayLineNumbers={config.editor.displayLineNumbers} scrollPastEnd={config.editor.scrollPastEnd} diff --git a/browser/components/MarkdownSplitEditor.js b/browser/components/MarkdownSplitEditor.js index 3b8cd768..3a16e4c2 100644 --- a/browser/components/MarkdownSplitEditor.js +++ b/browser/components/MarkdownSplitEditor.js @@ -110,6 +110,7 @@ class MarkdownSplitEditor extends React.Component { displayLineNumbers={config.editor.displayLineNumbers} indentType={config.editor.indentType} indentSize={editorIndentSize} + enableRulers={config.editor.enableRulers} rulers={config.editor.rulers} scrollPastEnd={config.editor.scrollPastEnd} fetchUrlTitle={config.editor.fetchUrlTitle} diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 2c896eb9..5b78a0c0 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -35,6 +35,7 @@ export const DEFAULT_CONFIG = { fontFamily: win ? 'Segoe UI' : 'Monaco, Consolas', indentType: 'space', indentSize: '2', + enableRulers: false, rulers: [80, 120], displayLineNumbers: true, switchPreview: 'BLUR', // Available value: RIGHTCLICK, BLUR diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index f3584bbc..da0ea62a 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -75,6 +75,7 @@ class UiTab extends React.Component { fontFamily: this.refs.editorFontFamily.value, indentType: this.refs.editorIndentType.value, indentSize: this.refs.editorIndentSize.value, + enableRulers: this.refs.enableEditorRulers.value === 'true', rulers: this.refs.editorRulers.value.replace(/[^0-9,]/g, '').split(','), displayLineNumbers: this.refs.editorDisplayLineNumbers.checked, switchPreview: this.refs.editorSwitchPreview.value, @@ -152,6 +153,7 @@ class UiTab extends React.Component { const themes = consts.THEMES const { config, codemirrorTheme } = this.state const codemirrorSampleCode = 'function iamHappy (happy) {\n\tif (happy) {\n\t console.log("I am Happy!")\n\t} else {\n\t console.log("I am not Happy!")\n\t}\n};' + const enableEditRulersStyle = config.editor.enableRulers ? 'block' : 'none' return (
@@ -309,7 +311,21 @@ class UiTab extends React.Component { {i18n.__('Editor Rulers')}
+
+ +
this.handleUIChange(e)} From bdb9349b52965b046ca6105869cab235b1cc15f6 Mon Sep 17 00:00:00 2001 From: Yu-Hung Ou Date: Wed, 21 Mar 2018 22:32:05 +1100 Subject: [PATCH 5/6] updated en local --- locales/en.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/locales/en.json b/locales/en.json index db13da16..06aa3269 100644 --- a/locales/en.json +++ b/locales/en.json @@ -144,5 +144,8 @@ "UserName": "UserName", "Password": "Password", "Russian": "Russian", - "Command(⌘)": "Command(⌘)" + "Command(⌘)": "Command(⌘)", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" } \ No newline at end of file From 2627c09cda64a63071622a9eea07356a0d074bee Mon Sep 17 00:00:00 2001 From: Yu-Hung Ou Date: Thu, 22 Mar 2018 21:44:26 +1100 Subject: [PATCH 6/6] added new local strings to all locals --- locales/da.json | 8 ++++++-- locales/de.json | 8 ++++++-- locales/es.json | 8 ++++++-- locales/fr.json | 9 +++++++-- locales/ja.json | 8 ++++++-- locales/ko.json | 7 +++++-- locales/no.json | 7 +++++-- locales/pl.json | 7 +++++-- locales/pt.json | 7 +++++-- locales/ru.json | 5 ++++- locales/sq.json | 7 +++++-- locales/zh-CN.json | 7 +++++-- locales/zh-TW.json | 7 +++++-- 13 files changed, 70 insertions(+), 25 deletions(-) diff --git a/locales/da.json b/locales/da.json index e54245f9..1f3db652 100644 --- a/locales/da.json +++ b/locales/da.json @@ -141,5 +141,9 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Command(⌘)": "Command(⌘)", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/de.json b/locales/de.json index 9c36871c..18491c6a 100644 --- a/locales/de.json +++ b/locales/de.json @@ -143,5 +143,9 @@ "Successfully applied!": "Erfolgreich angewendet!", "UserName": "UserName", "Password": "Password", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Command(⌘)": "Command(⌘)", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/es.json b/locales/es.json index e54245f9..1f3db652 100644 --- a/locales/es.json +++ b/locales/es.json @@ -141,5 +141,9 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Command(⌘)": "Command(⌘)", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/fr.json b/locales/fr.json index 6f664280..93995a52 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -139,5 +139,10 @@ "Polish": "Polonais", "Portuguese": "Portugais", "Spanish": "Espagnol", - "You have to save!": "Il faut sauvegarder !" - } \ No newline at end of file + "You have to save!": "Il faut sauvegarder !", + "Russian": "Russian", + "Command(⌘)": "Command(⌘)", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/ja.json b/locales/ja.json index e54245f9..1f3db652 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -141,5 +141,9 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Command(⌘)": "Command(⌘)", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/ko.json b/locales/ko.json index 4b85c0e3..d87bce9f 100644 --- a/locales/ko.json +++ b/locales/ko.json @@ -148,5 +148,8 @@ "UserName": "유저명", "Password": "패스워드", "Storage": "저장소", - "Hotkeys": "단축키" -} \ No newline at end of file + "Hotkeys": "단축키", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/no.json b/locales/no.json index e54245f9..bd54f4fc 100644 --- a/locales/no.json +++ b/locales/no.json @@ -141,5 +141,8 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/pl.json b/locales/pl.json index e54245f9..bd54f4fc 100644 --- a/locales/pl.json +++ b/locales/pl.json @@ -141,5 +141,8 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/pt.json b/locales/pt.json index e54245f9..bd54f4fc 100644 --- a/locales/pt.json +++ b/locales/pt.json @@ -141,5 +141,8 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/ru.json b/locales/ru.json index 74f83388..0f3696d2 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -143,5 +143,8 @@ "You have to save!": "Нужно сохранить!", "UserName": "Имя пользователя", "Password": "Пароль", - "Russian": "Русский" + "Russian": "Русский", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" } diff --git a/locales/sq.json b/locales/sq.json index e54245f9..bd54f4fc 100644 --- a/locales/sq.json +++ b/locales/sq.json @@ -141,5 +141,8 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/zh-CN.json b/locales/zh-CN.json index e54245f9..bd54f4fc 100644 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -141,5 +141,8 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +} diff --git a/locales/zh-TW.json b/locales/zh-TW.json index e54245f9..bd54f4fc 100644 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -141,5 +141,8 @@ "Portuguese": "Portuguese", "Spanish": "Spanish", "You have to save!": "You have to save!", - "Russian": "Russian" -} \ No newline at end of file + "Russian": "Russian", + "Editor Rulers": "Editor Rulers", + "Enable": "Enable", + "Disable": "Disable" +}