From dee96920b06ba0be360308e58be98dba778bfe9f Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 10 May 2018 18:03:54 +0100 Subject: [PATCH] Allow font family and line height to be user configurable --- .../Features/Project/ProjectController.coffee | 2 ++ .../Features/User/UserController.coffee | 5 +++++ .../infrastructure/ExpressLocals.coffee | 7 +++++-- services/web/app/coffee/models/User.coffee | 18 +++++++++-------- .../web/app/views/project/editor/editor.pug | 4 ++-- .../app/views/project/editor/left-menu.pug | 20 +++++++++++++++++++ services/web/public/coffee/ide.coffee | 4 ++-- .../ide/editor/directives/aceEditor.coffee | 19 ++++++++++++++++-- .../aceEditor/undo/UndoManager.coffee | 10 ++++++++-- .../controllers/SettingsController.coffee | 14 +++++++++++++ 10 files changed, 85 insertions(+), 18 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 1f9eb5f288..f2c92efcb3 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -299,6 +299,8 @@ module.exports = ProjectController = autoPairDelimiters: user.ace.autoPairDelimiters pdfViewer : user.ace.pdfViewer syntaxValidation: user.ace.syntaxValidation + fontFamily: user.ace.fontFamily + lineHeight: user.ace.lineHeight } trackChangesState: project.track_changes privilegeLevel: privilegeLevel diff --git a/services/web/app/coffee/Features/User/UserController.coffee b/services/web/app/coffee/Features/User/UserController.coffee index 7dc82c1a7b..ccbd0a86f1 100644 --- a/services/web/app/coffee/Features/User/UserController.coffee +++ b/services/web/app/coffee/Features/User/UserController.coffee @@ -81,6 +81,11 @@ module.exports = UserController = user.ace.pdfViewer = req.body.pdfViewer if req.body.syntaxValidation? user.ace.syntaxValidation = req.body.syntaxValidation + if req.body.fontFamily? + user.ace.fontFamily = req.body.fontFamily + if req.body.lineHeight? + user.ace.lineHeight = req.body.lineHeight + user.save (err)-> newEmail = req.body.email?.trim().toLowerCase() if !newEmail? or newEmail == user.email or req.externalAuthenticationSystemUsed() diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 11fc1d157e..6943a79cb2 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -183,6 +183,9 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> # Don't include the query string parameters, otherwise Google # treats ?nocdn=true as the canonical version res.locals.currentUrl = Url.parse(req.originalUrl).pathname + res.locals.capitalize = (string) -> + return "" if string.length == 0 + return string.charAt(0).toUpperCase() + string.slice(1) next() webRouter.use (req, res, next)-> @@ -321,7 +324,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)-> chatMessageBorderLightness : if isOl then "40%" else "70%" chatMessageBgSaturation : if isOl then "85%" else "60%" chatMessageBgLightness : if isOl then "40%" else "97%" - editorFontFamily : if isOl then '\\"Lucida Console\\", monospace' else null - editorLineHeight : if isOl then 1.6 else null + defaultFontFamily : if isOl then 'lucida' else 'monaco' + defaultLineHeight : if isOl then 'normal' else 'compact' renderAnnouncements : !isOl next() diff --git a/services/web/app/coffee/models/User.coffee b/services/web/app/coffee/models/User.coffee index d3916ab4b0..009f582b2a 100644 --- a/services/web/app/coffee/models/User.coffee +++ b/services/web/app/coffee/models/User.coffee @@ -20,14 +20,16 @@ UserSchema = new Schema loginCount : {type : Number, default: 0} holdingAccount : {type : Boolean, default: false} ace : { - mode : {type : String, default: 'none'} - theme : {type : String, default: 'textmate'} - fontSize : {type : Number, default:'12'} - autoComplete: {type : Boolean, default: true} - autoPairDelimiters: {type : Boolean, default: true} - spellCheckLanguage : {type : String, default: "en"} - pdfViewer : {type : String, default: "pdfjs"} - syntaxValidation : {type : Boolean} + mode : {type : String, default: 'none'} + theme : {type : String, default: 'textmate'} + fontSize : {type : Number, default:'12'} + autoComplete : {type : Boolean, default: true} + autoPairDelimiters : {type : Boolean, default: true} + spellCheckLanguage : {type : String, default: "en"} + pdfViewer : {type : String, default: "pdfjs"} + syntaxValidation : {type : Boolean} + fontFamily : {type : String} + lineHeight : {type : String} } features : { collaborators: { type:Number, default: Settings.defaultFeatures.collaborators } diff --git a/services/web/app/views/project/editor/editor.pug b/services/web/app/views/project/editor/editor.pug index 084216a02e..3cac3a9490 100644 --- a/services/web/app/views/project/editor/editor.pug +++ b/services/web/app/views/project/editor/editor.pug @@ -69,8 +69,8 @@ div.full-size( track-changes= "editor.trackChanges", doc-id="editor.open_doc_id" renderer-data="reviewPanel.rendererData" - font-family="ui.editorFontFamily" - line-height="ui.editorLineHeight" + font-family="settings.fontFamily || ui.defaultFontFamily" + line-height="settings.lineHeight || ui.defaultLineHeight" ) != moduleIncludes('editor:body', locals) diff --git a/services/web/app/views/project/editor/left-menu.pug b/services/web/app/views/project/editor/left-menu.pug index bf7b9ba331..8a0018f26f 100644 --- a/services/web/app/views/project/editor/left-menu.pug +++ b/services/web/app/views/project/editor/left-menu.pug @@ -150,6 +150,26 @@ aside#left-menu.full-size( each size in ['10','11','12','13','14','16','20','24'] option(value=size) #{size}px + .form-controls + label(for="fontFamily") #{translate("font_family")} + select( + name="fontFamily" + ng-model="settings.fontFamily" + ) + option(value="", disabled) Default + each fontFamily in ['monaco', 'lucida'] + option(value=fontFamily) #{capitalize(fontFamily)} + + .form-controls + label(for="lineHeight") #{translate("line_height")} + select( + name="lineHeight" + ng-model="settings.lineHeight" + ) + option(value="", disabled) Default + each lineHeight in ['compact', 'normal', 'wide'] + option(value=lineHeight) #{translate(lineHeight)} + .form-controls label(for="pdfViewer") #{translate("pdf_viewer")} select( diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 053db2396f..7c8602eb76 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -80,8 +80,8 @@ define [ miniReviewPanelVisible: false chatResizerSizeOpen: window.uiConfig.chatResizerSizeOpen chatResizerSizeClosed: window.uiConfig.chatResizerSizeClosed - editorFontFamily: window.uiConfig.editorFontFamily - editorLineHeight: window.uiConfig.editorLineHeight + defaultFontFamily: window.uiConfig.defaultFontFamily + defaultLineHeight: window.uiConfig.defaultLineHeight } $scope.user = window.user diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index c15bc03216..ef3c5b20f8 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -283,11 +283,26 @@ define [ scope.$watch "fontFamily", (value) -> if value? - editor.setOption('fontFamily', value) + switch value + when 'monaco' + editor.setOption('fontFamily', '"Monaco", "Menlo", "Ubuntu Mono", "Consolas", "source-code-pro", monospace') + when 'lucida' + editor.setOption('fontFamily', '"Lucida Console", monospace') + else + editor.setOption('fontFamily', null) scope.$watch "lineHeight", (value) -> if value? - editor.container.style.lineHeight = value + switch value + when 'compact' + editor.container.style.lineHeight = 1.33 + when 'normal' + editor.container.style.lineHeight = 1.6 + when 'wide' + editor.container.style.lineHeight = 2 + else + editor.container.style.lineHeight = 1.6 + editor.renderer.updateFontSize() scope.$watch "sharejsDoc", (sharejs_doc, old_sharejs_doc) -> if old_sharejs_doc? diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/undo/UndoManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/undo/UndoManager.coffee index 1f53fffe52..918413d609 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/undo/UndoManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/undo/UndoManager.coffee @@ -14,9 +14,14 @@ define [ @editor.on "changeSession", (e) => @reset() - @session = e.session + # @session = e.session e.session.setUndoManager(@) + addSession: (session) -> + @session = session + + addSelection: () -> + showUndoConflictWarning: () -> @$scope.$apply () => @$scope.undo.show_remote_warning = true @@ -31,7 +36,8 @@ define [ @undoStack = [] @redoStack = [] - execute: (options) -> + add: (delta, allowMerge, session) -> + return if @firstUpdate # The first update we receive is Ace setting the document, which we should # ignore diff --git a/services/web/public/coffee/ide/settings/controllers/SettingsController.coffee b/services/web/public/coffee/ide/settings/controllers/SettingsController.coffee index df65a2f721..9920372aab 100644 --- a/services/web/public/coffee/ide/settings/controllers/SettingsController.coffee +++ b/services/web/public/coffee/ide/settings/controllers/SettingsController.coffee @@ -8,6 +8,12 @@ define [ if $scope.settings.pdfViewer not in ["pdfjs", "native"] $scope.settings.pdfViewer = "pdfjs" + if $scope.settings.fontFamily? and $scope.settings.fontFamily not in ["monaco", "lucida"] + delete $scope.settings.fontFamily + + if $scope.settings.lineHeight? and $scope.settings.lineHeight not in ["compact", "normal", "wide"] + delete $scope.settings.lineHeight + $scope.fontSizeAsStr = (newVal) -> if newVal? $scope.settings.fontSize = newVal @@ -41,6 +47,14 @@ define [ if syntaxValidation != oldSyntaxValidation settings.saveSettings({syntaxValidation: syntaxValidation}) + $scope.$watch "settings.fontFamily", (fontFamily, oldFontFamily) => + if fontFamily != oldFontFamily + settings.saveSettings({fontFamily: fontFamily}) + + $scope.$watch "settings.lineHeight", (lineHeight, oldLineHeight) => + if lineHeight != oldLineHeight + settings.saveSettings({lineHeight: lineHeight}) + $scope.$watch "project.spellCheckLanguage", (language, oldLanguage) => return if @ignoreUpdates if oldLanguage? and language != oldLanguage