scroll lines, uicontext

This commit is contained in:
sawka
2022-08-29 13:54:11 -07:00
parent b8311c4e77
commit b0b6f18cfb
3 changed files with 92 additions and 7 deletions
+33 -1
View File
@@ -29,6 +29,21 @@ function isBlank(s : string) : boolean {
return (s == null || s == "");
}
function windowLinesDOMId(windowid : string) {
return "window-lines-" + windowid;
}
function scrollDiv(div : any, amt : number) {
if (div == null) {
return;
}
let newScrollTop = div.scrollTop + amt;
if (newScrollTop < 0) {
newScrollTop = 0;
}
div.scrollTo({top: newScrollTop, behavior: "smooth"});
}
function interObsCallback(entries) {
let now = Date.now();
entries.forEach((entry) => {
@@ -454,6 +469,23 @@ class TextAreaInput extends React.Component<{}, {}> {
return;
}
}
if (e.code == "PageUp" || e.code == "PageDown") {
e.preventDefault();
let infoScroll = GlobalModel.hasScrollingInfoMsg();
if (infoScroll) {
let div = document.querySelector(".cmd-iinput-info");
scrollDiv(div, (e.code == "PageUp" ? -500 : 500));
}
else {
let win = GlobalModel.getActiveWindow();
if (win == null) {
return;
}
let id = windowLinesDOMId(win.windowId);
let div = document.getElementById(id);
scrollDiv(div, (e.code == "PageUp" ? -500 : 500));
}
}
// console.log(e.code, e.keyCode, e.key, event.which, ctrlMod, e);
})();
}
@@ -696,7 +728,7 @@ class ScreenWindowView extends React.Component<{sw : ScreenWindow}, {}> {
}
getLinesDOMId() {
return "window-lines-" + this.getWindowId();
return windowLinesDOMId(this.getWindowId());
}
@boundMethod
+45 -5
View File
@@ -4,7 +4,7 @@ import {boundMethod} from "autobind-decorator";
import {handleJsonFetchResponse, base64ToArray, genMergeData, genMergeSimpleData} from "./util";
import {TermWrap} from "./term";
import {v4 as uuidv4} from "uuid";
import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, RemotePtrType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType} from "./types";
import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, RemotePtrType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType, UIContextType} from "./types";
import {WSControl} from "./ws";
var GlobalUser = "sawka";
@@ -769,7 +769,7 @@ class Model {
let key = sessionId + "/" + cmdId + "/" + width;
this.termUsedRowsCache[key] = usedRows;
}
contextScreen(e : any, screenId : string) {
console.log("model", screenId);
getApi().contextScreen({screenId: screenId}, {x: e.x, y: e.y});
@@ -791,6 +791,44 @@ class Model {
}
}
getUIContext() : UIContextType {
let rtn : UIContextType = {
sessionid : null,
screenid : null,
windowid : null,
remote : null,
};
let session = this.getActiveSession();
if (session != null) {
rtn.sessionid = session.sessionId;
let screen = session.getActiveScreen();
if (screen != null) {
rtn.screenid = screen.screenId;
let win = this.getActiveWindow();
if (win != null) {
rtn.windowid = win.windowId;
rtn.remote = win.curRemote.get();
}
}
}
return rtn;
}
hasScrollingInfoMsg() : boolean {
if (!this.infoShow.get()) {
return false;
}
let info = this.infoMsg.get();
if (info == null) {
return false;
}
let div = document.querySelector(".cmd-input-info");
if (div == null) {
return false;
}
return div.scrollHeight > div.clientHeight;
}
clearInfoMsg(setNull : boolean) {
this.infoTimeoutId = null;
mobx.action(() => {
@@ -1162,13 +1200,14 @@ class Model {
});
}
submitCommand(metaCmd : string, metaSubCmd : string, args : string[], kwargs : Record<string, string>, interactive : boolean) {
submitCommand(metaCmd : string, metaSubCmd : string, args : string[], kwargs : Record<string, string>, interactive : boolean) : void {
let pk : FeCmdPacketType = {
type: "fecmd",
metacmd: metaCmd,
metasubcmd: metaSubCmd,
args: args,
kwargs: Object.assign({}, this.getClientKwargs(), kwargs),
uicontext : this.getUIContext(),
};
this.submitCommandPacket(pk, interactive);
}
@@ -1179,6 +1218,7 @@ class Model {
metacmd: "eval",
args: [cmdStr],
kwargs: this.getClientKwargs(),
uicontext : this.getUIContext(),
};
if (!addToHistory) {
pk.kwargs["nohist"] = "1";
@@ -1186,7 +1226,7 @@ class Model {
this.submitCommandPacket(pk, interactive)
}
loadSessionList() {
loadSessionList() : void {
let url = new URL("http://localhost:8080/api/get-all-sessions");
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
this.runUpdate(data.data, false);
@@ -1331,7 +1371,7 @@ class InputClass {
clearCmdInput() : void {
mobx.action(() => {
GlobalModel.clearInfoMsg(true);
GlobalModel.clearCurLine();
GlobalModel.inputModel.clearCurLine();
})();
}
+14 -1
View File
@@ -137,12 +137,20 @@ type CmdRemoteStateType = {
cwd : string,
};
type UIContextType = {
sessionid : string,
screenid : string,
windowid : string,
remote : RemotePtrType,
};
type FeCmdPacketType = {
type : string,
metacmd : string,
metasubcmd? : string,
args : string[],
kwargs : Record<string, string>;
uicontext : UIContextType,
};
type WatchScreenPacketType = {
@@ -207,6 +215,11 @@ type ModelUpdateType = {
info? : InfoType,
cmdline? : CmdLineUpdateType,
remote? : RemoteType,
history? : HistoryInfoType,
};
type HistoryInfoType = {
items : HistoryItemType[],
};
type CmdLineUpdateType = {
@@ -226,4 +239,4 @@ type InfoType = {
type UpdateMessage = PtyDataUpdateType | ModelUpdateType;
export type {SessionDataType, LineType, RemoteType, RemoteStateType, RemoteInstanceType, WindowDataType, HistoryItem, CmdRemoteStateType, FeCmdPacketType, TermOptsType, CmdStartPacketType, CmdDonePacketType, CmdDataType, ScreenDataType, ScreenOptsType, ScreenWindowType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType, RemotePtrType};
export type {SessionDataType, LineType, RemoteType, RemoteStateType, RemoteInstanceType, WindowDataType, HistoryItem, CmdRemoteStateType, FeCmdPacketType, TermOptsType, CmdStartPacketType, CmdDonePacketType, CmdDataType, ScreenDataType, ScreenOptsType, ScreenWindowType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType, RemotePtrType, UIContextType};