From 19f522fa8e7239879762b6613047f39e0f7e80a8 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Fri, 10 Apr 2026 10:18:15 -0400 Subject: [PATCH] fix: proper focus changes --- src/create-space-and-focus.tsx | 26 ++++++++++++++++---------- src/destroy-space.tsx | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/create-space-and-focus.tsx b/src/create-space-and-focus.tsx index 67ecccb..00608b8 100644 --- a/src/create-space-and-focus.tsx +++ b/src/create-space-and-focus.tsx @@ -10,20 +10,26 @@ export default async function Command() { console.log(stderr); throw new Error(stderr); } - - const { stdout: spacesOutput } = await runYabaiCommand(`-m query --spaces --space mouse`); - const space = JSON.parse(spacesOutput); - - const { stderr: stderr2 } = await runYabaiCommand(`-m space last --move ${space.index+1}`); - if (stderr2) { - console.log(stderr2); - throw new Error(stderr2); + const { stdout: spacesOutput } = await runYabaiCommand(`-m query --spaces`); + const { stdout: spaceOutput } = await runYabaiCommand(`-m query --spaces --space mouse`); + const spaces = JSON.parse(spacesOutput); + const currentSpace = JSON.parse(spaceOutput); + + if (spaces.length - currentSpace.index > 2) { + const { stderr: stderr2 } = await runYabaiCommand(`-m space last --move ${currentSpace.index + 1}`); + if (stderr2) { + console.log(stderr2); + throw new Error(stderr2); + } } - + const { stderr: stderr3 } = await runYabaiCommand(`-m space --focus ${currentSpace.index + 1}`); - await runYabaiCommand(`-m space --focus next`); + if (stderr3) { + console.log(stderr3); + throw new Error(stderr3); + } showHUD(`Created space`); } catch (error) { diff --git a/src/destroy-space.tsx b/src/destroy-space.tsx index 80570b1..e374bc2 100644 --- a/src/destroy-space.tsx +++ b/src/destroy-space.tsx @@ -4,7 +4,21 @@ import { showFailureToast } from "@raycast/utils"; export default async function Command() { try { - const { stderr } = await runYabaiCommand(`-m space --destroy`); + const { stdout: spaceOutput } = await runYabaiCommand(`-m query --spaces --space mouse`); + const currentSpace = JSON.parse(spaceOutput); + let moveFocusIndex = currentSpace.index - 1; + + if (currentSpace.index === 0) { + moveFocusIndex = currentSpace.index + 1; + } + + const { stderr: stderr3 } = await runYabaiCommand(`-m space --focus ${moveFocusIndex}`); + if (stderr3) { + console.log(stderr3); + throw new Error(stderr3); + } + + const { stderr } = await runYabaiCommand(`-m space --destroy ${currentSpace.index}`); if (stderr) { throw new Error(stderr);