allow line to be selected (don't change focus when selecting text). working on contextmenu

This commit is contained in:
sawka 2023-01-02 14:08:24 -08:00
parent 6a5be9652d
commit 7ccd842bf7
5 changed files with 51 additions and 13 deletions

View File

@ -354,6 +354,17 @@ 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,
@ -437,6 +448,12 @@ electron.ipcMain.on("context-screen", (event, {screenId}, {x, y}) => {
menu.popup({x, y});
});
electron.ipcMain.on("context-editmenu", (event, {x, y}) => {
console.log("context-editmenu");
let menu = getCutCopyPasteMenu();
menu.popup({x, y});
});
async function createMainWindowWrap() {
let clientData = null;
try {

View File

@ -402,6 +402,13 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
@boundMethod
handleClick() {
let {line} = this.props;
let sel = window.getSelection();
if (this.lineRef.current != null) {
let selText = sel.toString();
if (sel.anchorNode != null && this.lineRef.current.contains(sel.anchorNode) && !isBlank(selText)) {
return;
}
}
GlobalCommandRunner.swSelectLine(String(line.linenum), "cmd");
}
@ -456,15 +463,15 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
<div className={mainDivCn} id={"line-" + getLineId(line)}
ref={this.lineRef} onClick={this.handleClick}
data-lineid={line.lineid} data-linenum={line.linenum} data-windowid={line.windowid} data-cmdid={line.cmdid}>
<div className={cn("focus-indicator", {"selected": isSelected}, {"active": isSelected && isFocused}, {"fg-focus": isFgFocused})}/>
<div className="line-header">
<div key="focus" className={cn("focus-indicator", {"selected": isSelected}, {"active": isSelected && isFocused}, {"fg-focus": isFgFocused})}/>
<div key="header" className="line-header">
<LineAvatar line={line} cmd={cmd}/>
<div className="meta-wrap">
<div className="meta">
<div key="meta" className="meta-wrap">
<div key="meta1" className="meta">
<div className="user" style={{display: "none"}}>{line.userid}</div>
<div className="ts">{formattedTime}</div>
</div>
<div className="meta">
<div key="meta2" className="meta">
<div className="metapart-mono" style={{display: "none"}}>
{line.cmdid}
({termOpts.rows}x{termOpts.cols})
@ -472,8 +479,8 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
{this.renderCmdText(cmd, remote)}
</div>
</div>
<div className="flex-spacer"/>
<div className={cn("line-star", {"active": line.star > 0})} onClick={this.clickStar}>
<div key="spacer" className="flex-spacer"/>
<div key="star" className={cn("line-star", {"active": line.star > 0})} onClick={this.clickStar}>
<If condition={!line.star || line.star == 0}>
<i className="fa fa-star-o"/>
</If>
@ -482,15 +489,15 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
</If>
</div>
</div>
<div className={cn("terminal-wrapper", {"focus": isFocused}, {"cmd-done": !cmd.isRunning()}, {"zero-height": (termHeight == 0)})}>
<div key="term-wrap" className={cn("terminal-wrapper", {"focus": isFocused}, {"cmd-done": !cmd.isRunning()}, {"zero-height": (termHeight == 0)})}>
<If condition={!isFocused}>
<div className="term-block" onClick={this.clickTermBlock}></div>
<div key="term-block" className="term-block" onClick={this.clickTermBlock}></div>
</If>
<div className="terminal-connectelem" id={"term-" + getLineId(line)} data-cmdid={line.cmdid} style={{height: termHeight}}></div>
<If condition={!termLoaded}><div className="terminal-loading-message">(loading)</div></If>
<div key="term-connectelem" className="terminal-connectelem" id={"term-" + getLineId(line)} data-cmdid={line.cmdid} style={{height: termHeight}}></div>
<If condition={!termLoaded}><div key="term-loading" className="terminal-loading-message">(loading)</div></If>
</div>
<If condition={cmd.getRtnState()}>
<div className="cmd-rtnstate" style={{visibility: ((cmd.getStatus() == "done") ? "visible" : "hidden")}}>
<div key="rtnstate" className="cmd-rtnstate" style={{visibility: ((cmd.getStatus() == "done") ? "visible" : "hidden")}}>
<If condition={rsdiff == null || rsdiff == ""}>
<div className="cmd-rtnstate-label">state unchanged</div>
<div className="cmd-rtnstate-sep"></div>

View File

@ -107,6 +107,7 @@ type ElectronApi = {
onBracketCmd : (callback : (event : any, arg : {relative : number}, mods : KeyModsType) => void) => void,
onDigitCmd : (callback : (event : any, arg : {digit : number}, mods : KeyModsType) => void) => void,
contextScreen : (screenOpts : {screenId : string}, position : {x : number, y : number}) => void,
contextEditMenu : (position : {x : number, y : number}) => void,
onLocalServerStatusChange : (callback : (status : boolean, pid : number) => void) => void,
};
@ -1576,6 +1577,7 @@ class Model {
getApi().onDigitCmd(this.onDigitCmd.bind(this));
getApi().onLocalServerStatusChange(this.onLocalServerStatusChange.bind(this));
document.addEventListener("keydown", this.docKeyDownHandler.bind(this));
document.addEventListener("selectionchange", this.docSelectionChangeHandler.bind(this));
}
getBaseHostPort() : string {
@ -1598,6 +1600,10 @@ class Model {
};
}
docSelectionChangeHandler(e : any) {
// nothing for now
}
docKeyDownHandler(e : any) {
if (isModKeyPress(e)) {
return;
@ -1649,10 +1655,13 @@ class Model {
}
contextScreen(e : any, screenId : string) {
console.log("model", screenId);
getApi().contextScreen({screenId: screenId}, {x: e.x, y: e.y});
}
contextEditMenu(e : any) {
getApi().contextEditMenu({x: e.x, y: e.y});
}
getUIContext() : UIContextType {
let rtn : UIContextType = {
sessionid : null,

View File

@ -18,5 +18,6 @@ contextBridge.exposeInMainWorld("api", {
onBracketCmd: (callback) => ipcRenderer.on("bracket-cmd", callback),
onDigitCmd: (callback) => ipcRenderer.on("digit-cmd", callback),
contextScreen: (screenOpts, position) => ipcRenderer.send("context-screen", screenOpts, position),
contextEditMenu: (position) => ipcRenderer.send("context-editmenu", position),
onLocalServerStatusChange: (callback) => ipcRenderer.on("local-server-status-change", callback),
});

View File

@ -108,6 +108,10 @@ class TermWrap {
this.terminal.attachCustomKeyEventHandler((e) => opts.customKeyHandler(e, this));
}
this.reloadTerminal(0);
elem.addEventListener("contextmenu", (e) => {
console.log("elem-contextmenu", elem, e);
GlobalModel.contextEditMenu(e);
});
}
@boundMethod