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 FNote from "../../../entities/fnote";
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 ViewModeStorage from "../view_mode_storage";
import { BoardData } from "./config";
@ -40,7 +40,8 @@ export default class BoardApi {
const { note } = await note_create.createNote(this._parentNoteId, {
activate: false,
targetBranchId: relativeToBranchId,
target: direction
target: direction,
title: "New item"
});
if (!note) {
@ -52,6 +53,8 @@ export default class BoardApi {
if (open) {
this.openNote(noteId);
}
return note;
}
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 { t } from "../../../services/i18n.js";
import BoardApi from "./api.js";
import type BoardView from "./index.js";
interface ShowNoteContextMenuArgs {
$container: JQuery<HTMLElement>;
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-column", showColumnContextMenu);
@ -71,12 +73,12 @@ export function setupContextMenu({ $container, api }: ShowNoteContextMenuArgs) {
{
title: t("board_view.insert-above"),
uiIcon: "bx bx-list-plus",
handler: () => api.insertRowAtPosition(column, branchId, "before")
handler: () => boardView.insertItemAtPosition(column, branchId, "before")
},
{
title: t("board_view.insert-below"),
uiIcon: "bx bx-empty",
handler: () => api.insertRowAtPosition(column, branchId, "after")
handler: () => boardView.insertItemAtPosition(column, branchId, "after")
},
{ title: "----" },
{

View file

@ -311,7 +311,8 @@ export default class BoardView extends ViewMode<BoardData> {
setupContextMenu({
$container: this.$container,
api: this.api
api: this.api,
boardView: this
});
// 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) {
this.renderer?.startInlineEditing(noteId);
}