diff --git a/src/emain.ts b/src/emain.ts index 7f023097..c2c08939 100644 --- a/src/emain.ts +++ b/src/emain.ts @@ -354,17 +354,6 @@ function getContextMenu() : any { return menu; } -function getCutCopyPasteMenu() : any { - let menu = new electron.Menu(); - let menuItem = new electron.MenuItem({label: "Cut", role: "cut"}); - menu.append(menuItem); - menuItem = new electron.MenuItem({label: "Copy", role: "copy"}); - menu.append(menuItem); - menuItem = new electron.MenuItem({label: "Paste", role: "paste"}); - menu.append(menuItem); - return menu; -} - function getFetchHeaders() { return { "x-authkey": GlobalAuthKey, @@ -448,9 +437,21 @@ electron.ipcMain.on("context-screen", (event, {screenId}, {x, y}) => { menu.popup({x, y}); }); -electron.ipcMain.on("context-editmenu", (event, {x, y}) => { +electron.ipcMain.on("context-editmenu", (event, {x, y}, opts) => { + if (opts == null) { + opts = {}; + } console.log("context-editmenu"); - let menu = getCutCopyPasteMenu(); + let menu = new electron.Menu(); + let menuItem = null; + if (opts.showCut) { + menuItem = new electron.MenuItem({label: "Cut", role: "cut"}); + menu.append(menuItem); + } + menuItem = new electron.MenuItem({label: "Copy", role: "copy"}); + menu.append(menuItem); + menuItem = new electron.MenuItem({label: "Paste", role: "paste"}); + menu.append(menuItem); menu.popup({x, y}); }); diff --git a/src/main.tsx b/src/main.tsx index 19a9c491..308d9f7e 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -9,7 +9,7 @@ import dayjs from "dayjs"; import {If, For, When, Otherwise, Choose} from "tsx-control-statements/components"; import cn from "classnames"; import {TermWrap} from "./term"; -import type {SessionDataType, LineType, CmdDataType, RemoteType, RemoteStateType, RemoteInstanceType, RemotePtrType, HistoryItem, HistoryQueryOpts, RemoteEditType, FeStateType} from "./types"; +import type {SessionDataType, LineType, CmdDataType, RemoteType, RemoteStateType, RemoteInstanceType, RemotePtrType, HistoryItem, HistoryQueryOpts, RemoteEditType, FeStateType, ContextMenuOpts} from "./types"; import localizedFormat from 'dayjs/plugin/localizedFormat'; import {GlobalModel, GlobalCommandRunner, Session, Cmd, Window, Screen, ScreenWindow, riToRPtr, widthToCols, termWidthFromCols, termHeightFromRows, termRowsFromHeight} from "./model"; import {isModKeyPress} from "./util"; @@ -2672,9 +2672,36 @@ class Main extends React.Component<{}, {}> { super(props); } + @boundMethod + handleContextMenu(e : any) { + let isInNonTermInput = false; + let activeElem = document.activeElement; + if (activeElem != null && activeElem.nodeName == "TEXTAREA") { + if (!activeElem.classList.contains("xterm-helper-textarea")) { + isInNonTermInput = true; + } + } + if (activeElem != null && activeElem.nodeName == "INPUT" && activeElem.getAttribute("type") == "text") { + isInNonTermInput = true; + } + let opts : ContextMenuOpts = {}; + if (isInNonTermInput) { + opts.showCut = true; + } + let sel = window.getSelection(); + if (!isBlank(sel.toString())) { + GlobalModel.contextEditMenu(e, opts); + } + else { + if (isInNonTermInput) { + GlobalModel.contextEditMenu(e, opts); + } + } + } + render() { return ( -