@dybai/dsh-editor 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/client.js +1953 -200
- package/host/preferences-service.js +38 -10
- package/locale/en.json +20 -1
- package/locale/zh.json +20 -1
- package/package.json +1 -1
|
@@ -106,7 +106,7 @@ const WRAP_OVERRIDES_TABLE = 'wrap_overrides';
|
|
|
106
106
|
* (e.g. `wordWrap`, which then falls back to its builtin per-file default)
|
|
107
107
|
* from an explicitly stored value.
|
|
108
108
|
*/
|
|
109
|
-
const SETTINGS_KEYS = new Set(['autoReloadClean', 'highlightActiveLine', 'showLineNumbers', 'scrollBeyondLastLine', 'wordWrap']);
|
|
109
|
+
const SETTINGS_KEYS = new Set(['autoReloadClean', 'highlightActiveLine', 'showLineNumbers', 'scrollBeyondLastLine', 'wordWrap', 'showWhitespaceSpaces', 'showWhitespaceTabs', 'showWhitespaceNewlines', 'indentMode', 'indentWidth']);
|
|
110
110
|
|
|
111
111
|
/** Keymap action ids the editor framework owns (spec §6; `gotoLine` v0.6.0). */
|
|
112
112
|
const KEYMAP_ACTIONS = new Set(['save', 'saveAll', 'deleteLines', 'gotoLine']);
|
|
@@ -223,9 +223,32 @@ function isValidAssociations(associations) {
|
|
|
223
223
|
return true;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
/** Valid `indentMode` values — mirror of src/settings.js type table (0.13.0). */
|
|
227
|
+
const INDENT_MODES = new Set(['auto', 'tabs', 'spaces']);
|
|
228
|
+
/** Valid `indentWidth` values — mirror of src/settings.js type table (0.13.0). */
|
|
229
|
+
const INDENT_WIDTHS = new Set([2, 4, 8]);
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The per-key type table: whether `value` is legal for the known setting
|
|
233
|
+
* `key` — a mirror of src/settings.js type table (0.13.0), so the Host's
|
|
234
|
+
* write validation and read echo accept exactly the values the client's own
|
|
235
|
+
* validator accepts (the Host imports no client code; same values, own
|
|
236
|
+
* constants). `indentMode` is an enum, `indentWidth` is an enum of widths,
|
|
237
|
+
* every other known setting is a boolean.
|
|
238
|
+
* @param key - a known setting name (`SETTINGS_KEYS`).
|
|
239
|
+
* @param value - the value to check.
|
|
240
|
+
* @returns whether the value matches the key's type.
|
|
241
|
+
*/
|
|
242
|
+
function isValidSettingValue(key, value) {
|
|
243
|
+
if (key === 'indentMode') return INDENT_MODES.has(value);
|
|
244
|
+
if (key === 'indentWidth') return INDENT_WIDTHS.has(value);
|
|
245
|
+
return typeof value === 'boolean';
|
|
246
|
+
}
|
|
247
|
+
|
|
226
248
|
/**
|
|
227
249
|
* Validate the settings payload: a plain object whose keys are all setting
|
|
228
|
-
* names this build knows and whose values
|
|
250
|
+
* names this build knows and whose values all match their per-key type (see
|
|
251
|
+
* `isValidSettingValue`). An EMPTY object
|
|
229
252
|
* is valid — it means "reset to defaults" (full-set replace deletes every
|
|
230
253
|
* stored record). Extra/unknown keys are rejected so a typo never silently
|
|
231
254
|
* persists a setting this build would never read back.
|
|
@@ -236,7 +259,7 @@ function isValidSettings(settings) {
|
|
|
236
259
|
if (settings === null || typeof settings !== 'object' || Array.isArray(settings)) return false;
|
|
237
260
|
for (const key of Object.keys(settings)) {
|
|
238
261
|
if (!SETTINGS_KEYS.has(key)) return false;
|
|
239
|
-
if (
|
|
262
|
+
if (!isValidSettingValue(key, settings[key])) return false;
|
|
240
263
|
}
|
|
241
264
|
return true;
|
|
242
265
|
}
|
|
@@ -453,11 +476,15 @@ export function createPreferencesService({ kv, now }) {
|
|
|
453
476
|
/**
|
|
454
477
|
* Read the stored behavior settings (spec: the settings panel's
|
|
455
478
|
* toggles). Settings this build knows but storage never wrote come
|
|
456
|
-
* back absent — the client applies its own defaults;
|
|
457
|
-
*
|
|
479
|
+
* back absent — the client applies its own defaults; known keys whose
|
|
480
|
+
* record value fails the per-key type table (`isValidSettingValue`;
|
|
481
|
+
* hand edit, older bug) are ignored, and so is any unknown key that
|
|
482
|
+
* somehow reached the medium.
|
|
458
483
|
* @param signal - caller cancellation (last parameter, SRC convention).
|
|
459
|
-
* @returns `{ settings: { [name]: boolean
|
|
460
|
-
*
|
|
484
|
+
* @returns `{ settings: { [name]: boolean | 'auto'|'tabs'|'spaces' |
|
|
485
|
+
* 2|4|8 }, updatedAt }` — each echoed value matches its key's type in
|
|
486
|
+
* the per-key type table (booleans, plus the typed indent keys);
|
|
487
|
+
* `updatedAt` is the SHARED token (see the module doc).
|
|
461
488
|
*/
|
|
462
489
|
async getSettings(signal) {
|
|
463
490
|
throwIfAborted(signal);
|
|
@@ -468,7 +495,7 @@ export function createPreferencesService({ kv, now }) {
|
|
|
468
495
|
const settings = {};
|
|
469
496
|
for (const key of SETTINGS_KEYS) {
|
|
470
497
|
const record = records[key];
|
|
471
|
-
if (record !== null && typeof record === 'object' &&
|
|
498
|
+
if (record !== null && typeof record === 'object' && isValidSettingValue(key, record.value)) {
|
|
472
499
|
settings[key] = record.value;
|
|
473
500
|
}
|
|
474
501
|
}
|
|
@@ -480,8 +507,9 @@ export function createPreferencesService({ kv, now }) {
|
|
|
480
507
|
* are deleted; `{}` resets to defaults), restamping the unit's SHARED
|
|
481
508
|
* global `updatedAt`.
|
|
482
509
|
* @param settings - the complete new set (keys ⊆ known setting names,
|
|
483
|
-
* values
|
|
484
|
-
* invalid payload never
|
|
510
|
+
* values matching their per-key type, see `isValidSettingValue`);
|
|
511
|
+
* validated before the write chain, so an invalid payload never
|
|
512
|
+
* touches storage.
|
|
485
513
|
* @param expectedUpdatedAt - compare-and-set guard against the SHARED
|
|
486
514
|
* token: when provided and not equal to the storage's current
|
|
487
515
|
* `updatedAt`, the write rejects with `settings/conflict` and storage
|
package/locale/en.json
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"resetTitle": "Restore the default keys (Ctrl+S / Ctrl+Shift+S / Ctrl+D / Ctrl+G)",
|
|
61
61
|
"duplicate": "That combo is already used by another action; pick another one.",
|
|
62
62
|
"reserved": "This combination is reserved by the browser (e.g. close/new tab) and cannot be recorded",
|
|
63
|
-
"reservedHint": "Browser-reserved combos (Ctrl/⌘+W, T, N, Q,
|
|
63
|
+
"reservedHint": "Browser-reserved combos (Ctrl/⌘+W, T, N, Q, etc.) and Tab indentation cannot be recorded",
|
|
64
64
|
"writeFailed": "Failed to save shortcuts",
|
|
65
65
|
"conflict": "Shortcuts changed elsewhere; reloaded, please retry."
|
|
66
66
|
},
|
|
@@ -98,8 +98,26 @@
|
|
|
98
98
|
"showLineNumbersTitle": "Draw the line-number column beside the content",
|
|
99
99
|
"scrollBeyondLastLine": "Scroll past last line",
|
|
100
100
|
"scrollBeyondLastLineTitle": "Keep scrollable blank space past the end of content so the last line can scroll to the top of the viewport",
|
|
101
|
+
"showWhitespaceGroup": "Show whitespace",
|
|
102
|
+
"showWhitespaceSpaces": "Show spaces",
|
|
103
|
+
"showWhitespaceSpacesTitle": "Render space characters as a light middle dot (·)",
|
|
104
|
+
"showWhitespaceSpacesNote": "Global setting; applies to every mounted editor immediately. Off by default.",
|
|
105
|
+
"showWhitespaceTabs": "Show tabs",
|
|
106
|
+
"showWhitespaceTabsTitle": "Render tab characters as a light arrow (→), padded to the next stop",
|
|
107
|
+
"showWhitespaceTabsNote": "Global setting; applies to every mounted editor immediately. Off by default.",
|
|
108
|
+
"showWhitespaceNewlines": "Show newlines",
|
|
109
|
+
"showWhitespaceNewlinesTitle": "Render each line break as a light return glyph (↵) at the end of its line; the trailing newline at end of file is not drawn",
|
|
110
|
+
"showWhitespaceNewlinesNote": "Global setting; applies to every mounted editor immediately. Off by default.",
|
|
101
111
|
"wordWrap": "Word wrap",
|
|
102
112
|
"wordWrapTitle": "Wrap overly long lines within the editor width",
|
|
113
|
+
"indentMode": "Indent style",
|
|
114
|
+
"indentModeTitle": "The indent unit the Tab key inserts: auto-detect the current file / fixed tabs / fixed spaces",
|
|
115
|
+
"indentModeAuto": "Auto detect",
|
|
116
|
+
"indentModeTabs": "Tabs",
|
|
117
|
+
"indentModeSpaces": "Spaces",
|
|
118
|
+
"indentWidth": "Indent width",
|
|
119
|
+
"indentWidthTitle": "Spaces per indent level in spaces mode",
|
|
120
|
+
"indentWidthNote": "Only applies in Spaces mode; also used as the fallback width when auto detect has no signal.",
|
|
103
121
|
"on": "On",
|
|
104
122
|
"off": "Off",
|
|
105
123
|
"writeFailed": "Failed to save settings",
|
|
@@ -111,6 +129,7 @@
|
|
|
111
129
|
"section": {
|
|
112
130
|
"appearance": "Appearance",
|
|
113
131
|
"behavior": "Behavior",
|
|
132
|
+
"indent": "Indent",
|
|
114
133
|
"wrap": "Word wrap",
|
|
115
134
|
"keymap": "Shortcuts"
|
|
116
135
|
},
|
package/locale/zh.json
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"resetTitle": "把四个动作的键位恢复为默认(Ctrl+S / Ctrl+Shift+S / Ctrl+D / Ctrl+G)",
|
|
61
61
|
"duplicate": "该组合已被其他动作占用,请换一个组合。",
|
|
62
62
|
"reserved": "该组合被浏览器保留(如关闭/新建标签页),无法录制",
|
|
63
|
-
"reservedHint": "浏览器保留组合(Ctrl/⌘+W、T、N、Q
|
|
63
|
+
"reservedHint": "浏览器保留组合(Ctrl/⌘+W、T、N、Q 等)与 Tab 缩进无法录制",
|
|
64
64
|
"writeFailed": "保存快捷键失败",
|
|
65
65
|
"conflict": "快捷键已被其他位置修改,已重新读取,请重试。"
|
|
66
66
|
},
|
|
@@ -98,8 +98,26 @@
|
|
|
98
98
|
"showLineNumbersTitle": "在内容左侧显示行号列",
|
|
99
99
|
"scrollBeyondLastLine": "滚动越过最后一行",
|
|
100
100
|
"scrollBeyondLastLineTitle": "在内容末尾之后保留可滚动空白,最后一行可滚动到视口顶部",
|
|
101
|
+
"showWhitespaceGroup": "显示空白字符",
|
|
102
|
+
"showWhitespaceSpaces": "显示空格",
|
|
103
|
+
"showWhitespaceSpacesTitle": "把空格字符显示为浅色间隔号 ·",
|
|
104
|
+
"showWhitespaceSpacesNote": "全局设置,对所有已挂载编辑器立即生效;默认关闭。",
|
|
105
|
+
"showWhitespaceTabs": "显示制表符",
|
|
106
|
+
"showWhitespaceTabsTitle": "把制表符显示为浅色箭头 → 并补位到停位",
|
|
107
|
+
"showWhitespaceTabsNote": "全局设置,对所有已挂载编辑器立即生效;默认关闭。",
|
|
108
|
+
"showWhitespaceNewlines": "显示换行符",
|
|
109
|
+
"showWhitespaceNewlinesTitle": "在每个行断的行尾显示浅色回车符 ↵(文件末尾的尾随换行不显示)",
|
|
110
|
+
"showWhitespaceNewlinesNote": "全局设置,对所有已挂载编辑器立即生效;默认关闭。",
|
|
101
111
|
"wordWrap": "自动换行",
|
|
102
112
|
"wordWrapTitle": "过长的行在编辑区宽度内自动折行显示",
|
|
113
|
+
"indentMode": "缩进模式",
|
|
114
|
+
"indentModeTitle": "Tab 键插入的缩进单位:自动探测当前文件 / 固定制表符 / 固定空格",
|
|
115
|
+
"indentModeAuto": "自动探测",
|
|
116
|
+
"indentModeTabs": "制表符",
|
|
117
|
+
"indentModeSpaces": "空格",
|
|
118
|
+
"indentWidth": "缩进宽度",
|
|
119
|
+
"indentWidthTitle": "空格模式下每级缩进的空格数",
|
|
120
|
+
"indentWidthNote": "仅「空格」模式生效;自动探测无信号时也用它作回退宽度。",
|
|
103
121
|
"on": "开",
|
|
104
122
|
"off": "关",
|
|
105
123
|
"writeFailed": "保存设置失败",
|
|
@@ -111,6 +129,7 @@
|
|
|
111
129
|
"section": {
|
|
112
130
|
"appearance": "外观",
|
|
113
131
|
"behavior": "行为",
|
|
132
|
+
"indent": "缩进",
|
|
114
133
|
"wrap": "换行",
|
|
115
134
|
"keymap": "快捷键"
|
|
116
135
|
},
|