diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-29 18:08:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-29 18:08:47 +0000 |
commit | 6b9d3a4e8351e662c4586b24bb152de78ae9e3bf (patch) | |
tree | 883e9db60c047c54418fc1d2b1c5517f97e0f185 /app/assets | |
parent | 23288f62da73fb0e30d8e7ce306665e8fda1b932 (diff) | |
download | gitlab-ce-6b9d3a4e8351e662c4586b24bb152de78ae9e3bf.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/editor/editor_lite.js | 68 | ||||
-rw-r--r-- | app/assets/javascripts/editor/utils.js | 11 | ||||
-rw-r--r-- | app/assets/javascripts/ide/lib/editor.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/vue_shared/components/changed_file_icon.vue | 18 | ||||
-rw-r--r-- | app/assets/stylesheets/pages/tree.scss | 4 |
5 files changed, 86 insertions, 24 deletions
diff --git a/app/assets/javascripts/editor/editor_lite.js b/app/assets/javascripts/editor/editor_lite.js new file mode 100644 index 00000000000..bdfbcf71267 --- /dev/null +++ b/app/assets/javascripts/editor/editor_lite.js @@ -0,0 +1,68 @@ +import { editor as monacoEditor, languages as monacoLanguages, Uri } from 'monaco-editor'; +import gitlabTheme from '~/ide/lib/themes/gl_theme'; +import { defaultEditorOptions } from '~/ide/lib/editor_options'; +import { clearDomElement } from './utils'; + +export default class Editor { + constructor(options = {}) { + this.editorEl = null; + this.blobContent = ''; + this.blobPath = ''; + this.instance = null; + this.model = null; + this.options = { + ...defaultEditorOptions, + ...options, + }; + + Editor.setupMonacoTheme(); + } + + static setupMonacoTheme() { + monacoEditor.defineTheme(gitlabTheme.themeName, gitlabTheme.monacoTheme); + monacoEditor.setTheme('gitlab'); + } + + createInstance({ el = undefined, blobPath = '', blobContent = '' } = {}) { + if (!el) return; + this.editorEl = el; + this.blobContent = blobContent; + this.blobPath = blobPath; + + clearDomElement(this.editorEl); + + this.model = monacoEditor.createModel( + this.blobContent, + undefined, + new Uri('gitlab', false, this.blobPath), + ); + + monacoEditor.onDidCreateEditor(this.renderEditor.bind(this)); + + this.instance = monacoEditor.create(this.editorEl, this.options); + this.instance.setModel(this.model); + } + + dispose() { + return this.instance && this.instance.dispose(); + } + + renderEditor() { + delete this.editorEl.dataset.editorLoading; + } + + updateModelLanguage(path) { + if (path === this.blobPath) return; + this.blobPath = path; + const ext = `.${path.split('.').pop()}`; + const language = monacoLanguages + .getLanguages() + .find(lang => lang.extensions.indexOf(ext) !== -1); + const id = language ? language.id : 'plaintext'; + monacoEditor.setModelLanguage(this.model, id); + } + + getValue() { + return this.model.getValue(); + } +} diff --git a/app/assets/javascripts/editor/utils.js b/app/assets/javascripts/editor/utils.js new file mode 100644 index 00000000000..d8b6396b671 --- /dev/null +++ b/app/assets/javascripts/editor/utils.js @@ -0,0 +1,11 @@ +export const clearDomElement = el => { + if (!el || !el.firstChild) return; + + while (el.firstChild) { + el.removeChild(el.firstChild); + } +}; + +export default () => ({ + clearDomElement, +}); diff --git a/app/assets/javascripts/ide/lib/editor.js b/app/assets/javascripts/ide/lib/editor.js index d1056ea6b98..a0f689065aa 100644 --- a/app/assets/javascripts/ide/lib/editor.js +++ b/app/assets/javascripts/ide/lib/editor.js @@ -8,20 +8,13 @@ import ModelManager from './common/model_manager'; import editorOptions, { defaultEditorOptions } from './editor_options'; import gitlabTheme from './themes/gl_theme'; import keymap from './keymap.json'; +import { clearDomElement } from '~/editor/utils'; function setupMonacoTheme() { monacoEditor.defineTheme(gitlabTheme.themeName, gitlabTheme.monacoTheme); monacoEditor.setTheme('gitlab'); } -export const clearDomElement = el => { - if (!el || !el.firstChild) return; - - while (el.firstChild) { - el.removeChild(el.firstChild); - } -}; - export default class Editor { static create(options = {}) { if (!this.editorInstance) { diff --git a/app/assets/javascripts/vue_shared/components/changed_file_icon.vue b/app/assets/javascripts/vue_shared/components/changed_file_icon.vue index 75c3c544c77..9ec99ac93d7 100644 --- a/app/assets/javascripts/vue_shared/components/changed_file_icon.vue +++ b/app/assets/javascripts/vue_shared/components/changed_file_icon.vue @@ -41,7 +41,7 @@ export default { changedIcon() { // False positive i18n lint: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26 // eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings - const suffix = !this.file.changed && this.file.staged && this.showStagedIcon ? '-solid' : ''; + const suffix = this.file.staged && this.showStagedIcon ? '-solid' : ''; return `${getCommitIconMap(this.file).icon}${suffix}`; }, @@ -49,25 +49,19 @@ export default { return `${this.changedIcon} float-left d-block`; }, tooltipTitle() { - if (!this.showTooltip) return undefined; + if (!this.showTooltip || !this.file.changed) return undefined; const type = this.file.tempFile ? 'addition' : 'modification'; - if (this.file.changed && !this.file.staged) { - return sprintf(__('Unstaged %{type}'), { - type, - }); - } else if (!this.file.changed && this.file.staged) { + if (this.file.staged) { return sprintf(__('Staged %{type}'), { type, }); - } else if (this.file.changed && this.file.staged) { - return sprintf(__('Unstaged and staged %{type}'), { - type, - }); } - return undefined; + return sprintf(__('Unstaged %{type}'), { + type, + }); }, showIcon() { return ( diff --git a/app/assets/stylesheets/pages/tree.scss b/app/assets/stylesheets/pages/tree.scss index 79ad0bd7735..c14ae8a3711 100644 --- a/app/assets/stylesheets/pages/tree.scss +++ b/app/assets/stylesheets/pages/tree.scss @@ -21,10 +21,6 @@ margin-left: 8px; } - .btn-group { - margin-left: 10px; - } - .control { float: left; margin-left: 10px; |