Compare commits

...

3 Commits

Author SHA1 Message Date
SiriusXT
be19d1f5b5 fix(split pane): hide the close button when no split panes exist 2025-11-17 09:24:18 +08:00
SiriusXT
a22687e2d8 Merge branch 'main' into siriusbcd_close_split 2025-11-16 20:15:43 +08:00
SiriusXT
44475853df feat(split): allow closing any split pane 2025-11-16 20:12:56 +08:00
2 changed files with 23 additions and 7 deletions

View File

@@ -1,18 +1,20 @@
import { useEffect, useState } from "preact/hooks"; import { useEffect, useState } from "preact/hooks";
import { t } from "../../services/i18n"; import { t } from "../../services/i18n";
import ActionButton from "../react/ActionButton"; import ActionButton from "../react/ActionButton";
import { useNoteContext, useTriliumEvent } from "../react/hooks"; import { useNoteContext, useTriliumEvents } from "../react/hooks";
import appContext from "../../components/app_context";
export default function ClosePaneButton() { export default function ClosePaneButton() {
const { noteContext, ntxId, parentComponent } = useNoteContext(); const { noteContext, ntxId, parentComponent } = useNoteContext();
const [ isEnabled, setIsEnabled ] = useState(false); const [isEnabled, setIsEnabled] = useState(false);
function refresh() { function refresh() {
setIsEnabled(!!(noteContext && !!noteContext.mainNtxId)); const isMainOfSomeContext = appContext.tabManager.noteContexts.some(c => c.mainNtxId === ntxId);
setIsEnabled(!!(noteContext && (!!noteContext.mainNtxId || isMainOfSomeContext)));
} }
useTriliumEvent("noteContextReorder", refresh); useTriliumEvents(["noteContextRemoved", "noteContextReorder", "newNoteContextCreated"], refresh);
useEffect(refresh, [ ntxId ]); useEffect(refresh, [ntxId]);
return ( return (
<ActionButton <ActionButton

View File

@@ -100,9 +100,23 @@ export default class SplitNoteContainer extends FlexContainer<SplitNoteWidget> {
} }
async closeThisNoteSplitCommand({ ntxId }: CommandListenerData<"closeThisNoteSplit">) { async closeThisNoteSplitCommand({ ntxId }: CommandListenerData<"closeThisNoteSplit">) {
if (ntxId) { if (!ntxId) return;
await appContext.tabManager.removeNoteContext(ntxId); const contexts = appContext.tabManager.noteContexts;
const currentIndex = contexts.findIndex((c) => c.ntxId === ntxId);
if (currentIndex === -1) return;
const isRemoveMainContext = !contexts[currentIndex].mainNtxId;
if (isRemoveMainContext && currentIndex + 1 <= contexts.length) {
const ntxIds = contexts.map((c) => c.ntxId).filter((c) => !!c) as string[];
this.triggerCommand("noteContextReorder", {
ntxIdsInOrder: ntxIds,
oldMainNtxId: ntxId,
newMainNtxId: ntxIds[currentIndex + 1]
});
} }
await appContext.tabManager.removeNoteContext(ntxId);
} }
async moveThisNoteSplitCommand({ ntxId, isMovingLeft }: CommandListenerData<"moveThisNoteSplit">) { async moveThisNoteSplitCommand({ ntxId, isMovingLeft }: CommandListenerData<"moveThisNoteSplit">) {