From 3ab2023423b19051cf1cd4245823d9d734bf69b7 Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 31 Aug 2022 13:29:59 -0700 Subject: [PATCH] show global/session history --- src/main.tsx | 44 +++++++++++++++++++---- src/model.ts | 97 ++++++++++++++++++++++++++++++++------------------ src/preload.js | 1 + src/sh2.less | 4 +++ src/types.ts | 1 + 5 files changed, 105 insertions(+), 42 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index 5942b679..fb1b32fc 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -467,7 +467,8 @@ class TextAreaInput extends React.Component<{}, {}> { if (e.code == "ArrowUp" || e.code == "ArrowDown") { if (!inputModel.isHistoryLoaded()) { if (e.code == "ArrowUp") { - inputModel.loadHistory(false, 1); + this.lastHistoryUpDown = true; + inputModel.loadHistory(false, 1, "window"); } return; } @@ -542,14 +543,14 @@ class TextAreaInput extends React.Component<{}, {}> { inputModel.resetInput(); return; } - if (e.code == "KeyM" && e.getModifierState("Meta")) { + if (e.code == "KeyM" && (e.getModifierState("Meta") || e.getModifierState("Control"))) { e.preventDefault(); let opts = mobx.toJS(inputModel.historyQueryOpts.get()); opts.includeMeta = !opts.includeMeta; inputModel.setHistoryQueryOpts(opts); return; } - if (e.code == "KeyR" && (e.getModifierState("Meta") && !e.getModifierState("Shift"))) { + if (e.code == "KeyR" && ((e.getModifierState("Meta") || e.getModifierState("Control")) && !e.getModifierState("Shift"))) { console.log("meta-r"); e.preventDefault(); let opts = mobx.toJS(inputModel.historyQueryOpts.get()); @@ -564,6 +565,22 @@ class TextAreaInput extends React.Component<{}, {}> { inputModel.setHistoryQueryOpts(opts); return; } + if (e.code == "KeyS" && (e.getModifierState("Meta") || e.getModifierState("Control"))) { + e.preventDefault(); + let opts = mobx.toJS(inputModel.historyQueryOpts.get()); + let htype = opts.queryType; + if (htype == "window") { + htype = "session"; + } + else if (htype == "session") { + htype = "global"; + } + else { + htype = "window"; + } + inputModel.setHistoryType(htype); + return; + } if (e.code == "Tab") { e.preventDefault(); return; @@ -695,10 +712,23 @@ class HistoryInfo extends React.Component<{}, {}> { let line : string = ""; let idx = 0; let limitRemote = opts.limitRemote; + let sessionStr = ""; + if (opts.queryType == "global") { + if (!isBlank(hitem.sessionid)) { + let s = GlobalModel.getSessionById(hitem.sessionid); + if (s != null) { + sessionStr = s.name.get(); + if (sessionStr.indexOf(" ") != -1) { + sessionStr = "[" + sessionStr + "]"; + } + sessionStr = sprintf("#%-15s ", sessionStr); + } + } + } return (
this.handleItemClick(hitem)}> -
{(isSelected ? "*" : " ")}{sprintf("%5s", hitem.historynum)} {!limitRemote ? this.renderRemote(hitem) : ""}{lines[0]}
- +
{(isSelected ? "*" : " ")}{sprintf("%5s", hitem.historynum)} {opts.queryType == "global" ? sessionStr : ""}{!limitRemote ? this.renderRemote(hitem) : ""} {lines[0]}
+
{line}
@@ -723,7 +753,7 @@ class HistoryInfo extends React.Component<{}, {}> {
history
-
[for window ⌘W]
+
[for {opts.queryType} ⌘S]
[containing '{opts.queryStr}']
@@ -734,7 +764,7 @@ class HistoryInfo extends React.Component<{}, {}> {
(ESC)
-
+
[no history] diff --git a/src/model.ts b/src/model.ts index 52c50c21..d20b9976 100644 --- a/src/model.ts +++ b/src/model.ts @@ -577,6 +577,7 @@ class InputModel { historyShow : OV = mobx.observable.box(false); infoShow : OV = mobx.observable.box(false); + historyType : mobx.IObservableValue = mobx.observable.box("window"); historyLoading : mobx.IObservableValue = mobx.observable.box(false); historyAfterLoadIndex : number = 0; historyItems : mobx.IObservableValue = mobx.observable.box(null, {name: "history-items", deep: false}); // sorted in reverse (most recent is index 0) @@ -629,33 +630,43 @@ class InputModel { return false; } + setHistoryType(htype : string) : void { + if (this.historyQueryOpts.get().queryType == htype) { + return; + } + this.loadHistory(true, -1, htype); + } + + findBestNewIndex(oldItem : HistoryItem) : number { + if (oldItem == null) { + return 0; + } + let newItems = this.getFilteredHistoryItems(); + if (newItems.length == 0) { + return 0; + } + let bestIdx = 0; + for (let i=0; i { let oldItem = this.getHistorySelectedItem(); this.historyQueryOpts.set(opts); - if (oldItem == null) { - setTimeout(() => this.setHistoryIndex(0, true), 10); - return; - } - let newItems = this.getFilteredHistoryItems(); - if (newItems.length == 0) { - setTimeout(() => this.setHistoryIndex(0, true), 10); - return; - } - let bestIdx = 0; - for (let i=0; i this.setHistoryIndex(bestIdx+1, true), 10); + let bestIndex = this.findBestNewIndex(oldItem); + setTimeout(() => this.setHistoryIndex(bestIndex, true), 10); return; })(); } @@ -680,18 +691,20 @@ class InputModel { return (hitems != null); } - loadHistory(show : boolean, afterLoadIndex : number) { + loadHistory(show : boolean, afterLoadIndex : number, htype : string) { if (this.historyLoading.get()) { return; } if (this.isHistoryLoaded()) { - return; + if (this.historyQueryOpts.get().queryType == htype) { + return; + } } this.historyAfterLoadIndex = afterLoadIndex; mobx.action(() => { this.historyLoading.set(true); })(); - GlobalCommandRunner.loadHistory(show); + GlobalCommandRunner.loadHistory(show, htype); } openHistory() : void { @@ -699,7 +712,7 @@ class InputModel { return; } if (!this.isHistoryLoaded()) { - this.loadHistory(true, 0); + this.loadHistory(true, 0, "window"); return; } if (!this.historyShow.get()) { @@ -756,15 +769,25 @@ class InputModel { setHistoryInfo(hinfo : HistoryInfoType) : void { mobx.action(() => { + let oldItem = this.getHistorySelectedItem(); let hitems : HistoryItem[] = hinfo.items ?? []; this.historyItems.set(hitems); this.historyLoading.set(false); - if (this.historyAfterLoadIndex) { + this.historyQueryOpts.get().queryType = hinfo.historytype; + if (hinfo.historytype == "session" || hinfo.historytype == "global") { + this.historyQueryOpts.get().limitRemote = false; + this.historyQueryOpts.get().limitRemoteInstance = false; + } + if (this.historyAfterLoadIndex == -1) { + let bestIndex = this.findBestNewIndex(oldItem); + setTimeout(() => this.setHistoryIndex(bestIndex, true), 100); + } + else if (this.historyAfterLoadIndex) { if (hitems.length >= this.historyAfterLoadIndex) { this.setHistoryIndex(this.historyAfterLoadIndex); } - this.historyAfterLoadIndex = 0; } + this.historyAfterLoadIndex = 0; if (hinfo.show) { this.openHistory(); } @@ -780,9 +803,9 @@ class InputModel { let rtn : HistoryItem[] = []; let opts = mobx.toJS(this.historyQueryOpts.get()); let ctx = GlobalModel.getUIContext(); - let curRemote = ctx.remote; + let curRemote : RemotePtrType = ctx.remote; if (curRemote == null) { - curRemote : RemotePtrType = {ownerid: "", name: "", remoteid: ""}; + curRemote = {ownerid: "", name: "", remoteid: ""}; } curRemote = mobx.toJS(curRemote); for (let i=0; i { this.setHistoryShow(false); this.historyLoading.set(false); + this.historyType.set("window"); this.historyItems.set(null); this.historyIndex.set(0); this.historyQueryOpts.set(getDefaultHistoryQueryOpts()); @@ -1659,11 +1683,14 @@ class CommandRunner { constructor() { } - loadHistory(show : boolean) { + loadHistory(show : boolean, htype : string) { let kwargs = {"nohist": "1"}; if (!show) { kwargs["noshow"] = "1"; } + if (htype != null && htype != "window") { + kwargs["type"] = htype; + } GlobalModel.submitCommand("history", null, null, kwargs, true); } diff --git a/src/preload.js b/src/preload.js index 427fc568..5fd7970b 100644 --- a/src/preload.js +++ b/src/preload.js @@ -5,6 +5,7 @@ contextBridge.exposeInMainWorld("api", { onTCmd: (callback) => ipcRenderer.on("t-cmd", callback), onICmd: (callback) => ipcRenderer.on("i-cmd", callback), onHCmd: (callback) => ipcRenderer.on("h-cmd", callback), + onWCmd: (callback) => ipcRenderer.on("w-cmd", callback), onMetaArrowUp: (callback) => ipcRenderer.on("meta-arrowup", callback), onMetaArrowDown: (callback) => ipcRenderer.on("meta-arrowdown", callback), onBracketCmd: (callback) => ipcRenderer.on("bracket-cmd", callback), diff --git a/src/sh2.less b/src/sh2.less index b9132751..32b24b32 100644 --- a/src/sh2.less +++ b/src/sh2.less @@ -694,6 +694,10 @@ body .xterm .xterm-viewport { margin-left: 174px; } + &.show-remotes.show-sessions .history-line { + margin-left: 294px; + } + .history-item.history-haderror { color: mix(@term-red, @term-white, 50%); } diff --git a/src/types.ts b/src/types.ts index 313bd232..2d799ed7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -220,6 +220,7 @@ type ModelUpdateType = { }; type HistoryInfoType = { + historytype : "global" | "session" | "window", sessionid : string, windowid : string, items : HistoryItem[],