fix: 统一输入框编辑能力、修复拖拽合并网格并支持光标吸附数据点

统一文本输入(新增 Utilities/Inc/TextEdit.hpp + TextEdit.cpp)
- 一个共享的编辑模型,提供光标/选区/过滤/限长,接入全部输入框:
  样式区数值与信号名/分组名、波形图例改名、视图标签页改名、
  拾色器 R/G/B 与色号、光标时间与网格上下限。
- 新增能力:Ctrl+A/C/X/V(含剪贴板清洗)、Shift+方向键与 Home/End 选区、
  退格与删除清除选区、代理对安全的光标步进。
- 渲染改为选区高亮 + 插入符,文本超出框宽时水平滚动并让插入符始终可见;
  初始态为整段选中,首字符键入即整体替换(保持"登录框"式交互)。
- 新增 Utf8Util::PasteTextFromClipboard(换行/制表符折叠为空格)。

修复网格合并(Utilities/Src/DataModel.cpp)
- 拖拽信号到其它网格时先固定目标网格的锚信号,再移除源信号并按引用找回目标,
  避免空网格回收导致下标错位,从"与原网格交换位置"改为真正合并。
- 自定义划分下未分配网格的可见信号改为各自独占一个新网格,
  修复"拖拽合并后再勾选新信号被并入该合并网格"的问题。

绘图区(Components/PlotView)
- 网格右键菜单新增"时间轴自适应(匹配本网格)",把时间轴对齐到该网格信号范围。
- 时间轴放大到采样点在屏幕上可分辨(>=6 逻辑像素)时,拖动光标吸附到最近数据点;
  缩小到无法分辨时保持自由移动,避免光标"跳格"。

验证:真实输入脚本逐项核对——拖拽合并后单网格含两条曲线、拖拽合并再勾选新信号得 G2 独立网格、
Shift 选区 + Delete 清除、Ctrl+A/C/V 复制粘贴、46 字符文本水平滚动、拾色器色号 1E90FF、
标签页改名 A1、光标时间框复制粘贴、全视图拖动得 0.522213(不吸附)而放大后得 0.28125(= 225 × 0.00125,已吸附)。
This commit is contained in:
DeepSeek V4.1 Flash committed 2026-09-30 13:40:58 +08:00
1 parent 4e295a2a7d
commit 53768b8b25
16 files changed
+1135 -288

No files matched your search

+53 -21
View File
@@ -210,7 +210,9 @@ namespace jdi
[](const Lane& lane) { return lane.signals.empty(); }),
lanes.end());
// 未分配网格的可见信号统一追加到第一个网格。
// 未分配网格的可见信号各自独占一个新网格。
// 注意:不能把它们塞进已有的第一个网格——那会导致“拖拽合并后新勾选的信号
// 被悄悄并入合并网格”,用户看不到新增的独立泳道。
for (const SignalRef& ref : visible)
{
bool placed = false;
@@ -227,13 +229,10 @@ namespace jdi
continue;
}
if (lanes.empty())
{
Lane lane;
lane.autoRange = true;
lanes.push_back(std::move(lane));
}
lanes[0].signals.push_back(ref);
Lane lane;
lane.autoRange = true;
lane.signals.push_back(ref);
lanes.push_back(std::move(lane));
}
}
@@ -809,17 +808,11 @@ namespace jdi
}
style->visible = visible;
// 合并模式下新勾选的信号独占一个新网格:避免「先合并已有信号、再加入新信号」
// 时新信号被悄悄塞进那个唯一的合并网格里,导致用户看不到新增的独立泳道。
// 合并模式下新勾选的信号独占一个新网格:切到自定义划分后,
// RebuildLanes 会把尚未分配网格的可见信号各自放入新网格。
if (visible && m_laneMode == LaneMode::MERGED)
{
m_laneMode = LaneMode::CUSTOM;
Lane lane;
lane.autoRange = true;
lane.signals.push_back(ref);
m_lanes.push_back(std::move(lane));
SyncLanes(dataSet);
return;
}
SyncLanes(dataSet);
@@ -978,6 +971,31 @@ namespace jdi
return -1;
}
const int sourceLane = LaneOfSignal(ref);
if (laneIndex >= 0 && laneIndex == sourceLane)
{
// 拖回原网格:无需变动,避免因网格回收导致顺序抖动。
return sourceLane;
}
// 先把目标网格的“锚信号”固定下来:移除信号后空网格会被回收,
// 下标随之变化,必须用不依赖下标的引用找回真正的目标网格
// (否则会变成“与原网格交换位置”而不是合并进去)。
SignalRef targetAnchor;
bool hasTarget = (laneIndex >= 0 && laneIndex < static_cast<int>(m_lanes.size()));
if (hasTarget)
{
const std::vector<SignalRef>& targetSignals = m_lanes[static_cast<std::size_t>(laneIndex)].signals;
for (const SignalRef& candidate : targetSignals)
{
if (!(candidate == ref))
{
targetAnchor = candidate;
break;
}
}
}
// 手动指定归属意味着切换到自定义划分策略。
m_laneMode = LaneMode::CUSTOM;
@@ -990,17 +1008,31 @@ namespace jdi
[](const Lane& lane) { return lane.signals.empty(); }),
m_lanes.end());
if (laneIndex < 0 || laneIndex >= static_cast<int>(m_lanes.size()))
int destination = -1;
if (hasTarget && targetAnchor.IsValid())
{
for (std::size_t index = 0; index < m_lanes.size(); ++index)
{
const std::vector<SignalRef>& refs = m_lanes[index].signals;
if (std::find(refs.begin(), refs.end(), targetAnchor) != refs.end())
{
destination = static_cast<int>(index);
break;
}
}
}
if (destination >= 0)
{
m_lanes[static_cast<std::size_t>(destination)].signals.push_back(ref);
}
else
{
Lane lane;
lane.autoRange = true;
lane.signals.push_back(ref);
m_lanes.push_back(std::move(lane));
}
else
{
m_lanes[static_cast<std::size_t>(laneIndex)].signals.push_back(ref);
}
for (std::size_t index = 0; index < m_lanes.size(); ++index)
{