From 271dde4d1d7e6ab2eaadf47ed153f12f2e1f67b1 Mon Sep 17 00:00:00 2001 From: sawka Date: Thu, 6 Oct 2022 18:35:01 -0700 Subject: [PATCH] checkpoint on screen window changes --- src/main.tsx | 7 +++- src/model.ts | 104 +++++++++++++++++++++++++++++++++++++++++++++------ src/types.ts | 2 + 3 files changed, 101 insertions(+), 12 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index 3752cb5d..c803cc1c 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -357,9 +357,10 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width let termOpts = cmd.getTermOpts(); let isFocused = sw.getIsFocused(line.cmdid); let lineNumStr = (line.linenumtemp ? "~" : "") + String(line.linenum); + let isSelected = (sw.selectedLine.get() == line.linenum); return (
-
+
{lineNumStr} @@ -1699,11 +1700,15 @@ class ScreenWindowView extends React.Component<{sw : ScreenWindow}, {}> { @boundMethod scrollHandler(event : any) { let {sw} = this.props; + if (sw == null) { + return; + } let target = event.target; let atBottom = (target.scrollTop + 30 > (target.scrollHeight - target.offsetHeight)); if (sw.shouldFollow.get() != atBottom) { mobx.action(() => sw.shouldFollow.set(atBottom))(); } + sw.setScrollTop_debounced(target.scrollTop); // console.log("scroll-handler (sw)>", atBottom, target.scrollTop, target.scrollHeight, event); } diff --git a/src/model.ts b/src/model.ts index 997f3822..fe978f00 100644 --- a/src/model.ts +++ b/src/model.ts @@ -260,19 +260,78 @@ class ScreenWindow { windowId : string; name : OV; layout : OV; - shouldFollow : OV = mobx.observable.box(true); lastCols : number; - selectedLine : OV = mobx.observable.box(null); + selectedLine : OV; + scrollTop : OV; + shouldFollow : OV = mobx.observable.box(true); // cmdid => TermWrap terms : Record = {}; + setScrollTop_debounced : (scrollTop : number) => void; + constructor(swdata : ScreenWindowType) { this.sessionId = swdata.sessionid; this.screenId = swdata.screenid; this.windowId = swdata.windowid; this.name = mobx.observable.box(swdata.name); this.layout = mobx.observable.box(swdata.layout); + this.selectedLine = mobx.observable.box(swdata.selectedline == 0 ? null : swdata.selectedline); + this.scrollTop = mobx.observable.box(swdata.scrolltop); + this.setScrollTop_debounced = debounce(1000, this.setScrollTop.bind(this)); + } + + setScrollTop(scrollTop : number) : void { + GlobalCommandRunner.swSetScrollTop(this.sessionId, this.screenId, this.windowId, scrollTop); + } + + getMaxLineNum() : number { + let win = this.getWindow(); + if (win == null) { + return null; + } + let lines = win.lines; + if (lines == null || lines.length == 0) { + return null; + } + return lines[lines.length-1].linenum; + } + + getPresentLineNum(lineNum : number) : number { + let win = this.getWindow(); + if (win == null || !win.loaded.get()) { + return lineNum; + } + let lines = win.lines; + if (lines == null || lines.length == 0) { + return null; + } + for (let i=0; i lineNum) { + return line.linenum; + } + } + return lines[lines.length-1].linenum; + } + + setSelectedLine(lineNum : number) : void { + mobx.action(() => { + let pln = this.getPresentLineNum(lineNum); + if (pln != this.selectedLine.get()) { + this.selectedLine.set(pln); + } + })(); + } + + checkSelectedLine() : void { + let pln = this.getPresentLineNum(this.selectedLine.get()); + if (pln != this.selectedLine.get()) { + this.setSelectedLine(pln); + } } updatePtyData(ptyMsg : PtyDataUpdateType) { @@ -372,10 +431,10 @@ class ScreenWindow { class Window { sessionId : string; windowId : string; - curRemote : OV = mobx.observable.box(null); - loaded : OV = mobx.observable.box(false); + curRemote : OV = mobx.observable.box(null, {name: "window-curRemote"}); + loaded : OV = mobx.observable.box(false, {name: "window-loaded"}); loadError : OV = mobx.observable.box(null); - lines : OArr = mobx.observable.array([], {deep: false}); + lines : OArr = mobx.observable.array([], {name: "window-lines", deep: false}); cmds : Record = {}; constructor(sessionId : string, windowId : string) { @@ -1254,13 +1313,13 @@ type LineFocusType = { class Model { clientId : string; - activeSessionId : OV = mobx.observable.box(null); - sessionListLoaded : OV = mobx.observable.box(false); + activeSessionId : OV = mobx.observable.box(null, {name: "activeSessionId"}); + sessionListLoaded : OV = mobx.observable.box(false, {name: "sessionListLoaded"}); sessionList : OArr = mobx.observable.array([], {name: "SessionList", deep: false}); ws : WSControl; - remotes : OArr = mobx.observable.array([], {deep: false}); - remotesLoaded : OV = mobx.observable.box(false); - windows : OMap = mobx.observable.map({}, {deep: false}); // key = "sessionid/windowid" + remotes : OArr = mobx.observable.array([], {name: "remotes", deep: false}); + remotesLoaded : OV = mobx.observable.box(false, {name: "remotesLoaded"}); + windows : OMap = mobx.observable.map({}, {name: "windows", deep: false}); // key = "sessionid/windowid" inputModel : InputModel; termUsedRowsCache : Record = {}; remotesModalOpen : OV = mobx.observable.box(false); @@ -1385,6 +1444,14 @@ class Model { } onMetaArrowUp() : void { + GlobalCommandRunner.swSelectLine("-"); + } + + onMetaArrowDown() : void { + GlobalCommandRunner.swSelectLine("+"); + } + + onMetaArrowUpOld() : void { let focus = this.getFocusedLine(); if (focus == null) { return; @@ -1434,7 +1501,7 @@ class Model { console.log("arrow-up", this.getFocusedLine(), "=>", switchLine); } - onMetaArrowDown() : void { + onMetaArrowDownOld() : void { let focus = this.getFocusedLine(); if (focus == null || focus.cmdInputFocus) { return; @@ -1960,6 +2027,21 @@ class CommandRunner { archiveRemote(remoteid : string) { GlobalModel.submitCommand("remote", "archive", null, {"remote": remoteid, "nohist": "1"}, true); } + + swSelectLine(lineArg : string) { + GlobalModel.submitCommand("sw", "set", null, {"nohist": "1", "line": lineArg}, true); + } + + swSetScrollTop(sessionId : string, screenId : string, windowId : string, scrollTopVal : number) { + let kwargs = { + "nohist": "1", + "scrolltop": String(scrollTopVal), + "session": sessionId, + "screen": screenId, + "window": windowId, + }; + GlobalModel.submitCommand("sw", "set", null, kwargs, true); + } }; let GlobalModel : Model = null; diff --git a/src/types.ts b/src/types.ts index 803ddb5d..91b76ec7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -67,6 +67,8 @@ type ScreenWindowType = { windowid : string, name : string, layout : LayoutType, + selectedline : number, + scrolltop : number, // for updates remove? : boolean,