mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-21 21:32:13 +01:00
checkpoint on screen window changes
This commit is contained in:
parent
1939cba14f
commit
271dde4d1d
@ -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 (
|
||||
<div className={cn("line", "line-cmd", {"focus": isFocused})} id={"line-" + getLineId(line)} ref={this.lineRef} style={{position: "relative"}} data-lineid={line.lineid} data-windowid={line.windowid} data-cmdid={line.cmdid}>
|
||||
<div className="focus-indicator"/>
|
||||
<div className={cn("focus-indicator", {"selected": isSelected}, {"active": isSelected && isFocused})}/>
|
||||
<div className="line-header">
|
||||
<div className={cn("avatar", "num-"+lineNumStr.length, "status-" + status, {"ephemeral": line.ephemeral})} onClick={this.doRefresh}>
|
||||
{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);
|
||||
}
|
||||
|
||||
|
104
src/model.ts
104
src/model.ts
@ -260,19 +260,78 @@ class ScreenWindow {
|
||||
windowId : string;
|
||||
name : OV<string>;
|
||||
layout : OV<LayoutType>;
|
||||
shouldFollow : OV<boolean> = mobx.observable.box(true);
|
||||
lastCols : number;
|
||||
selectedLine : OV<number> = mobx.observable.box(null);
|
||||
selectedLine : OV<number>;
|
||||
scrollTop : OV<number>;
|
||||
shouldFollow : OV<boolean> = mobx.observable.box(true);
|
||||
|
||||
// cmdid => TermWrap
|
||||
terms : Record<string, TermWrap> = {};
|
||||
|
||||
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<lines.length; i++) {
|
||||
let line = lines[i];
|
||||
if (line.linenum == lineNum) {
|
||||
return lineNum;
|
||||
}
|
||||
if (line.linenum > 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<RemotePtrType> = mobx.observable.box(null);
|
||||
loaded : OV<boolean> = mobx.observable.box(false);
|
||||
curRemote : OV<RemotePtrType> = mobx.observable.box(null, {name: "window-curRemote"});
|
||||
loaded : OV<boolean> = mobx.observable.box(false, {name: "window-loaded"});
|
||||
loadError : OV<string> = mobx.observable.box(null);
|
||||
lines : OArr<LineType> = mobx.observable.array([], {deep: false});
|
||||
lines : OArr<LineType> = mobx.observable.array([], {name: "window-lines", deep: false});
|
||||
cmds : Record<string, Cmd> = {};
|
||||
|
||||
constructor(sessionId : string, windowId : string) {
|
||||
@ -1254,13 +1313,13 @@ type LineFocusType = {
|
||||
|
||||
class Model {
|
||||
clientId : string;
|
||||
activeSessionId : OV<string> = mobx.observable.box(null);
|
||||
sessionListLoaded : OV<boolean> = mobx.observable.box(false);
|
||||
activeSessionId : OV<string> = mobx.observable.box(null, {name: "activeSessionId"});
|
||||
sessionListLoaded : OV<boolean> = mobx.observable.box(false, {name: "sessionListLoaded"});
|
||||
sessionList : OArr<Session> = mobx.observable.array([], {name: "SessionList", deep: false});
|
||||
ws : WSControl;
|
||||
remotes : OArr<RemoteType> = mobx.observable.array([], {deep: false});
|
||||
remotesLoaded : OV<boolean> = mobx.observable.box(false);
|
||||
windows : OMap<string, Window> = mobx.observable.map({}, {deep: false}); // key = "sessionid/windowid"
|
||||
remotes : OArr<RemoteType> = mobx.observable.array([], {name: "remotes", deep: false});
|
||||
remotesLoaded : OV<boolean> = mobx.observable.box(false, {name: "remotesLoaded"});
|
||||
windows : OMap<string, Window> = mobx.observable.map({}, {name: "windows", deep: false}); // key = "sessionid/windowid"
|
||||
inputModel : InputModel;
|
||||
termUsedRowsCache : Record<string, number> = {};
|
||||
remotesModalOpen : OV<boolean> = 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;
|
||||
|
@ -67,6 +67,8 @@ type ScreenWindowType = {
|
||||
windowid : string,
|
||||
name : string,
|
||||
layout : LayoutType,
|
||||
selectedline : number,
|
||||
scrolltop : number,
|
||||
|
||||
// for updates
|
||||
remove? : boolean,
|
||||
|
Loading…
Reference in New Issue
Block a user