Support stable insertion and managed tab placement
Verify Tessera GUI / verify (push) Failing after 7m40s
Verify Tessera GUI / verify (push) Failing after 7m40s
This commit is contained in:
+188
-24
@@ -250,6 +250,7 @@ enum Operation {
|
||||
CloseWindow,
|
||||
Detach,
|
||||
MoveWindow,
|
||||
MoveTab,
|
||||
State,
|
||||
StateSet,
|
||||
Increment,
|
||||
@@ -266,6 +267,7 @@ enum Operation {
|
||||
SetText,
|
||||
SetColor,
|
||||
Append,
|
||||
Insert,
|
||||
Remove,
|
||||
Replace,
|
||||
Move,
|
||||
@@ -690,11 +692,11 @@ impl NativeCallable for Function {
|
||||
Scroll => (3, 3),
|
||||
Text => (1, 3),
|
||||
Rect => (2, 4),
|
||||
MoveWindow | OpenValue | Spacer | SetText | SetColor | Append | Remove | Render
|
||||
| Navigate | OnClick | Present => (1, 1),
|
||||
MoveTab | MoveWindow | OpenValue | Spacer | SetText | SetColor | Append | Remove
|
||||
| Render | Navigate | OnClick | Present => (1, 1),
|
||||
Row | Column => (2, MAX_UI_NODES + 2),
|
||||
Button => (1, 1),
|
||||
Replace | Move => (2, 2),
|
||||
Insert | Replace | Move => (2, 2),
|
||||
Page | Unmount | Close | Activate | Back | Forward | Children | NewWindow
|
||||
| CloseWindow | Detach => (0, 0),
|
||||
Open => (0, 1),
|
||||
@@ -1158,6 +1160,23 @@ impl NativeCallable for Function {
|
||||
)?,
|
||||
)));
|
||||
}
|
||||
if matches!(self.operation, MoveTab) {
|
||||
let position = usize::try_from(integer(args.first())?)
|
||||
.map_err(|_| invalid("tab position out of range"))?;
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let id = page_window(cx.store(), &state, owner)?.ok_or(invalid("Page is not open"))?;
|
||||
let view = state
|
||||
.presentations
|
||||
.get_mut(&id)
|
||||
.ok_or(invalid("missing window"))?;
|
||||
let window = object(Some(&cx.store().get_attr(view.desktop, "window")?))?;
|
||||
crate::window::move_page(cx, window, owner, position)?;
|
||||
view.force_frame = true;
|
||||
return Ok(NativeResult::Return(Value::Object(owner)));
|
||||
}
|
||||
let (data_ref, data) = block::resolve(cx.store(), owner)?;
|
||||
let mut data = data.clone();
|
||||
let mut result = Value::Nil;
|
||||
@@ -1181,16 +1200,29 @@ impl NativeCallable for Function {
|
||||
}
|
||||
_ => return Err(invalid("this Block has no color")),
|
||||
},
|
||||
Append | Remove | Replace | Move => {
|
||||
Append | Insert | Remove | Replace | Move => {
|
||||
if !data.is_container() {
|
||||
return Err(invalid("expected a container Block"));
|
||||
}
|
||||
if matches!(self.operation, Append) {
|
||||
let child = object(args.first())?;
|
||||
if matches!(self.operation, Append | Insert) {
|
||||
let (position, argument) = if matches!(self.operation, Insert) {
|
||||
let position = usize::try_from(integer(args.first())?)
|
||||
.map_err(|_| invalid("child position out of range"))?;
|
||||
if position > data.children.len() {
|
||||
return Err(invalid("child position out of range"));
|
||||
}
|
||||
(position, args.get(1))
|
||||
} else {
|
||||
(data.children.len(), args.first())
|
||||
};
|
||||
let child = object(argument)?;
|
||||
block::validate(cx.store(), child, Some(data_ref))?;
|
||||
let slot = data.next_slot;
|
||||
data.next_slot = slot.checked_add(1).ok_or(VmError::IdentityExhausted)?;
|
||||
data.children.push(Child { slot, block: child });
|
||||
data.next_slot = slot
|
||||
.checked_add(1)
|
||||
.filter(|next| *next <= i64::MAX as u64)
|
||||
.ok_or(VmError::IdentityExhausted)?;
|
||||
data.children.insert(position, Child { slot, block: child });
|
||||
result = Value::Number((slot as i64).into());
|
||||
} else {
|
||||
let slot = integer(args.first())?;
|
||||
@@ -1209,7 +1241,8 @@ impl NativeCallable for Function {
|
||||
data.children[index].block = child;
|
||||
}
|
||||
Move => {
|
||||
let to = integer(args.get(1))? as usize;
|
||||
let to = usize::try_from(integer(args.get(1))?)
|
||||
.map_err(|_| invalid("child position out of range"))?;
|
||||
if to >= data.children.len() {
|
||||
return Err(invalid("child position out of range"));
|
||||
}
|
||||
@@ -1421,6 +1454,31 @@ pub struct UiBridge {
|
||||
tasks: crate::tasks::Scheduler,
|
||||
}
|
||||
|
||||
fn invoke_member(
|
||||
vm: &mut Vm,
|
||||
owner: ObjectRef,
|
||||
method: &str,
|
||||
arguments: &[Value],
|
||||
instruction_budget: usize,
|
||||
) -> Result<Value> {
|
||||
let bound = vm.bind_attr(owner, method)?;
|
||||
let result = match &bound {
|
||||
Value::Object(function) => vm
|
||||
.call_with_limits(
|
||||
*function,
|
||||
arguments,
|
||||
endor_core::ExecutionLimits {
|
||||
max_frames: 128,
|
||||
max_instructions: instruction_budget,
|
||||
},
|
||||
)
|
||||
.map_err(|error| crate::endor_host::runtime_error(vm, error)),
|
||||
_ => Err(anyhow::anyhow!("object method is not callable")),
|
||||
};
|
||||
vm.release_value(bound)?;
|
||||
result
|
||||
}
|
||||
|
||||
fn project_tabs(
|
||||
vm: &Vm,
|
||||
state: &mut crate::presentation::Presentation,
|
||||
@@ -1632,6 +1690,43 @@ impl UiBridge {
|
||||
.values()
|
||||
.any(|view| view.pending.flatten().is_some() || view.active.is_some()))
|
||||
}
|
||||
pub fn accepts_tab_drop(&self, vm: &Vm, input: &crate::events::Input) -> bool {
|
||||
let Some(target) = &input.tab_drop else {
|
||||
return true;
|
||||
};
|
||||
let Ok(state) = self.session.lock() else {
|
||||
return false;
|
||||
};
|
||||
for (id, version) in [
|
||||
(input.window, input.layout_version),
|
||||
(target.window, target.layout_version),
|
||||
] {
|
||||
let Some(view) = state.presentations.get(&id) else {
|
||||
return false;
|
||||
};
|
||||
if view.closing || view.published_version != version {
|
||||
return false;
|
||||
}
|
||||
let Ok(Value::Object(window)) = vm.get_attr(view.desktop, "window") else {
|
||||
return false;
|
||||
};
|
||||
let Ok(pages) = crate::window::pages(vm.object_store(), window) else {
|
||||
return false;
|
||||
};
|
||||
if view.tab_ids.len() != pages.len()
|
||||
|| !pages
|
||||
.iter()
|
||||
.zip(&view.tab_ids)
|
||||
.all(|(page, (weak, _))| vm.object_store().downgrade(*page).ok() == Some(*weak))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if id == target.window && target.index > pages.len() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
pub fn open_value(&self, vm: &mut Vm, value: &Value) -> Result<()> {
|
||||
let function = object(Some(&vm.get_attr(self.ui, "open")?))?;
|
||||
let page = vm.call(function, std::slice::from_ref(value))?;
|
||||
@@ -1660,25 +1755,92 @@ impl UiBridge {
|
||||
.find(|page| vm.object_store().downgrade(*page).ok() == Some(weak))
|
||||
.ok_or_else(|| anyhow::anyhow!("Page is no longer open"))?
|
||||
};
|
||||
if let Some(target) = &input.tab_drop {
|
||||
let window = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
let view = state
|
||||
.presentations
|
||||
.get(&target.window)
|
||||
.ok_or_else(|| anyhow::anyhow!("drop window has closed"))?;
|
||||
if view.published_version != target.layout_version {
|
||||
bail!("drop targets an obsolete presentation");
|
||||
}
|
||||
object(Some(&vm.get_attr(view.desktop, "window")?))?
|
||||
};
|
||||
if target.window != input.window {
|
||||
let value =
|
||||
invoke_member(vm, page, "moveToWindow", &[Value::Object(window)], 300_000)?;
|
||||
vm.release_value(value)?;
|
||||
}
|
||||
// An override may deliberately decline or redirect the move. Do
|
||||
// not reorder an unrelated window after that source decision.
|
||||
let destination = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
page_window(vm.object_store(), &state, page)?
|
||||
};
|
||||
if destination == Some(target.window) {
|
||||
let pages = crate::window::pages(vm.object_store(), window)?;
|
||||
let from = pages
|
||||
.iter()
|
||||
.position(|candidate| *candidate == page)
|
||||
.ok_or_else(|| anyhow::anyhow!("Page is no longer open"))?;
|
||||
let position = if input.window == target.window && from < target.index {
|
||||
target.index - 1
|
||||
} else {
|
||||
target.index
|
||||
};
|
||||
if position >= pages.len() {
|
||||
bail!("drop destination changed during Page method");
|
||||
}
|
||||
let value = invoke_member(
|
||||
vm,
|
||||
page,
|
||||
"moveTab",
|
||||
&[Value::Number((position as i64).into())],
|
||||
300_000,
|
||||
)?;
|
||||
vm.release_value(value)?;
|
||||
let value = invoke_member(vm, page, "activate", &[], 300_000)?;
|
||||
vm.release_value(value)?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
let method = match input.kind.as_str() {
|
||||
"tab-close" => "close",
|
||||
"tab-detach" => "detachToWindow",
|
||||
_ => "activate",
|
||||
};
|
||||
let bound = vm.bind_attr(page, method)?;
|
||||
let result = match &bound {
|
||||
Value::Object(function) => vm.call_with_limits(
|
||||
*function,
|
||||
&[],
|
||||
endor_core::ExecutionLimits {
|
||||
max_frames: 128,
|
||||
max_instructions: 1_000_000,
|
||||
},
|
||||
),
|
||||
_ => Err(invalid("Page method is not callable")),
|
||||
};
|
||||
vm.release_value(bound)?;
|
||||
vm.release_value(result?)?;
|
||||
let value = invoke_member(vm, page, method, &[], 1_000_000)?;
|
||||
let placed = (|| -> Result<()> {
|
||||
if input.kind == "tab-detach"
|
||||
&& let Some([x, y]) = input.screen_position
|
||||
&& let Value::Object(window) = &value
|
||||
&& vm
|
||||
.payload::<crate::window::ManagedWindow>(*window, "Window")
|
||||
.is_ok()
|
||||
{
|
||||
let result = invoke_member(
|
||||
vm,
|
||||
*window,
|
||||
"moveTo",
|
||||
&[
|
||||
Value::Number((x as i64).into()),
|
||||
Value::Number((y as i64).into()),
|
||||
],
|
||||
100_000,
|
||||
)?;
|
||||
vm.release_value(result)?;
|
||||
}
|
||||
Ok(())
|
||||
})();
|
||||
vm.release_value(value)?;
|
||||
placed?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1720,7 +1882,7 @@ impl UiBridge {
|
||||
}
|
||||
if matches!(
|
||||
input.kind.as_str(),
|
||||
"tab-activate" | "tab-close" | "tab-detach"
|
||||
"tab-activate" | "tab-close" | "tab-detach" | "tab-drop"
|
||||
) {
|
||||
return self.dispatch_tab(vm, input);
|
||||
}
|
||||
@@ -2441,12 +2603,14 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
("TextBlock", "setColor", Operation::SetColor),
|
||||
("RectBlock", "setColor", Operation::SetColor),
|
||||
("ContainerBlock", "append", Operation::Append),
|
||||
("ContainerBlock", "insert", Operation::Insert),
|
||||
("ContainerBlock", "remove", Operation::Remove),
|
||||
("ContainerBlock", "replace", Operation::Replace),
|
||||
("ContainerBlock", "move", Operation::Move),
|
||||
("ContainerBlock", "children", Operation::Children),
|
||||
("Window", "close", Operation::CloseWindow),
|
||||
("Page", "moveToWindow", Operation::MoveWindow),
|
||||
("Page", "moveTab", Operation::MoveTab),
|
||||
("Page", "detachToWindow", Operation::Detach),
|
||||
("Page", "render", Operation::Render),
|
||||
("Page", "unmount", Operation::Unmount),
|
||||
|
||||
Reference in New Issue
Block a user