Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug after porting tab manager #1340

Merged
merged 9 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions e2e/support/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export default class App {
*/
async closeAllTabs() {
await this.triggerCommand("closeAllTabs");
// Page in Playwright is not updated somehow, need to click on the tab to make sure it's rendered
await this.getTab(0).click();
}

/**
Expand Down
21 changes: 8 additions & 13 deletions src/public/app/components/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import type LoadResults from "../services/load_results.js";
import type { Attribute } from "../services/attribute_parser.js";
import type NoteTreeWidget from "../widgets/note_tree.js";
import type { default as NoteContext, GetTextEditorCallback } from "./note_context.js";
import type { ContextMenuEvent } from "../menus/context_menu.js";
import type TypeWidget from "../widgets/type_widgets/type_widget.js";
import type EditableTextTypeWidget from "../widgets/type_widgets/editable_text.js";
import type FAttribute from "../entities/fattribute.js";
Expand Down Expand Up @@ -58,8 +57,8 @@ export interface ContextMenuCommandData extends CommandData {
}

export interface NoteCommandData extends CommandData {
notePath?: string;
hoistedNoteId?: string;
notePath?: string | null;
hoistedNoteId?: string | null;
viewScope?: ViewScope;
}

Expand Down Expand Up @@ -297,16 +296,13 @@ type EventMappings = {
noteContext: NoteContext;
notePath?: string | null;
};
noteSwitchedAndActivatedEvent: {
noteSwitchedAndActivated: {
noteContext: NoteContext;
notePath: string;
};
setNoteContext: {
noteContext: NoteContext;
};
noteTypeMimeChangedEvent: {
noteId: string;
};
reEvaluateHighlightsListWidgetVisibility: {
noteId: string | undefined;
};
Expand All @@ -327,22 +323,22 @@ type EventMappings = {
noteId: string;
ntxId: string | null;
};
contextsReopenedEvent: {
mainNtxId: string;
contextsReopened: {
mainNtxId: string | null;
tabPosition: number;
};
noteDetailRefreshed: {
ntxId?: string | null;
};
noteContextReorderEvent: {
noteContextReorder: {
oldMainNtxId: string;
newMainNtxId: string;
ntxIdsInOrder: string[];
};
newNoteContextCreated: {
noteContext: NoteContext;
};
noteContextRemovedEvent: {
noteContextRemoved: {
ntxIds: string[];
};
exportSvg: {
Expand All @@ -363,12 +359,11 @@ type EventMappings = {
relationMapResetPanZoom: { ntxId: string | null | undefined };
relationMapResetZoomIn: { ntxId: string | null | undefined };
relationMapResetZoomOut: { ntxId: string | null | undefined };
activeNoteChangedEvent: {};
activeNoteChanged: {};
showAddLinkDialog: {
textTypeWidget: EditableTextTypeWidget;
text: string;
};

};

export type EventListener<T extends EventNames> = {
Expand Down
16 changes: 13 additions & 3 deletions src/public/app/components/entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ export default class Entrypoints extends Component {
}

async toggleNoteHoistingCommand({ noteId = appContext.tabManager.getActiveContextNoteId() }) {
if (!noteId) {
const activeNoteContext = appContext.tabManager.getActiveContext();

if (!activeNoteContext || !noteId) {
return;
}

const noteToHoist = await froca.getNote(noteId);
const activeNoteContext = appContext.tabManager.getActiveContext();

if (noteToHoist?.noteId === activeNoteContext.hoistedNoteId) {
await activeNoteContext.unhoist();
Expand All @@ -83,6 +84,11 @@ export default class Entrypoints extends Component {
async hoistNoteCommand({ noteId }: { noteId: string }) {
const noteContext = appContext.tabManager.getActiveContext();

if (!noteContext) {
logError("hoistNoteCommand: noteContext is null");
return;
}

if (noteContext.hoistedNoteId !== noteId) {
await noteContext.setHoistedNoteId(noteId);
}
Expand Down Expand Up @@ -174,7 +180,11 @@ export default class Entrypoints extends Component {
}

async runActiveNoteCommand() {
const { ntxId, note } = appContext.tabManager.getActiveContext();
const noteContext = appContext.tabManager.getActiveContext();
if (!noteContext) {
return;
}
const { ntxId, note } = noteContext;

// ctrl+enter is also used elsewhere, so make sure we're running only when appropriate
if (!note || note.type !== "code") {
Expand Down
Loading