diff --git a/src/main.tsx b/src/main.tsx index fb426f29..10f94bf7 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -189,6 +189,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width termLoaded : mobx.IObservableValue = mobx.observable.box(false); lineRef : React.RefObject = React.createRef(); + constructor(props) { super(props); } @@ -221,7 +222,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width console.log("cannot load terminal, no term elem found", termId); return; } - sw.connectElem(termElem, cmd, this.props.width); + sw.connectElem(termElem, line, cmd, this.props.width); mobx.action(() => this.termLoaded.set(true))(); } @@ -315,6 +316,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width let {sw, line, width, staticRender, visible} = this.props; let model = GlobalModel; let lineid = line.lineid; + let isVisible = visible.get(); let formattedTime = getLineDateStr(line.ts); let cmd = model.getCmd(line); if (cmd == null) { @@ -330,11 +332,12 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width let remote = model.getRemote(cmd.remoteId); let status = cmd.getStatus(); let termOpts = cmd.getTermOpts(); - let isFocused = sw.getIsFocused(line.cmdid); let lineNumStr = (line.linenumtemp ? "~" : "") + String(line.linenum); let isSelected = (sw.selectedLine.get() == line.linenum); + let isPhysicalFocused = sw.getIsFocused(line.cmdid); + let swFocusType = sw.focusType.get(); + let isFocused = isPhysicalFocused && (swFocusType == "cmd" || swFocusType == "cmd-fg"); let isStatic = staticRender; - let isVisible = visible.get(); return (
diff --git a/src/model.ts b/src/model.ts index dc6a00c3..15a4ad37 100644 --- a/src/model.ts +++ b/src/model.ts @@ -278,10 +278,10 @@ class ScreenWindow { 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.focusType = mobx.observable.box(swdata.focustype); - this.selectedLine = mobx.observable.box(swdata.selectedline == 0 ? null : swdata.selectedline); + this.name = mobx.observable.box(swdata.name, {name: "name"}); + this.layout = mobx.observable.box(swdata.layout, {name: "layout"}); + this.focusType = mobx.observable.box(swdata.focustype, {name: "focusType"}); + this.selectedLine = mobx.observable.box(swdata.selectedline == 0 ? null : swdata.selectedline, {name: "selectedLine"}); this.setAnchor_debounced = debounce(1000, this.setAnchor.bind(this)); if (swdata.selectedline != 0) { this.anchorLine = swdata.selectedline; @@ -293,12 +293,37 @@ class ScreenWindow { mobx.action(() => { this.name.set(swdata.name); this.layout.set(swdata.layout); + let oldSelectedLine = this.selectedLine.get(); + let oldFocusType = this.focusType.get(); this.selectedLine.set(swdata.selectedline); this.focusType.set(swdata.focustype); + this.refocusLine(swdata, oldFocusType, oldSelectedLine); // do not update anchorLine/anchorOffset (only stored) })(); } + refocusLine(swdata : ScreenWindowType, oldFocusType : string, oldSelectedLine : number) : void { + let isCmdFocus = (swdata.focustype == "cmd" || swdata.focustype == "cmd-fg"); + if (!isCmdFocus) { + return; + } + let curLineFocus = GlobalModel.getFocusedLine(); + let sline : LineType = null; + if (swdata.selectedline != 0) { + sline = this.getLineByNum(swdata.selectedline); + } + // console.log("refocus", curLineFocus.linenum, "=>", swdata.selectedline, sline.cmdid); + if (curLineFocus.cmdInputFocus || (curLineFocus.linenum != null && curLineFocus.linenum != swdata.selectedline)) { + (document.activeElement as HTMLElement).blur(); + } + if (sline != null && sline.cmdid != null) { + let termWrap = this.getTermWrap(sline.cmdid); + if (termWrap != null && termWrap.terminal != null) { + termWrap.terminal.focus(); + } + } + } + setFocusType(ftype : "input" | "cmd" | "cmd-fg") : void { mobx.action(() => { this.focusType.set(ftype); @@ -322,6 +347,23 @@ class ScreenWindow { return lines[lines.length-1].linenum; } + getLineByNum(lineNum : number) : LineType { + let win = this.getWindow(); + if (win == null) { + return null; + } + let lines = win.lines; + if (lines == null || lines.length == 0) { + return null; + } + for (let i=0; i", switchLine); } - onMetaArrowDownOld() : void { - let focus = this.getFocusedLine(); - if (focus == null || focus.cmdInputFocus) { - return; - } - let sw = this.getSWByWindowId(focus.windowid); - if (sw == null) { - return; - } - let win = sw.getWindow(); - if (win == null) { - return; - } - let runningLines = win.getRunningCmdLines(); - if (runningLines.length == 0) { - this.inputModel.giveFocus(); - return; - } - let foundIdx = -1; - for (let i=0; i