Skip to content

Commit

Permalink
optimize: optimize variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamMaoMao committed Oct 14, 2024
1 parent 375f30d commit 6b9e1d8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/wm/src/wm_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,35 +303,35 @@ impl WmState {
.and_then(|name| self.workspace_by_name(&name)),
),
WorkspaceTarget::NextActive => {
let workspaces = self.sorted_workspaces(config);
let origin_index = workspaces
let active_workspaces = self.sorted_workspaces(config);
let origin_index = active_workspaces
.iter()
.position(|workspace| workspace.id() == origin_workspace.id())
.context("Failed to get index of given workspace.")?;

let next_workspace = workspaces
let next_active_workspace = active_workspaces
.get(origin_index + 1)
.or_else(|| workspaces.first());
.or_else(|| active_workspaces.first());

(
next_workspace.map(|workspace| workspace.config().name),
next_workspace.cloned(),
next_active_workspace.map(|workspace| workspace.config().name),
next_active_workspace.cloned(),
)
}
WorkspaceTarget::PreviousActive => {
let workspaces = self.sorted_workspaces(config);
let origin_index = workspaces
let active_workspaces = self.sorted_workspaces(config);
let origin_index = active_workspaces
.iter()
.position(|workspace| workspace.id() == origin_workspace.id())
.context("Failed to get index of given workspace.")?;

let prev_workspace = workspaces.get(
origin_index.checked_sub(1).unwrap_or(workspaces.len() - 1),
let prev_active_workspace = active_workspaces.get(
origin_index.checked_sub(1).unwrap_or(active_workspaces.len() - 1),
);

(
prev_workspace.map(|workspace| workspace.config().name),
prev_workspace.cloned(),
prev_active_workspace.map(|workspace| workspace.config().name),
prev_active_workspace.cloned(),
)
}
WorkspaceTarget::Next => {
Expand Down

0 comments on commit 6b9e1d8

Please sign in to comment.