Skip to content

Commit ca99f60

Browse files
committed
improve(settings): use numeric input for long-press duration
1 parent 1d4ea27 commit ca99f60

3 files changed

Lines changed: 31 additions & 15 deletions

File tree

src/i18n/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const en: ZhCnStrings = {
4343
multiLineSelection: 'Multi-line selection',
4444
multiLineSelectionDesc: 'Disable to keep single-block drag only',
4545
multiLineSelectionLongPressMs: 'Multi-line selection long-press duration',
46-
multiLineSelectionLongPressMsDesc: 'On mobile, hold for this duration before entering multi-block selection mode',
46+
multiLineSelectionLongPressMsDesc: 'Enter milliseconds (300-2000). On mobile, hold for this duration before entering multi-block selection mode',
4747
mobileTextLongPressDrag: 'Mobile text long-press drag',
4848
mobileTextLongPressDragDesc: 'On mobile, long-press a text line or rendered block content to drag the current block directly without using the left handle',
4949
enableCrossFileDrag: 'Cross-file drag',

src/i18n/zh-cn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const zhCn = {
4949
multiLineSelection: '多行选取',
5050
multiLineSelectionDesc: '关闭后仅保留单块拖拽,不进入多行选取流程',
5151
multiLineSelectionLongPressMs: '多选模式长按时长',
52-
multiLineSelectionLongPressMsDesc: '移动端长按多少毫秒后进入多文本块选择模式',
52+
multiLineSelectionLongPressMsDesc: '输入毫秒数(300-2000),移动端长按达到该时长后进入多文本块选择模式',
5353
mobileTextLongPressDrag: '移动端文本长按拖拽',
5454
mobileTextLongPressDragDesc: '移动端在文本整行或块内容区域长按可直接拖拽当前块,无需左侧手柄',
5555
enableCrossFileDrag: '跨文件拖拽',

src/settings.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export type {
1818
export const DEFAULT_MULTI_LINE_SELECTION_LONG_PRESS_MS = 900;
1919
const MIN_MULTI_LINE_SELECTION_LONG_PRESS_MS = 300;
2020
const MAX_MULTI_LINE_SELECTION_LONG_PRESS_MS = 2000;
21-
const MULTI_LINE_SELECTION_LONG_PRESS_STEP_MS = 50;
2221

2322
export function normalizeMultiLineSelectionLongPressMs(value: unknown): number {
2423
if (typeof value !== 'number' || !Number.isFinite(value)) {
@@ -223,19 +222,36 @@ export class DragNDropSettingTab extends PluginSettingTab {
223222
new Setting(containerEl)
224223
.setName(i.multiLineSelectionLongPressMs)
225224
.setDesc(i.multiLineSelectionLongPressMsDesc)
226-
.addSlider((slider) => slider
227-
.setLimits(
228-
MIN_MULTI_LINE_SELECTION_LONG_PRESS_MS,
229-
MAX_MULTI_LINE_SELECTION_LONG_PRESS_MS,
230-
MULTI_LINE_SELECTION_LONG_PRESS_STEP_MS,
231-
)
232-
.setDynamicTooltip()
233-
.setValue(this.plugin.settings.multiLineSelectionLongPressMs)
234-
.onChange(async (value) => {
235-
this.plugin.settings.multiLineSelectionLongPressMs =
236-
normalizeMultiLineSelectionLongPressMs(value);
225+
.addText((text) => {
226+
const commit = async () => {
227+
const normalized = normalizeMultiLineSelectionLongPressMs(Number(text.inputEl.value));
228+
const normalizedValue = String(normalized);
229+
if (text.inputEl.value !== normalizedValue) {
230+
text.setValue(normalizedValue);
231+
}
232+
if (this.plugin.settings.multiLineSelectionLongPressMs === normalized) {
233+
return;
234+
}
235+
this.plugin.settings.multiLineSelectionLongPressMs = normalized;
237236
await this.plugin.saveSettings();
238-
}));
237+
};
238+
239+
text.inputEl.type = 'number';
240+
text.inputEl.inputMode = 'numeric';
241+
text.inputEl.min = String(MIN_MULTI_LINE_SELECTION_LONG_PRESS_MS);
242+
text.inputEl.max = String(MAX_MULTI_LINE_SELECTION_LONG_PRESS_MS);
243+
text.inputEl.step = '1';
244+
text.setPlaceholder(`${MIN_MULTI_LINE_SELECTION_LONG_PRESS_MS}-${MAX_MULTI_LINE_SELECTION_LONG_PRESS_MS}`);
245+
text.setValue(String(this.plugin.settings.multiLineSelectionLongPressMs));
246+
text.inputEl.addEventListener('blur', () => {
247+
void commit();
248+
});
249+
text.inputEl.addEventListener('keydown', (event: KeyboardEvent) => {
250+
if (event.key !== 'Enter') return;
251+
event.preventDefault();
252+
text.inputEl.blur();
253+
});
254+
});
239255

240256
new Setting(containerEl)
241257
.setName(i.mobileTextLongPressDrag)

0 commit comments

Comments
 (0)