copy to clipboard as keyboard command as well

This commit is contained in:
sawka 2023-03-05 13:24:29 -08:00
parent 2e4d3c3da7
commit 778d801b88
3 changed files with 69 additions and 25 deletions

View File

@ -31,8 +31,6 @@ function CodeRenderer(props : any) : any {
@mobxReact.observer @mobxReact.observer
class Bookmark extends React.Component<{bookmark : BookmarkType}, {}> { class Bookmark extends React.Component<{bookmark : BookmarkType}, {}> {
copiedIndicator : OV<boolean> = mobx.observable.box(false, {name: "copiedIndicator"});
@boundMethod @boundMethod
handleDeleteClick() : void { handleDeleteClick() : void {
let {bookmark} = this.props; let {bookmark} = this.props;
@ -56,7 +54,7 @@ class Bookmark extends React.Component<{bookmark : BookmarkType}, {}> {
@boundMethod @boundMethod
handleEditUpdate() : void { handleEditUpdate() : void {
let model = GlobalModel.bookmarksModel;opie let model = GlobalModel.bookmarksModel;
model.confirmEdit(); model.confirmEdit();
return; return;
} }
@ -93,16 +91,9 @@ class Bookmark extends React.Component<{bookmark : BookmarkType}, {}> {
@boundMethod @boundMethod
clickCopy() : void { clickCopy() : void {
let bm = this.props.bookmark let bm = this.props.bookmark;
navigator.clipboard.writeText(bm.cmdstr); let model = GlobalModel.bookmarksModel;
mobx.action(() => { model.handleCopyBookmark(bm.bookmarkid);
this.copiedIndicator.set(true);
})();
setTimeout(() => {
mobx.action(() => {
this.copiedIndicator.set(false);
})();
}, 600)
} }
render() { render() {
@ -122,6 +113,7 @@ class Bookmark extends React.Component<{bookmark : BookmarkType}, {}> {
}; };
let hasDesc = markdown != ""; let hasDesc = markdown != "";
let isEditing = (model.editingBookmark.get() == bm.bookmarkid); let isEditing = (model.editingBookmark.get() == bm.bookmarkid);
let isCopied = mobx.computed(() => (model.copiedIndicator.get() == bm.bookmarkid)).get();
if (isEditing) { if (isEditing) {
return ( return (
<div data-bookmarkid={bm.bookmarkid} className={cn("bookmark focus-parent is-editing", {"pending-delete": model.pendingDelete.get() == bm.bookmarkid})}> <div data-bookmarkid={bm.bookmarkid} className={cn("bookmark focus-parent is-editing", {"pending-delete": model.pendingDelete.get() == bm.bookmarkid})}>
@ -153,7 +145,7 @@ class Bookmark extends React.Component<{bookmark : BookmarkType}, {}> {
} }
return ( return (
<div className={cn("bookmark focus-parent", {"pending-delete": model.pendingDelete.get() == bm.bookmarkid})} onClick={this.handleClick}> <div className={cn("bookmark focus-parent", {"pending-delete": model.pendingDelete.get() == bm.bookmarkid})} onClick={this.handleClick}>
<If condition={this.copiedIndicator.get()}> <If condition={isCopied}>
<div className="copied-indicator"> <div className="copied-indicator">
<div>copied</div> <div>copied</div>
</div> </div>
@ -225,6 +217,7 @@ class BookmarksView extends React.Component<{}, {}> {
[Backspace/Delete]x2 or <i className="fa-sharp fa-solid fa-trash"/> to Delete<br/> [Backspace/Delete]x2 or <i className="fa-sharp fa-solid fa-trash"/> to Delete<br/>
[Arrow Up]/[Arrow Down]/[PageUp]/[PageDown] to Move in List<br/> [Arrow Up]/[Arrow Down]/[PageUp]/[PageDown] to Move in List<br/>
[e] or <i className="fa-sharp fa-solid fa-pen"/> to Edit<br/> [e] or <i className="fa-sharp fa-solid fa-pen"/> to Edit<br/>
[c] or <i className="fa-sharp fa-regular fa-copy"/> to Copy<br/>
</div> </div>
</div> </div>
</If> </If>

View File

@ -690,6 +690,28 @@ class ScreenWindow {
getWindow() : Window { getWindow() : Window {
return GlobalModel.getWindowById(this.sessionId, this.windowId); return GlobalModel.getWindowById(this.sessionId, this.windowId);
} }
giveFocus() : void {
if (!this.isActive()) {
return;
}
let ftype = this.focusType.get();
if (ftype == "input") {
GlobalModel.inputModel.giveFocus();
}
else {
let sline : LineType = null;
if (this.selectedLine.get() != 0) {
sline = this.getLineByNum(this.selectedLine.get());
}
if (sline != null) {
let termWrap = this.getRenderer(sline.cmdid);
if (termWrap != null) {
termWrap.giveFocus();
}
}
}
}
} }
class Window { class Window {
@ -1784,9 +1806,8 @@ class HistoryViewModel {
} }
closeView() : void { closeView() : void {
mobx.action(() => { GlobalModel.showSessionView();
GlobalModel.activeMainView.set("session"); setTimeout(() => GlobalModel.inputModel.giveFocus(), 50);
})();
} }
getLineById(lineId : string) : LineType { getLineById(lineId : string) : LineType {
@ -1886,7 +1907,7 @@ class HistoryViewModel {
_getSearchParams(newOffset? : number) : HistorySearchParams { _getSearchParams(newOffset? : number) : HistorySearchParams {
let offset = (newOffset != null ? newOffset : this.offset.get()); let offset = (newOffset != null ? newOffset : this.offset.get());
let opts : HistorySearchParms = { let opts : HistorySearchParams = {
offset: offset, offset: offset,
searchText: this.activeSearchText, searchText: this.activeSearchText,
searchSessionId: this.searchSessionId.get(), searchSessionId: this.searchSessionId.get(),
@ -1980,6 +2001,7 @@ class BookmarksModel {
activeBookmark : OV<string> = mobx.observable.box(null, {name: "activeBookmark"}); activeBookmark : OV<string> = mobx.observable.box(null, {name: "activeBookmark"});
editingBookmark : OV<string> = mobx.observable.box(null, {name: "editingBookmark"}); editingBookmark : OV<string> = mobx.observable.box(null, {name: "editingBookmark"});
pendingDelete : OV<string> = mobx.observable.box(null, {name: "pendingDelete"}); pendingDelete : OV<string> = mobx.observable.box(null, {name: "pendingDelete"});
copiedIndicator : OV<string> = mobx.observable.box(null, {name: "copiedIndicator"});
tempDesc : OV<string> = mobx.observable.box("", {name: "bookmarkEdit-tempDesc"}); tempDesc : OV<string> = mobx.observable.box("", {name: "bookmarkEdit-tempDesc"});
tempCmd : OV<string> = mobx.observable.box("", {name: "bookmarkEdit-tempCmd"}); tempCmd : OV<string> = mobx.observable.box("", {name: "bookmarkEdit-tempCmd"});
@ -2008,9 +2030,8 @@ class BookmarksModel {
} }
closeView() : void { closeView() : void {
mobx.action(() => { GlobalModel.showSessionView();
GlobalModel.activeMainView.set("session"); setTimeout(() => GlobalModel.inputModel.giveFocus(), 50);
})();
} }
@boundMethod @boundMethod
@ -2025,7 +2046,7 @@ class BookmarksModel {
} }
mobx.action(() => { mobx.action(() => {
this.reset(); this.reset();
GlobalModel.activeMainView.set("session"); GlobalModel.showSessionView();
GlobalModel.inputModel.setCurLine(bm.cmdstr); GlobalModel.inputModel.setCurLine(bm.cmdstr);
setTimeout(() => GlobalModel.inputModel.giveFocus(), 50); setTimeout(() => GlobalModel.inputModel.giveFocus(), 50);
})(); })();
@ -2124,6 +2145,22 @@ class BookmarksModel {
})(); })();
} }
handleCopyBookmark(bookmarkId : string) : void {
let bm = this.getBookmark(bookmarkId);
if (bm == null) {
return;
}
navigator.clipboard.writeText(bm.cmdstr);
mobx.action(() => {
this.copiedIndicator.set(bm.bookmarkid);
})();
setTimeout(() => {
mobx.action(() => {
this.copiedIndicator.set(null);
})();
}, 600)
}
mergeBookmarks(bmArr : BookmarkType[]) : void { mergeBookmarks(bmArr : BookmarkType[]) : void {
mobx.action(() => { mobx.action(() => {
genMergeSimpleData(this.bookmarks, bmArr, (bm : BookmarkType) => bm.bookmarkid, (bm : BookmarkType) => sprintf("%05d", bm.orderidx)); genMergeSimpleData(this.bookmarks, bmArr, (bm : BookmarkType) => bm.bookmarkid, (bm : BookmarkType) => sprintf("%05d", bm.orderidx));
@ -2190,6 +2227,14 @@ class BookmarksModel {
this.handleEditBookmark(this.activeBookmark.get()); this.handleEditBookmark(this.activeBookmark.get());
return; return;
} }
if (e.code == "KeyC") {
if (this.activeBookmark.get() == null) {
return;
}
e.preventDefault();
this.handleCopyBookmark(this.activeBookmark.get());
return;
}
} }
return; return;
} }
@ -2290,6 +2335,12 @@ class Model {
} }
} }
showSessionView() : void {
mobx.action(() => {
this.activeMainView.set("session");
})();
}
getBaseHostPort() : string { getBaseHostPort() : string {
if (this.isDev) { if (this.isDev) {
return DevServerEndpoint; return DevServerEndpoint;

View File

@ -134,9 +134,9 @@ type FeStateType = {
}; };
type RemotePtrType = { type RemotePtrType = {
ownerid : string,
remoteid : string, remoteid : string,
name : string, ownerid? : string,
name? : string,
}; };
type WindowDataType = { type WindowDataType = {
@ -432,7 +432,7 @@ type HistorySearchParams = {
searchText? : string, searchText? : string,
searchSessionId? : string, searchSessionId? : string,
searchRemoteId? : string, searchRemoteId? : string,
fromts? : number, fromTs? : number,
noMeta? : boolean, noMeta? : boolean,
}; };