Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xsline OpenChatCut Context Menu

From Leeroopedia
Knowledge Sources
Domains Desktop, UI
Last Updated 2026-10-22 14:00 GMT

Overview

Native text editing context menu builder for Electron that generates menu items with roles (undo/redo/cut/copy/paste/selectAll) decoupled from Electron APIs for testability.

Description

The Context Menu module takes `TextContextMenuParams` (editable, selectionText, editFlags) and returns `TextContextMenuItem[]` with roles and separators. Non-editable contexts show only copy. Decoupled from Electron so behavior can be tested without the Electron runtime.

Usage

  • Desktop UI: Used by the Electron main process to build native context menus for text editing.

Code Reference

Source Location

  • Repository: OpenChatCut
  • File: desktop/context-menu.ts
  • Lines: 1-34

Signature

export interface TextContextMenuParams {
  editable: boolean;
  selectionText: string;
  editFlags: { canUndo: boolean; canRedo: boolean; canCut: boolean; canCopy: boolean; canPaste: boolean; canSelectAll: boolean };
}

export interface TextContextMenuItem {
  role?: string;
  label?: string;
  separator?: boolean;
}

export function buildTextContextMenuTemplate(params: TextContextMenuParams): TextContextMenuItem[];

Import

import { buildTextContextMenuTemplate, type TextContextMenuParams } from './context-menu.ts';

I/O Contract

Inputs

Name Type Required Description
params TextContextMenuParams Yes Context state (editable, selection, flags)

Outputs

Name Type Description
buildTextContextMenuTemplate() returns TextContextMenuItem[] Menu items for Electron's Menu.buildFromTemplate

Usage Examples

Building a Context Menu

import { buildTextContextMenuTemplate } from './context-menu.ts';

const items = buildTextContextMenuTemplate({
  editable: true,
  selectionText: 'hello',
  editFlags: { canUndo: true, canRedo: false, canCut: true, canCopy: true, canPaste: true, canSelectAll: true }
});

const menu = Menu.buildFromTemplate(items);
menu.popup();

Related Pages

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment