feat(views/board): use same note title editing mechanism for insert above/below

This commit is contained in:
Elian Doran 2025-07-21 14:32:03 +03:00
parent 96ca3d5e38
commit d0ea6d9e8d
No known key found for this signature in database
3 changed files with 29 additions and 6 deletions

View file

@ -1,7 +1,7 @@
import appContext from "../../../components/app_context"; import appContext from "../../../components/app_context";
import FNote from "../../../entities/fnote"; import FNote from "../../../entities/fnote";
import attributes from "../../../services/attributes"; import attributes from "../../../services/attributes";
import bulk_action, { executeBulkActions } from "../../../services/bulk_action"; import { executeBulkActions } from "../../../services/bulk_action";
import note_create from "../../../services/note_create"; import note_create from "../../../services/note_create";
import ViewModeStorage from "../view_mode_storage"; import ViewModeStorage from "../view_mode_storage";
import { BoardData } from "./config"; import { BoardData } from "./config";
@ -40,7 +40,8 @@ export default class BoardApi {
const { note } = await note_create.createNote(this._parentNoteId, { const { note } = await note_create.createNote(this._parentNoteId, {
activate: false, activate: false,
targetBranchId: relativeToBranchId, targetBranchId: relativeToBranchId,
target: direction target: direction,
title: "New item"
}); });
if (!note) { if (!note) {
@ -52,6 +53,8 @@ export default class BoardApi {
if (open) { if (open) {
this.openNote(noteId); this.openNote(noteId);
} }
return note;
} }
async renameColumn(oldValue: string, newValue: string, noteIds: string[]) { async renameColumn(oldValue: string, newValue: string, noteIds: string[]) {

View file

@ -4,13 +4,15 @@ import branches from "../../../services/branches.js";
import dialog from "../../../services/dialog.js"; import dialog from "../../../services/dialog.js";
import { t } from "../../../services/i18n.js"; import { t } from "../../../services/i18n.js";
import BoardApi from "./api.js"; import BoardApi from "./api.js";
import type BoardView from "./index.js";
interface ShowNoteContextMenuArgs { interface ShowNoteContextMenuArgs {
$container: JQuery<HTMLElement>; $container: JQuery<HTMLElement>;
api: BoardApi; api: BoardApi;
boardView: BoardView;
} }
export function setupContextMenu({ $container, api }: ShowNoteContextMenuArgs) { export function setupContextMenu({ $container, api, boardView }: ShowNoteContextMenuArgs) {
$container.on("contextmenu", ".board-note", showNoteContextMenu); $container.on("contextmenu", ".board-note", showNoteContextMenu);
$container.on("contextmenu", ".board-column", showColumnContextMenu); $container.on("contextmenu", ".board-column", showColumnContextMenu);
@ -71,12 +73,12 @@ export function setupContextMenu({ $container, api }: ShowNoteContextMenuArgs) {
{ {
title: t("board_view.insert-above"), title: t("board_view.insert-above"),
uiIcon: "bx bx-list-plus", uiIcon: "bx bx-list-plus",
handler: () => api.insertRowAtPosition(column, branchId, "before") handler: () => boardView.insertItemAtPosition(column, branchId, "before")
}, },
{ {
title: t("board_view.insert-below"), title: t("board_view.insert-below"),
uiIcon: "bx bx-empty", uiIcon: "bx bx-empty",
handler: () => api.insertRowAtPosition(column, branchId, "after") handler: () => boardView.insertItemAtPosition(column, branchId, "after")
}, },
{ title: "----" }, { title: "----" },
{ {

View file

@ -311,7 +311,8 @@ export default class BoardView extends ViewMode<BoardData> {
setupContextMenu({ setupContextMenu({
$container: this.$container, $container: this.$container,
api: this.api api: this.api,
boardView: this
}); });
// Setup column title editing and add column functionality // Setup column title editing and add column functionality
@ -437,6 +438,23 @@ export default class BoardView extends ViewMode<BoardData> {
} }
} }
async insertItemAtPosition(column: string, relativeToBranchId: string, direction: "before" | "after"): Promise<void> {
try {
// Create the note without opening it
const newNote = await this.api?.insertRowAtPosition(column, relativeToBranchId, direction, false);
if (newNote) {
// Refresh the board to show the new item
await this.renderList();
// Start inline editing of the newly created card
this.startInlineEditingCard(newNote.noteId);
}
} catch (error) {
console.error("Failed to insert new item:", error);
}
}
private startInlineEditingCard(noteId: string) { private startInlineEditingCard(noteId: string) {
this.renderer?.startInlineEditing(noteId); this.renderer?.startInlineEditing(noteId);
} }