Right-click Replace only offers modules of the same kind (same WIT world)
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
783618b89f
commit
8724805a72
1 file changed
+25
-1
@@ -59,6 +59,24 @@ fn stem(path : String) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| The WIT world ("clock-widget", "taskbar-widget", ...) a module was built for, read from the
|
||||||
|
/// `<name>.meta.json` that build-modules.sh writes next to it; "" when unknown (a module loaded
|
||||||
|
/// from elsewhere). Two modules are interchangeable only when their worlds match.
|
||||||
|
fn module_world(path : String) -> String {
|
||||||
|
let base = if path.has_suffix(".wasm") { path[:path.length() - 5].to_string() } else { path }
|
||||||
|
let text = @utf8.decode_lossy(@sys.read_file_bytes(base + ".meta.json"))
|
||||||
|
match text.find("\"world\":\"") {
|
||||||
|
None => ""
|
||||||
|
Some(i) => {
|
||||||
|
let rest = text[i + 9:].to_string()
|
||||||
|
match rest.find("\"") {
|
||||||
|
Some(j) => rest[:j].to_string()
|
||||||
|
None => ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///| Find every module file on the search path (earlier directories win on the same name).
|
///| Find every module file on the search path (earlier directories win on the same name).
|
||||||
fn DesktopShell::scan_catalog(self : DesktopShell) -> Unit {
|
fn DesktopShell::scan_catalog(self : DesktopShell) -> Unit {
|
||||||
self.catalog.clear()
|
self.catalog.clear()
|
||||||
@@ -545,8 +563,14 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool
|
|||||||
Some(w) => {
|
Some(w) => {
|
||||||
self.name_catalog()
|
self.name_catalog()
|
||||||
let rows : Array[MenuRow] = []
|
let rows : Array[MenuRow] = []
|
||||||
|
// Only modules of the same kind (same WIT world) can stand in for this one.
|
||||||
|
let world = module_world(w.path)
|
||||||
for e in self.catalog {
|
for e in self.catalog {
|
||||||
if e.id != w.module_id && e.path != w.path && rows.length() < max_replace_rows {
|
if world.length() > 0 &&
|
||||||
|
e.id != w.module_id &&
|
||||||
|
e.path != w.path &&
|
||||||
|
rows.length() < max_replace_rows &&
|
||||||
|
module_world(e.path) == world {
|
||||||
rows.push({ label: "Replace with " + e.name, kind: 0, arg: e.path })
|
rows.push({ label: "Replace with " + e.name, kind: 0, arg: e.path })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user