mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 15:55:52 +01:00
Fix keyboard shortcut support and address code review feedback
- Add editBranchPrefixCommand in note_tree.ts to support F2 keyboard shortcut with multi-selection - Extract CSS to separate branch_prefix.css file - Remove hard-coded color, use CSS class instead - Fix translation key usage to keep t() calls visible in IDE - Remove all inline styles Co-authored-by: eliandoran <21236836+eliandoran@users.noreply.github.com>
This commit is contained in:
13
apps/client/src/widgets/dialogs/branch_prefix.css
Normal file
13
apps/client/src/widgets/dialogs/branch_prefix.css
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
.branch-prefix-dialog .branch-prefix-notes-list {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.branch-prefix-dialog .branch-prefix-notes-list ul {
|
||||||
|
max-height: 200px;
|
||||||
|
overflow: auto;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.branch-prefix-dialog .branch-prefix-current {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import FormGroup from "../react/FormGroup.js";
|
|||||||
import { useTriliumEvent } from "../react/hooks.jsx";
|
import { useTriliumEvent } from "../react/hooks.jsx";
|
||||||
import FBranch from "../../entities/fbranch.js";
|
import FBranch from "../../entities/fbranch.js";
|
||||||
import type { ContextMenuCommandData } from "../../components/app_context.js";
|
import type { ContextMenuCommandData } from "../../components/app_context.js";
|
||||||
|
import "./branch_prefix.css";
|
||||||
|
|
||||||
// Virtual branches (e.g., from search results) start with this prefix
|
// Virtual branches (e.g., from search results) start with this prefix
|
||||||
const VIRTUAL_BRANCH_PREFIX = "virt-";
|
const VIRTUAL_BRANCH_PREFIX = "virt-";
|
||||||
@@ -84,12 +85,11 @@ export default function BranchPrefixDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isSingleBranch = branches.length === 1;
|
const isSingleBranch = branches.length === 1;
|
||||||
const titleKey = isSingleBranch ? "branch_prefix.edit_branch_prefix" : "branch_prefix.edit_branch_prefix_multiple";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
className="branch-prefix-dialog"
|
className="branch-prefix-dialog"
|
||||||
title={t(titleKey, { count: branches.length })}
|
title={isSingleBranch ? t("branch_prefix.edit_branch_prefix") : t("branch_prefix.edit_branch_prefix_multiple", { count: branches.length })}
|
||||||
size="lg"
|
size="lg"
|
||||||
onShown={() => branchInput.current?.focus()}
|
onShown={() => branchInput.current?.focus()}
|
||||||
onHidden={() => setShown(false)}
|
onHidden={() => setShown(false)}
|
||||||
@@ -108,14 +108,14 @@ export default function BranchPrefixDialog() {
|
|||||||
</div>
|
</div>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
{!isSingleBranch && (
|
{!isSingleBranch && (
|
||||||
<div className="branch-prefix-notes-list" style={{ marginTop: "10px" }}>
|
<div className="branch-prefix-notes-list">
|
||||||
<strong>{t("branch_prefix.affected_branches", { count: branches.length })}</strong>
|
<strong>{t("branch_prefix.affected_branches", { count: branches.length })}</strong>
|
||||||
<ul style={{ maxHeight: "200px", overflow: "auto", marginTop: "5px" }}>
|
<ul>
|
||||||
{branches.map((branch) => {
|
{branches.map((branch) => {
|
||||||
const note = branch.getNoteFromCache();
|
const note = branch.getNoteFromCache();
|
||||||
return (
|
return (
|
||||||
<li key={branch.branchId}>
|
<li key={branch.branchId}>
|
||||||
{branch.prefix && <span style={{ color: "#888" }}>{branch.prefix} - </span>}
|
{branch.prefix && <span className="branch-prefix-current">{branch.prefix} - </span>}
|
||||||
{note.title}
|
{note.title}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1591,6 +1591,20 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||||||
this.clearSelectedNodes();
|
this.clearSelectedNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async editBranchPrefixCommand({ node }: CommandListenerData<"editBranchPrefix">) {
|
||||||
|
const branchIds = this.getSelectedOrActiveBranchIds(node).filter((branchId) => !branchId.startsWith("virt-"));
|
||||||
|
|
||||||
|
if (!branchIds.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger the event with the selected branch IDs
|
||||||
|
appContext.triggerEvent("editBranchPrefix", {
|
||||||
|
selectedOrActiveBranchIds: branchIds,
|
||||||
|
node: node
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
canBeMovedUpOrDown(node: Fancytree.FancytreeNode) {
|
canBeMovedUpOrDown(node: Fancytree.FancytreeNode) {
|
||||||
if (node.data.noteId === "root") {
|
if (node.data.noteId === "root") {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user