Skip to content

Commit

Permalink
feat: support more editor configuration (#704)
Browse files Browse the repository at this point in the history
* feat: support more editor configuration

* chore: remove unused i18n

* fix: update nullish check
  • Loading branch information
bytemain authored Mar 23, 2022
1 parent 021fa8d commit 14b148e
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 55 deletions.
12 changes: 12 additions & 0 deletions packages/core-browser/src/core-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ export const corePreferenceSchema: PreferenceSchema = {
enum: ['\n', '\r\n', 'auto'],
default: 'auto',
},
'files.trimFinalNewlines': {
type: 'boolean',
default: false,
},
'files.trimTrailingWhitespace': {
type: 'boolean',
default: false,
},
'files.insertFinalNewline': {
type: 'boolean',
default: false,
},
'files.autoGuessEncoding': {
type: 'boolean',
default: false,
Expand Down
6 changes: 5 additions & 1 deletion packages/core-browser/src/preferences/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export interface ISettingGroup {

export interface IPreferenceViewDesc {
id: string;
localized: string;
/**
* 为空会根据 id 来生成展示的名字
* 如:`enablePreview` -> `Enable Preview`
*/
localized?: string;
/**
* 在指定 scope 下不展示
*/
Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/browser/preference/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { IConfigurationService } from '@opensumi/monaco-editor-core/esm/vs/platf

import { IConvertedMonacoOptions } from '../types';


/**
* 计算由ConfigurationService设置值带来的monaco编辑器的属性
* @param configurationService IConfigurationService
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/browser/preference/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ const customEditorSchema: PreferenceSchemaProperties = {
'editor.previewMode': {
type: 'boolean',
default: true,
description: '%editor.configuration.previewMode%',
},
'editor.wrapTab': {
type: 'boolean',
Expand Down
7 changes: 4 additions & 3 deletions packages/i18n/src/common/en-US.lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,12 @@ export const localizationBundle = {
'preference.editor.largeFile': 'Large File Size',
'preference.editor.formatOnPaste': 'Format On Paste',
'preference.files.eol': 'Files EOL',

'keymaps.tab.name': 'Keyboard Shortcuts',

'preference.editor.wrapTab': 'Wrap Editor Tabs',
'preference.editor.enablePreviewFromCodeNavigation':
'Controls whether editors remain in preview when a code navigation is started from them. Preview editors do not keep open and are reused until explicitly set to be kept open (e.g. via double click or editing). This value is ignored when `#workbench.editor.enablePreview#` is disabled.',
'preference.editor.preferredFormatter': 'Default Formatter',
'preference.editor.previewMode': 'Preview Mode',
'editor.configuration.previewMode': 'Enable Preview Mode',
'preference.editor.fontFamily': 'Font Family',
'preference.editor.minimap': 'minimap',
'preference.editor.forceReadOnly': 'readOnly',
Expand All @@ -522,6 +521,8 @@ export const localizationBundle = {

'preference.item.notValid': '{0} is not a valid option',

'editor.configuration.enablePreviewFromCodeNavigation':
'Controls whether editors remain in preview when a code navigation is started from them. Preview editors do not keep open and are reused until explicitly set to be kept open (e.g. via double click or editing). This value is ignored when `#workbench.editor.enablePreview#` is disabled.',
'editor.configuration.wrapTab':
'Controls whether to wrap editor tabs instead of scroll mode when tabs are beyond the visible area.',
'editor.configuration.askIfDiff': 'When saving files, throw error if the file on disk has a newer version.',
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/src/common/zh-CN.lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export const localizationBundle = {
'preference.workbench.refactoringChanges.showPreviewStrategy.title': '重构确认方式',

'preference.editor.wrapTab': '编辑器 Tab 自动换行',
'preference.editor.previewMode': '使用预览模式打开',
'editor.configuration.previewMode': '使用预览模式打开',
'preference.editor.fontFamily': '字体',
'preference.editor.minimap': '显示 Minimap',
'preference.editor.forceReadOnly': '只读模式',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import { PreferenceView } from './preferences.view';
import { USER_PREFERENCE_URI } from './user-preference-provider';
import { WorkspacePreferenceProvider } from './workspace-preference-provider';


const PREF_PREVIEW_COMPONENT_ID = 'pref-preview';

@Injectable()
Expand Down
86 changes: 43 additions & 43 deletions packages/preferences/src/browser/preference-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from '@opensumi/ide-core-browser';
import { IFileServiceClient } from '@opensumi/ide-file-service';

import { toPreferenceReadableName, PreferenceSettingId } from '../common';
import { toPreferenceReadableName, PreferenceSettingId, getPreferenceItemLabel } from '../common';

import { PREFERENCE_COMMANDS } from './preference-contribution';

Expand Down Expand Up @@ -231,7 +231,7 @@ export class PreferenceSettingsService implements IPreferenceSettingsService {

const prefId = typeof pref === 'string' ? pref : pref.id;
const schema = this.schemaProvider.getPreferenceProperty(prefId);
const prefLabel = typeof pref === 'string' ? toPreferenceReadableName(pref) : localize(pref.localized);
const prefLabel = typeof pref === 'string' ? toPreferenceReadableName(pref) : getPreferenceItemLabel(pref);
const description = schema && replaceLocalizePlaceholder(schema.description);
return (
this.isContainSearchValue(prefId, search) ||
Expand Down Expand Up @@ -407,10 +407,9 @@ export const defaultSettingSections: {
{
preferences: [
// 预览模式
{ id: 'editor.previewMode', localized: 'preference.editor.previewMode' },
{ id: 'editor.previewMode' },
{
id: 'editor.enablePreviewFromCodeNavigation',
localized: 'preference.editor.enablePreviewFromCodeNavigation',
},
// 自动保存
{ id: 'editor.autoSave', localized: 'preference.editor.autoSave' },
Expand All @@ -427,46 +426,44 @@ export const defaultSettingSections: {
{ id: 'editor.fontWeight', localized: 'preference.editor.fontWeight' },
{ id: 'editor.fontFamily', localized: 'preference.editor.fontFamily' },
{ id: 'editor.lineHeight', localized: 'preference.editor.lineHeight' },
{ id: 'editor.trimAutoWhitespace' },
// 补全
{ id: 'editor.suggest.insertMode', localized: 'preference.editor.suggest.insertMode' },
{ id: 'editor.suggest.filterGraceful', localized: 'preference.editor.suggest.filterGraceful' },
{ id: 'editor.suggest.localityBonus', localized: 'preference.editor.suggest.localityBonus' },
{ id: 'editor.suggest.shareSuggestSelections', localized: 'preference.editor.suggest.shareSuggestSelections' },
{
id: 'editor.suggest.snippetsPreventQuickSuggestions',
localized: 'preference.editor.suggest.snippetsPreventQuickSuggestions',
},
{ id: 'editor.suggest.showIcons', localized: 'preference.editor.suggest.showIcons' },
{ id: 'editor.suggest.maxVisibleSuggestions', localized: 'preference.editor.suggest.maxVisibleSuggestions' },
{ id: 'editor.suggest.showMethods', localized: 'preference.editor.suggest.showMethods' },
{ id: 'editor.suggest.showFunctions', localized: 'preference.editor.suggest.showFunctions' },
{ id: 'editor.suggest.showConstructors', localized: 'preference.editor.suggest.showConstructors' },
{ id: 'editor.suggest.showFields', localized: 'preference.editor.suggest.showFields' },
{ id: 'editor.suggest.showVariables', localized: 'preference.editor.suggest.showVariables' },
{ id: 'editor.suggest.showClasses', localized: 'preference.editor.suggest.showClasses' },
{ id: 'editor.suggest.showStructs', localized: 'preference.editor.suggest.showStructs' },
{ id: 'editor.suggest.showInterfaces', localized: 'preference.editor.suggest.showInterfaces' },
{ id: 'editor.suggest.showModules', localized: 'preference.editor.suggest.showModules' },
{ id: 'editor.suggest.showProperties', localized: 'preference.editor.suggest.showProperties' },
{ id: 'editor.suggest.showEvents', localized: 'preference.editor.suggest.showEvents' },
{ id: 'editor.suggest.showOperators', localized: 'preference.editor.suggest.showOperators' },
{ id: 'editor.suggest.showUnits', localized: 'preference.editor.suggest.showUnits' },
{ id: 'editor.suggest.showValues', localized: 'preference.editor.suggest.showValues' },
{ id: 'editor.suggest.showConstants', localized: 'preference.editor.suggest.showConstants' },
{ id: 'editor.suggest.showEnums', localized: 'preference.editor.suggest.showEnums' },
{ id: 'editor.suggest.showEnumMembers', localized: 'preference.editor.suggest.showEnumMembers' },
{ id: 'editor.suggest.showKeywords', localized: 'preference.editor.suggest.showKeywords' },
{ id: 'editor.suggest.showWords', localized: 'preference.editor.suggest.showWords' },
{ id: 'editor.suggest.showColors', localized: 'preference.editor.suggest.showColors' },
{ id: 'editor.suggest.showFiles', localized: 'preference.editor.suggest.showFiles' },
{ id: 'editor.suggest.showReferences', localized: 'preference.editor.suggest.showReferences' },
{ id: 'editor.suggest.showCustomcolors', localized: 'preference.editor.suggest.showCustomcolors' },
{ id: 'editor.suggest.showFolders', localized: 'preference.editor.suggest.showFolders' },
{ id: 'editor.suggest.showTypeParameters', localized: 'preference.editor.suggest.showTypeParameters' },
{ id: 'editor.suggest.showSnippets', localized: 'preference.editor.suggest.showSnippets' },
{ id: 'editor.suggest.showUsers', localized: 'preference.editor.suggest.showUsers' },
{ id: 'editor.suggest.showIssues', localized: 'preference.editor.suggest.showIssues' },
{ id: 'editor.suggest.preview', localized: 'preference.editor.suggest.preview' },
{ id: 'editor.suggest.insertMode' },
{ id: 'editor.suggest.filterGraceful' },
{ id: 'editor.suggest.localityBonus' },
{ id: 'editor.suggest.shareSuggestSelections' },
{ id: 'editor.suggest.snippetsPreventQuickSuggestions' },
{ id: 'editor.suggest.showIcons' },
{ id: 'editor.suggest.maxVisibleSuggestions' },
{ id: 'editor.suggest.showMethods' },
{ id: 'editor.suggest.showFunctions' },
{ id: 'editor.suggest.showConstructors' },
{ id: 'editor.suggest.showFields' },
{ id: 'editor.suggest.showVariables' },
{ id: 'editor.suggest.showClasses' },
{ id: 'editor.suggest.showStructs' },
{ id: 'editor.suggest.showInterfaces' },
{ id: 'editor.suggest.showModules' },
{ id: 'editor.suggest.showProperties' },
{ id: 'editor.suggest.showEvents' },
{ id: 'editor.suggest.showOperators' },
{ id: 'editor.suggest.showUnits' },
{ id: 'editor.suggest.showValues' },
{ id: 'editor.suggest.showConstants' },
{ id: 'editor.suggest.showEnums' },
{ id: 'editor.suggest.showEnumMembers' },
{ id: 'editor.suggest.showKeywords' },
{ id: 'editor.suggest.showWords' },
{ id: 'editor.suggest.showColors' },
{ id: 'editor.suggest.showFiles' },
{ id: 'editor.suggest.showReferences' },
{ id: 'editor.suggest.showCustomcolors' },
{ id: 'editor.suggest.showFolders' },
{ id: 'editor.suggest.showTypeParameters' },
{ id: 'editor.suggest.showSnippets' },
{ id: 'editor.suggest.showUsers' },
{ id: 'editor.suggest.showIssues' },
{ id: 'editor.suggest.preview' },

// Guides
{ id: 'editor.guides.bracketPairs', localized: 'preference.editor.guides.bracketPairs' },
Expand Down Expand Up @@ -502,6 +499,9 @@ export const defaultSettingSections: {
{ id: 'files.autoGuessEncoding', localized: 'preference.files.autoGuessEncoding.title' },
{ id: 'files.encoding', localized: 'preference.files.encoding.title' },
{ id: 'files.eol', localized: 'preference.files.eol' },
{ id: 'files.trimFinalNewlines' },
{ id: 'files.trimTrailingWhitespace' },
{ id: 'files.insertFinalNewline' },
{ id: 'editor.readonlyFiles', localized: 'preference.editor.readonlyFiles' },
{ id: 'files.exclude', localized: 'preference.files.exclude.title' },
{ id: 'files.watcherExclude', localized: 'preference.files.watcherExclude.title' },
Expand Down
5 changes: 2 additions & 3 deletions packages/preferences/src/browser/preferenceItem.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import {
formatLocalize,
} from '@opensumi/ide-core-browser';

import { toPreferenceReadableName } from '../common';
import { toPreferenceReadableName, getPreferenceItemLabel } from '../common';

import { PreferenceSettingsService } from './preference-settings.service';
import styles from './preferences.module.less';


interface IPreferenceItemProps {
preferenceName: string;
localizedName?: string;
Expand Down Expand Up @@ -175,7 +174,7 @@ const renderDescriptionExpression = (des: string) => {
const { 0: expression, 1: preferenceId } = match;
const preference = preferenceSettingService.getSectionByPreferenceId(preferenceId);
if (preference) {
const preferenceTitle = localize(preference.localized);
const preferenceTitle = getPreferenceItemLabel(preference);
const others: any[] = description
.split(expression)
.map((des: string, index: number) => <span key={`${preferenceId}-${index}`}>{des}</span>);
Expand Down
2 changes: 1 addition & 1 deletion packages/preferences/src/browser/preferences.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const PreferenceItem = ({ data, index }: { data: ISectionItemData; index:
<NextPreferenceItem
key={`${index} - ${data.preference.id} - ${data.scope}`}
preferenceName={data.preference.id}
localizedName={localize(data.preference.localized)}
localizedName={data.preference.localized ? localize(data.preference.localized) : ''}
scope={data.scope}
/>
);
Expand Down
11 changes: 10 additions & 1 deletion packages/preferences/src/common/preference.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IPreferenceViewDesc, localize } from '@opensumi/ide-core-browser';

export const PREF_SCHEME = 'pref';

export function toPreferenceReadableName(name) {
export function toPreferenceReadableName(name: string) {
const parts = name.split('.');
let result = toNormalCase(parts[0]);
if (parts[1]) {
Expand All @@ -12,6 +14,13 @@ export function toPreferenceReadableName(name) {
return result;
}

export function getPreferenceItemLabel(pref: IPreferenceViewDesc) {
if (pref.localized) {
return localize(pref.localized);
}
return toPreferenceReadableName(pref.id);
}

export function toNormalCase(str: string) {
return str.substr(0, 1).toUpperCase() + str.substr(1).replace(/([^A-Z])([A-Z])/g, '$1 $2');
}

0 comments on commit 14b148e

Please sign in to comment.