Skip to content

Commit 7efab3a

Browse files
committed
feat: 接收区选中文字后状态栏显示选中字节数
v0.8.5
1 parent f383678 commit 7efab3a

6 files changed

Lines changed: 31 additions & 3 deletions

File tree

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "zcom"
3-
version = "0.8.4"
3+
version = "0.8.5"
44
description = "High performance serial debug assistant"
55
authors = ["zt"]
66
edition = "2021"

src/css/style.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,14 @@ select:focus, input:focus, textarea:focus {
635635
gap: 10px;
636636
white-space: nowrap;
637637
}
638-
#stat-tx, #stat-rx {
638+
#stat-tx, #stat-rx, .stat-sel {
639639
font-family: 'Consolas', monospace;
640640
color: var(--fg-dim);
641641
cursor: pointer;
642642
}
643+
.stat-sel {
644+
cursor: default;
645+
}
643646
#port-info {
644647
margin-left: auto;
645648
color: var(--fg-dim);

src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
<div class="status-group">
124124
<span id="stat-tx">Tx: 0</span>
125125
<span id="stat-rx">Rx: 0</span>
126+
<span id="stat-sel" class="stat-sel hidden"></span>
126127
</div>
127128
<div class="status-group" id="port-info">
128129
<span>未连接</span>

src/js/receive.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,19 @@ export async function initReceive() {
563563
foldThreshold = e.detail.foldRepeatCount || 5;
564564
});
565565

566+
document.addEventListener('selectionchange', () => {
567+
const sel = window.getSelection();
568+
if (sel && sel.rangeCount > 0 && !sel.isCollapsed) {
569+
const range = sel.getRangeAt(0);
570+
if (receiveContent && receiveContent.contains(range.commonAncestorContainer)) {
571+
const bytes = new TextEncoder().encode(sel.toString()).length;
572+
document.dispatchEvent(new CustomEvent('selection-bytes-changed', { detail: { bytes } }));
573+
return;
574+
}
575+
}
576+
document.dispatchEvent(new CustomEvent('selection-bytes-changed', { detail: { bytes: null } }));
577+
});
578+
566579
mcpFlushTimer = setInterval(flushMcp, 1000);
567580
}
568581

src/js/statusbar.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export async function initStatusBar() {
1010
const encSelect = document.getElementById('encoding-select');
1111
const statTx = document.getElementById('stat-tx');
1212
const statRx = document.getElementById('stat-rx');
13+
const statSel = document.getElementById('stat-sel');
1314
const portInfo = document.getElementById('port-info');
1415

1516
document.addEventListener('port-state-change', (e) => {
@@ -102,4 +103,14 @@ export async function initStatusBar() {
102103
// ignore
103104
}
104105
}, 500);
106+
107+
document.addEventListener('selection-bytes-changed', (e) => {
108+
const bytes = e.detail.bytes;
109+
if (bytes !== null) {
110+
statSel.textContent = `Sel: ${formatByteCount(bytes)}`;
111+
statSel.classList.remove('hidden');
112+
} else {
113+
statSel.classList.add('hidden');
114+
}
115+
});
105116
}

0 commit comments

Comments
 (0)