Commit c10e3d61 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'ide_render_whitespaces' into 'master'

Ide render whitespaces

See merge request gitlab-org/gitlab!17244
parents 887dd2b1 7d7737a3
...@@ -32,7 +32,13 @@ export default { ...@@ -32,7 +32,13 @@ export default {
...mapState('rightPane', { ...mapState('rightPane', {
rightPaneIsOpen: 'isOpen', rightPaneIsOpen: 'isOpen',
}), }),
...mapState(['rightPanelCollapsed', 'viewer', 'panelResizing', 'currentActivityView']), ...mapState([
'rightPanelCollapsed',
'viewer',
'panelResizing',
'currentActivityView',
'renderWhitespaceInCode',
]),
...mapGetters([ ...mapGetters([
'currentMergeRequest', 'currentMergeRequest',
'getStagedFile', 'getStagedFile',
...@@ -76,6 +82,11 @@ export default { ...@@ -76,6 +82,11 @@ export default {
showEditor() { showEditor() {
return !this.shouldHideEditor && this.isEditorViewMode; return !this.shouldHideEditor && this.isEditorViewMode;
}, },
editorOptions() {
return {
renderWhitespace: this.renderWhitespaceInCode ? 'all' : 'none',
};
},
}, },
watch: { watch: {
file(newVal, oldVal) { file(newVal, oldVal) {
...@@ -131,7 +142,7 @@ export default { ...@@ -131,7 +142,7 @@ export default {
}, },
mounted() { mounted() {
if (!this.editor) { if (!this.editor) {
this.editor = Editor.create(); this.editor = Editor.create(this.editorOptions);
} }
this.initEditor(); this.initEditor();
}, },
......
...@@ -50,6 +50,7 @@ export function initIde(el, options = {}) { ...@@ -50,6 +50,7 @@ export function initIde(el, options = {}) {
}); });
this.setInitialData({ this.setInitialData({
clientsidePreviewEnabled: parseBoolean(el.dataset.clientsidePreviewEnabled), clientsidePreviewEnabled: parseBoolean(el.dataset.clientsidePreviewEnabled),
renderWhitespaceInCode: parseBoolean(el.dataset.renderWhitespaceInCode),
}); });
}, },
methods: { methods: {
......
...@@ -23,20 +23,24 @@ export const clearDomElement = el => { ...@@ -23,20 +23,24 @@ export const clearDomElement = el => {
}; };
export default class Editor { export default class Editor {
static create() { static create(options = {}) {
if (!this.editorInstance) { if (!this.editorInstance) {
this.editorInstance = new Editor(); this.editorInstance = new Editor(options);
} }
return this.editorInstance; return this.editorInstance;
} }
constructor() { constructor(options = {}) {
this.currentModel = null; this.currentModel = null;
this.instance = null; this.instance = null;
this.dirtyDiffController = null; this.dirtyDiffController = null;
this.disposable = new Disposable(); this.disposable = new Disposable();
this.modelManager = new ModelManager(); this.modelManager = new ModelManager();
this.decorationsController = new DecorationsController(this); this.decorationsController = new DecorationsController(this);
this.options = {
...defaultEditorOptions,
...options,
};
setupMonacoTheme(); setupMonacoTheme();
...@@ -51,7 +55,7 @@ export default class Editor { ...@@ -51,7 +55,7 @@ export default class Editor {
this.disposable.add( this.disposable.add(
(this.instance = monacoEditor.create(domElement, { (this.instance = monacoEditor.create(domElement, {
...defaultEditorOptions, ...this.options,
})), })),
(this.dirtyDiffController = new DirtyDiffController( (this.dirtyDiffController = new DirtyDiffController(
this.modelManager, this.modelManager,
...@@ -71,7 +75,7 @@ export default class Editor { ...@@ -71,7 +75,7 @@ export default class Editor {
this.disposable.add( this.disposable.add(
(this.instance = monacoEditor.createDiffEditor(domElement, { (this.instance = monacoEditor.createDiffEditor(domElement, {
...defaultEditorOptions, ...this.options,
quickSuggestions: false, quickSuggestions: false,
occurrencesHighlight: false, occurrencesHighlight: false,
renderSideBySide: Editor.renderSideBySide(domElement), renderSideBySide: Editor.renderSideBySide(domElement),
......
...@@ -31,4 +31,5 @@ export default () => ({ ...@@ -31,4 +31,5 @@ export default () => ({
entry: {}, entry: {},
}, },
clientsidePreviewEnabled: false, clientsidePreviewEnabled: false,
renderWhitespaceInCode: false,
}); });
...@@ -48,7 +48,8 @@ class Profiles::PreferencesController < Profiles::ApplicationController ...@@ -48,7 +48,8 @@ class Profiles::PreferencesController < Profiles::ApplicationController
:time_display_relative, :time_display_relative,
:time_format_in_24h, :time_format_in_24h,
:show_whitespace_in_diffs, :show_whitespace_in_diffs,
:sourcegraph_enabled :sourcegraph_enabled,
:render_whitespace_in_code
] ]
end end
end end
......
...@@ -10,7 +10,8 @@ module IdeHelper ...@@ -10,7 +10,8 @@ module IdeHelper
"promotion-svg-path": image_path('illustrations/web-ide_promotion.svg'), "promotion-svg-path": image_path('illustrations/web-ide_promotion.svg'),
"ci-help-page-path" => help_page_path('ci/quick_start/README'), "ci-help-page-path" => help_page_path('ci/quick_start/README'),
"web-ide-help-page-path" => help_page_path('user/project/web_ide/index.html'), "web-ide-help-page-path" => help_page_path('user/project/web_ide/index.html'),
"clientside-preview-enabled": Gitlab::CurrentSettings.current_application_settings.web_ide_clientside_preview_enabled.to_s "clientside-preview-enabled": Gitlab::CurrentSettings.current_application_settings.web_ide_clientside_preview_enabled.to_s,
"render-whitespace-in-code": current_user.render_whitespace_in_code.to_s
} }
end end
end end
...@@ -246,6 +246,7 @@ class User < ApplicationRecord ...@@ -246,6 +246,7 @@ class User < ApplicationRecord
delegate :show_whitespace_in_diffs, :show_whitespace_in_diffs=, to: :user_preference delegate :show_whitespace_in_diffs, :show_whitespace_in_diffs=, to: :user_preference
delegate :sourcegraph_enabled, :sourcegraph_enabled=, to: :user_preference delegate :sourcegraph_enabled, :sourcegraph_enabled=, to: :user_preference
delegate :setup_for_company, :setup_for_company=, to: :user_preference delegate :setup_for_company, :setup_for_company=, to: :user_preference
delegate :render_whitespace_in_code, :render_whitespace_in_code=, to: :user_preference
accepts_nested_attributes_for :user_preference, update_only: true accepts_nested_attributes_for :user_preference, update_only: true
......
...@@ -13,6 +13,7 @@ class UserPreference < ApplicationRecord ...@@ -13,6 +13,7 @@ class UserPreference < ApplicationRecord
default_value_for :timezone, value: Time.zone.tzinfo.name, allows_nil: false default_value_for :timezone, value: Time.zone.tzinfo.name, allows_nil: false
default_value_for :time_display_relative, value: true, allows_nil: false default_value_for :time_display_relative, value: true, allows_nil: false
default_value_for :time_format_in_24h, value: false, allows_nil: false default_value_for :time_format_in_24h, value: false, allows_nil: false
default_value_for :render_whitespace_in_code, value: false, allows_nil: false
class << self class << self
def notes_filters def notes_filters
......
...@@ -61,10 +61,14 @@ ...@@ -61,10 +61,14 @@
= f.select :project_view, project_view_choices, {}, class: 'select2' = f.select :project_view, project_view_choices, {}, class: 'select2'
.form-text.text-muted .form-text.text-muted
= s_('Preferences|Choose what content you want to see on a project’s overview page.') = s_('Preferences|Choose what content you want to see on a project’s overview page.')
.form-group.form-check
= f.check_box :render_whitespace_in_code, class: 'form-check-input'
= f.label :render_whitespace_in_code, class: 'form-check-label' do
= s_('Preferences|Render whitespace characters in the Web IDE')
.form-group.form-check .form-group.form-check
= f.check_box :show_whitespace_in_diffs, class: 'form-check-input' = f.check_box :show_whitespace_in_diffs, class: 'form-check-input'
= f.label :show_whitespace_in_diffs, class: 'form-check-label' do = f.label :show_whitespace_in_diffs, class: 'form-check-label' do
= s_('Preferences|Show whitespace in diffs') = s_('Preferences|Show whitespace changes in diffs')
.col-sm-12 .col-sm-12
%hr %hr
......
---
title: Render whitespaces in code
merge_request: 17244
author: Mathieu Parent
type: added
# frozen_string_literal: true
class AddRenderWhitespaceInCodeToUserPreference < ActiveRecord::Migration[5.1]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column(:user_preferences, :render_whitespace_in_code, :boolean)
end
def down
remove_column(:user_preferences, :render_whitespace_in_code)
end
end
...@@ -4038,6 +4038,7 @@ ActiveRecord::Schema.define(version: 2020_01_02_170221) do ...@@ -4038,6 +4038,7 @@ ActiveRecord::Schema.define(version: 2020_01_02_170221) do
t.boolean "show_whitespace_in_diffs", default: true, null: false t.boolean "show_whitespace_in_diffs", default: true, null: false
t.boolean "sourcegraph_enabled" t.boolean "sourcegraph_enabled"
t.boolean "setup_for_company" t.boolean "setup_for_company"
t.boolean "render_whitespace_in_code"
t.index ["user_id"], name: "index_user_preferences_on_user_id", unique: true t.index ["user_id"], name: "index_user_preferences_on_user_id", unique: true
end end
......
...@@ -13299,7 +13299,10 @@ msgstr "" ...@@ -13299,7 +13299,10 @@ msgstr ""
msgid "Preferences|Project overview content" msgid "Preferences|Project overview content"
msgstr "" msgstr ""
msgid "Preferences|Show whitespace in diffs" msgid "Preferences|Render whitespace characters in the Web IDE"
msgstr ""
msgid "Preferences|Show whitespace changes in diffs"
msgstr "" msgstr ""
msgid "Preferences|Sourcegraph" msgid "Preferences|Sourcegraph"
......
...@@ -46,7 +46,8 @@ describe Profiles::PreferencesController do ...@@ -46,7 +46,8 @@ describe Profiles::PreferencesController do
dashboard: 'stars', dashboard: 'stars',
theme_id: '2', theme_id: '2',
first_day_of_week: '1', first_day_of_week: '1',
preferred_language: 'jp' preferred_language: 'jp',
render_whitespace_in_code: 'true'
}.with_indifferent_access }.with_indifferent_access
expect(user).to receive(:assign_attributes).with(ActionController::Parameters.new(prefs).permit!) expect(user).to receive(:assign_attributes).with(ActionController::Parameters.new(prefs).permit!)
......
...@@ -86,6 +86,23 @@ describe 'User visits the profile preferences page' do ...@@ -86,6 +86,23 @@ describe 'User visits the profile preferences page' do
end end
end end
describe 'User changes whitespace in code' do
it 'updates their preference' do
expect(user.render_whitespace_in_code).to be(false)
expect(render_whitespace_field).not_to be_checked
render_whitespace_field.click
click_button 'Save changes'
expect(user.reload.render_whitespace_in_code).to be(true)
expect(render_whitespace_field).to be_checked
end
end
def render_whitespace_field
find_field('user[render_whitespace_in_code]')
end
def expect_preferences_saved_message def expect_preferences_saved_message
page.within('.flash-container') do page.within('.flash-container') do
expect(page).to have_content('Preferences saved.') expect(page).to have_content('Preferences saved.')
......
...@@ -52,6 +52,18 @@ describe('RepoEditor', () => { ...@@ -52,6 +52,18 @@ describe('RepoEditor', () => {
state.rightPanelCollapsed = !state.rightPanelCollapsed; state.rightPanelCollapsed = !state.rightPanelCollapsed;
}; };
it('sets renderWhitespace to `all`', () => {
vm.$store.state.renderWhitespaceInCode = true;
expect(vm.editorOptions.renderWhitespace).toEqual('all');
});
it('sets renderWhitespace to `none`', () => {
vm.$store.state.renderWhitespaceInCode = false;
expect(vm.editorOptions.renderWhitespace).toEqual('none');
});
it('renders an ide container', () => { it('renders an ide container', () => {
expect(vm.shouldHideEditor).toBeFalsy(); expect(vm.shouldHideEditor).toBeFalsy();
expect(vm.showEditor).toBe(true); expect(vm.showEditor).toBe(true);
......
...@@ -67,6 +67,7 @@ describe('Multi-file editor library', () => { ...@@ -67,6 +67,7 @@ describe('Multi-file editor library', () => {
}, },
readOnly: true, readOnly: true,
scrollBeyondLastLine: false, scrollBeyondLastLine: false,
renderWhitespace: 'none',
quickSuggestions: false, quickSuggestions: false,
occurrencesHighlight: false, occurrencesHighlight: false,
wordWrap: 'on', wordWrap: 'on',
......
...@@ -12,6 +12,16 @@ describe 'profiles/preferences/show' do ...@@ -12,6 +12,16 @@ describe 'profiles/preferences/show' do
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
end end
context 'behavior' do
before do
render
end
it 'has option for Render whitespace characters in the Web IDE' do
expect(rendered).to have_unchecked_field('Render whitespace characters in the Web IDE')
end
end
context 'sourcegraph' do context 'sourcegraph' do
def have_sourcegraph_field(*args) def have_sourcegraph_field(*args)
have_field('user_sourcegraph_enabled', *args) have_field('user_sourcegraph_enabled', *args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment