From 24302b56de517e27a03a74461b9f0f07eb1bace0 Mon Sep 17 00:00:00 2001 From: Laksh Singla <30999375+LakshSingla@users.noreply.github.com> Date: Wed, 27 Mar 2019 01:07:44 +0530 Subject: [PATCH] Added softwrap preference for users. (#970) * Client and server side code added for Linewrap option * Linked linewrap prop with the Editor.jsx property * linewrap defaults to true * Renamed 'LineWrap' to 'WordWrap' --- client/constants.js | 1 + client/modules/IDE/actions/preferences.js | 18 ++++++++++ client/modules/IDE/components/Editor.jsx | 6 +++- client/modules/IDE/components/Preferences.jsx | 35 +++++++++++++++++++ client/modules/IDE/pages/IDEView.jsx | 5 +++ client/modules/IDE/reducers/preferences.js | 3 ++ client/styles/components/_overlay.scss | 2 +- server/models/user.js | 1 + 8 files changed, 69 insertions(+), 2 deletions(-) diff --git a/client/constants.js b/client/constants.js index 4250cc3b..5d10b458 100644 --- a/client/constants.js +++ b/client/constants.js @@ -62,6 +62,7 @@ export const UPDATE_FILE_NAME = 'UPDATE_FILE_NAME'; export const DELETE_FILE = 'DELETE_FILE'; export const SET_AUTOSAVE = 'SET_AUTOSAVE'; +export const SET_LINEWRAP = 'SET_LINEWRAP'; export const SET_LINT_WARNING = 'SET_LINT_WARNING'; export const SET_PREFERENCES = 'SET_PREFERENCES'; export const SET_TEXT_OUTPUT = 'SET_TEXT_OUTPUT'; diff --git a/client/modules/IDE/actions/preferences.js b/client/modules/IDE/actions/preferences.js index 3e26e45a..c5fb44ad 100644 --- a/client/modules/IDE/actions/preferences.js +++ b/client/modules/IDE/actions/preferences.js @@ -102,6 +102,24 @@ export function setAutosave(value) { }; } +export function setLinewrap(value) { + return (dispatch, getState) => { + dispatch({ + type: ActionTypes.SET_LINEWRAP, + value + }); + const state = getState(); + if (state.user.authenticated) { + const formParams = { + preferences: { + linewrap: value + } + }; + updatePreferences(formParams, dispatch); + } + }; +} + export function setLintWarning(value) { return (dispatch, getState) => { dispatch({ diff --git a/client/modules/IDE/components/Editor.jsx b/client/modules/IDE/components/Editor.jsx index 485302e5..859baf77 100644 --- a/client/modules/IDE/components/Editor.jsx +++ b/client/modules/IDE/components/Editor.jsx @@ -80,7 +80,7 @@ class Editor extends React.Component { lineNumbers: true, styleActiveLine: true, inputStyle: 'contenteditable', - lineWrapping: false, + lineWrapping: this.props.linewrap, fixedGutter: false, foldGutter: true, foldOptions: { widget: '\u2026' }, @@ -178,6 +178,9 @@ class Editor extends React.Component { this._cm.setOption('tabSize', this.props.indentationAmount); this._cm.setOption('indentUnit', this.props.indentationAmount); } + if (this.props.linewrap !== prevProps.linewrap) { + this._cm.setOption('lineWrapping', this.props.linewrap); + } if (this.props.isTabIndent !== prevProps.isTabIndent) { this._cm.setOption('indentWithTabs', this.props.isTabIndent); } @@ -339,6 +342,7 @@ class Editor extends React.Component { Editor.propTypes = { lintWarning: PropTypes.bool.isRequired, + linewrap: PropTypes.bool.isRequired, lintMessages: PropTypes.arrayOf(PropTypes.shape({ severity: PropTypes.string.isRequired, line: PropTypes.number.isRequired, diff --git a/client/modules/IDE/components/Preferences.jsx b/client/modules/IDE/components/Preferences.jsx index 27eddd7d..16d8bf15 100644 --- a/client/modules/IDE/components/Preferences.jsx +++ b/client/modules/IDE/components/Preferences.jsx @@ -15,6 +15,7 @@ class Preferences extends React.Component { constructor(props) { super(props); this.handleUpdateAutosave = this.handleUpdateAutosave.bind(this); + this.handleUpdateLinewrap = this.handleUpdateLinewrap.bind(this); this.handleUpdateFont = this.handleUpdateFont.bind(this); this.handleUpdateIndentation = this.handleUpdateIndentation.bind(this); this.handleLintWarning = this.handleLintWarning.bind(this); @@ -53,6 +54,11 @@ class Preferences extends React.Component { this.props.setAutosave(value); } + handleUpdateLinewrap(event) { + const value = event.target.value === 'true'; + this.props.setLinewrap(value); + } + handleLintWarning(event) { const value = event.target.value === 'true'; this.props.setLintWarning(value); @@ -230,6 +236,33 @@ class Preferences extends React.Component { +