feat(text): in-place editors for all text entities

Route every text-bearing entity to an in-place editor instead of the
command line: a plain text box for single-line text (Text, attributes,
dimension override, tolerance) and the rich MText editor for MText /
MultiLeader. A Leader resolves to the entity it annotates.

- TEXT places a plain text box at the click; double-click edits in place.
- DDEDIT and double-click on any text entity open the matching editor.
- MLEADER places the leader then opens the MText editor on its content.
- LEADER follows the classic flow: points, Enter, then a linked empty
  MText annotation opens in the editor; the leader's annotation_handle
  links the pair so they edit/erase as a unit.

Adds shared field read/write helpers and a begin_text_edit router, plus
CommitAndEditText / CommitManyAndEditText results that commit an entity
and open its editor (commit_entity now returns the new handle).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-05-31 14:44:18 +03:00
commit 2627d06224
13 changed files with 551 additions and 346 deletions

View file

@ -1260,6 +1260,11 @@ impl OpenCADStudio {
self.mtext_cancel();
return Task::none();
}
// The in-place TEXT editor likewise cancels on Escape.
if self.text_inline.is_some() {
self.text_inline_cancel();
return Task::none();
}
// Grip popup intercepts Escape — dismisses the menu
// without doing anything else.
if self.grip_popup.take().is_some() {
@ -2959,31 +2964,20 @@ impl OpenCADStudio {
let hit = scene::hit_test::click_hit(p, &all_wires[..], vp_mat, bounds)
.and_then(|s| Scene::handle_from_wire_name(s));
if let Some(handle) = hit {
// MText opens the in-place editor; other text types
// keep the command-line DDEDIT path.
if let Some(AcadEntityType::MText(m)) =
self.tabs[i].scene.document.get_entity(handle)
{
let pos = glam::Vec3::new(
m.insertion_point.x as f32,
m.insertion_point.y as f32,
m.insertion_point.z as f32,
);
let (val, h) = (m.value.clone(), m.height);
self.open_mtext_editor(pos, Some(handle), &val, h);
return Task::none();
}
if let Some(entity) = self.tabs[i].scene.document.get_entity(handle) {
use crate::modules::annotate::ddedit::{
entity_text, DdeditCommand,
};
if let Some(cur) = entity_text(entity) {
let cmd = DdeditCommand::with_handle(handle, cur.clone());
self.command_line
.push_info(&format!("DDEDIT Enter new text <{cur}>:"));
self.tabs[i].active_cmd = Some(Box::new(cmd));
return self.focus_cmd_input();
}
// Any text-bearing entity opens its in-place editor
// (plain box or rich MText editor, per type). A
// Leader resolves to the entity it annotates.
let is_editable_text = self
.tabs[i]
.scene
.document
.get_entity(handle)
.is_some_and(|e| {
super::text_inline::read_text_field(e).is_some()
|| matches!(e, AcadEntityType::Leader(_))
});
if is_editable_text {
return self.begin_text_edit(handle);
}
}
}
@ -3621,6 +3615,17 @@ impl OpenCADStudio {
Task::none()
}
Message::TextInlineInput(s) => {
if let Some(ed) = self.text_inline.as_mut() {
ed.value = s;
}
Task::none()
}
Message::TextInlineOk => {
self.text_inline_commit();
Task::none()
}
Message::DrawOrderSubmenuToggle => {
let i = self.active_tab;
let mut sel = self.tabs[i].scene.selection.borrow_mut();