clideck 1.30.8 → 1.30.9
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "trim-clip",
|
|
3
3
|
"name": "Trim Clip",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"author": "CliDeck",
|
|
6
6
|
"description": "Copy selected terminal text with trailing whitespace trimmed",
|
|
7
7
|
"icon": "<svg class=\"w-4 h-4\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"6\" cy=\"6\" r=\"3\"/><circle cx=\"6\" cy=\"18\" r=\"3\"/><line x1=\"20\" y1=\"4\" x2=\"8.12\" y2=\"15.88\"/><line x1=\"14.47\" y1=\"14.48\" x2=\"20\" y2=\"20\"/><line x1=\"8.12\" y1=\"8.12\" x2=\"12\" y2=\"12\"/></svg>",
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
"label": "Enabled",
|
|
12
12
|
"type": "toggle",
|
|
13
13
|
"default": true
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"key": "hotkey",
|
|
17
|
+
"label": "Trim Key",
|
|
18
|
+
"type": "text",
|
|
19
|
+
"default": "F8",
|
|
20
|
+
"description": "Key to copy selected terminal text with whitespace trimmed (e.g. F8, Ctrl+Shift+C)"
|
|
14
21
|
}
|
|
15
22
|
]
|
|
16
23
|
}
|
|
@@ -1,31 +1,53 @@
|
|
|
1
1
|
let enabled = true;
|
|
2
2
|
let btnEl = null;
|
|
3
|
+
let apiRef = null;
|
|
4
|
+
let currentHotkey = null;
|
|
5
|
+
|
|
6
|
+
async function trimAndCopy() {
|
|
7
|
+
if (!enabled) return;
|
|
8
|
+
const text = apiRef.getTerminalSelection();
|
|
9
|
+
if (!text || !text.trim()) { apiRef.toast('Select text to copy & trim', { type: 'warn' }); return; }
|
|
10
|
+
const trimmed = text
|
|
11
|
+
.split('\n')
|
|
12
|
+
.map(l => l.trimEnd())
|
|
13
|
+
.join('\n')
|
|
14
|
+
.replace(/^\n+/, '').replace(/\n+$/, '');
|
|
15
|
+
try {
|
|
16
|
+
await navigator.clipboard.writeText(trimmed);
|
|
17
|
+
const saved = text.length - trimmed.length;
|
|
18
|
+
apiRef.toast(saved ? `Copied & trimmed ${saved} char${saved !== 1 ? 's' : ''}` : 'Copied', { type: 'success' });
|
|
19
|
+
} catch {
|
|
20
|
+
apiRef.toast('Clipboard access denied — allow it in browser site settings', { type: 'error' });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function bindHotkey(hotkey) {
|
|
25
|
+
const next = hotkey || 'F8';
|
|
26
|
+
if (next === currentHotkey) return;
|
|
27
|
+
const prev = currentHotkey;
|
|
28
|
+
if (prev) apiRef.unregisterHotkey(prev);
|
|
29
|
+
if (apiRef.registerHotkey(next, trimAndCopy)) {
|
|
30
|
+
currentHotkey = next;
|
|
31
|
+
} else if (prev) {
|
|
32
|
+
apiRef.registerHotkey(prev, trimAndCopy);
|
|
33
|
+
apiRef.toast(`Hotkey "${next}" is taken, keeping "${prev}"`, { type: 'warn' });
|
|
34
|
+
} else {
|
|
35
|
+
apiRef.toast(`Hotkey "${next}" is unavailable`, { type: 'warn' });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
3
38
|
|
|
4
39
|
export function init(api) {
|
|
40
|
+
apiRef = api;
|
|
5
41
|
api.onMessage('settings', (msg) => {
|
|
6
42
|
enabled = msg.enabled !== false;
|
|
7
43
|
if (btnEl) btnEl.style.display = enabled ? '' : 'none';
|
|
44
|
+
bindHotkey(msg.hotkey || 'F8');
|
|
8
45
|
});
|
|
9
46
|
api.send('getSettings');
|
|
10
47
|
|
|
11
48
|
btnEl = api.addToolbarButton({
|
|
12
49
|
title: 'Trim & Copy',
|
|
13
50
|
icon: '<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="6" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M20 4 8.12 15.88M14.47 14.48 20 20M8.12 8.12 12 12"/></svg>',
|
|
14
|
-
|
|
15
|
-
const text = api.getTerminalSelection();
|
|
16
|
-
if (!text || !text.trim()) { api.toast('Select text to copy & trim', { type: 'warn' }); return; }
|
|
17
|
-
const trimmed = text
|
|
18
|
-
.split('\n')
|
|
19
|
-
.map(l => l.trimEnd())
|
|
20
|
-
.join('\n')
|
|
21
|
-
.replace(/^\n+/, '').replace(/\n+$/, '');
|
|
22
|
-
try {
|
|
23
|
-
await navigator.clipboard.writeText(trimmed);
|
|
24
|
-
const saved = text.length - trimmed.length;
|
|
25
|
-
api.toast(saved ? `Copied & trimmed ${saved} char${saved !== 1 ? 's' : ''}` : 'Copied', { type: 'success' });
|
|
26
|
-
} catch {
|
|
27
|
-
api.toast('Clipboard access denied — allow it in browser site settings', { type: 'error' });
|
|
28
|
-
}
|
|
29
|
-
}
|
|
51
|
+
onClick: trimAndCopy,
|
|
30
52
|
});
|
|
31
53
|
}
|