Skip to content

Commit

Permalink
feat: add hotkey: "Yak on here and up" (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
cablehead authored Oct 23, 2024
1 parent 806d53e commit a5ac6c1
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ utilitarian design, give Stacks a try-- I'd love to hear your thoughts!

`.DMG` installers that have been notarized by Apple.

- **Current version**: v0.15.11
- **Current version**: v0.15.12
- **Last release**: Oct 14, 2024

[![MacOS (Universal)](./docs/assets/MacOS-Universal.svg)](https://stacks.cross.stream/releases/Stacks_0.15.11_universal.dmg)
[![MacOS (Universal)](./docs/assets/MacOS-Universal.svg)](https://stacks.cross.stream/releases/Stacks_0.15.12_universal.dmg)

## Community

Expand Down
1 change: 1 addition & 0 deletions changes/v0.15.12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- add action "Yak on here and up"
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stacks"
version = "0.15.11"
version = "0.15.12"
description = "Stacks"
authors = ["Andy Gayton <[email protected]>"]
license = ""
Expand Down
34 changes: 29 additions & 5 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ pub fn store_add_to_new_stack(
state: tauri::State<SharedState>,
name: String,
source_id: scru128::Scru128Id,
and_up: bool, // fork the source_id and all items above it into the new stack
focus: bool,
) {
state.with_lock(|state| {
Expand All @@ -998,17 +999,40 @@ pub fn store_add_to_new_stack(
.select(state.view.get_best_focus(&state.ui.focused));
}

// Create a new stack
let stack_packet = state
.store
.add_stack(name.as_bytes(), StackLockStatus::Unlocked);
state.merge(&stack_packet);

let item_packet =
state
.store
.fork(source_id, None, MimeType::TextPlain, Some(stack_packet.id));
state.merge(&item_packet);
if and_up {
// Fork the source_id and all items above it into the new stack
if let Some(item) = state.view.items.get(&source_id) {
if let Some(stack_id) = item.stack_id {
if let Some(stack) = state.view.items.get(&stack_id) {
let children = state.view.children(stack);
for &item_id in children.iter().rev().skip_while(|&&id| id != source_id) {
let item_packet = state.store.fork(
item_id,
None,
MimeType::TextPlain,
Some(stack_packet.id),
);
state.merge(&item_packet);
}
}
}
}
} else {
// Fork the source_id into the new stack
let item_packet =
state
.store
.fork(source_id, None, MimeType::TextPlain, Some(stack_packet.id));
state.merge(&item_packet);
}
});

app.emit_all("refresh-items", true).unwrap();
}

Expand Down
8 changes: 2 additions & 6 deletions src-tauri/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,8 @@ impl Store {
.filter(|p| p.packet_type == PacketType::Update || p.packet_type == PacketType::Add)
.for_each(|p| {
let meta = p.hash.and_then(|hash| content_meta_cache.get_mut(&hash));

match (meta, p.content_type) {
(Some(meta), Some(content_type)) => {
meta.content_type = content_type;
}
_ => {}
if let (Some(meta), Some(content_type)) = (meta, p.content_type) {
meta.content_type = content_type;
}
});

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": {
"productName": "Stacks",
"version": "0.15.11"
"version": "0.15.12"
},
"build": {
"beforeDevCommand": "npm run dev",
Expand Down
22 changes: 22 additions & 0 deletions src/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ export const actions: Action[] = [
name: dn(),
sourceId: item.id,
focus: true,
andUp: false,
});
})();
}
},
},

{
name: "Yak on here and up",
keys: [<Icon name="IconCommandKey" />, <Icon name="IconShiftKey" />, "Y"],
matchKeyEvent: (event: KeyboardEvent) =>
matchKeyEvent(event, { meta: true, shift: true, code: "KeyY" }),
canApply: (stack: Stack) => !!stack.selected_item(),
trigger: (stack: Stack) => {
const item = stack.selected_item();
if (item) {
(async () => {
await invoke("store_add_to_new_stack", {
name: dn(),
sourceId: item.id,
focus: true,
andUp: true,
});
})();
}
Expand Down

0 comments on commit a5ac6c1

Please sign in to comment.