a bare enter will focus the last line in a window

This commit is contained in:
sawka 2023-01-31 22:22:51 -08:00
parent 65e23f9f48
commit d7d6067fbb
2 changed files with 37 additions and 6 deletions

View File

@ -168,8 +168,8 @@ class LineText extends React.Component<{sw : ScreenWindow, line : LineType}, {}>
render() {
let {sw, line} = this.props;
let formattedTime = getLineDateStr(line.ts);
let isSelected = (sw.selectedLine.get() == line.linenum);
let isFocused = (sw.focusType.get() == "cmd");
let isSelected = mobx.computed(() => (sw.selectedLine.get() == line.linenum), {name: "computed-isSelected"}).get();
let isFocused = mobx.computed(() => (sw.focusType.get() == "cmd"), {name: "computed-isFocused"}).get();
return (
<div className="line line-text" data-lineid={line.lineid} data-linenum={line.linenum} data-windowid={line.windowid} onClick={this.clickHandler}>
<div className={cn("focus-indicator", {"selected": isSelected}, {"active": isSelected && isFocused})}/>
@ -391,6 +391,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
}
if (snapshot.height != curHeight && this.props.onHeightChange != null) {
this.props.onHeightChange(line.linenum, curHeight, snapshot.height);
// console.log("line height change: ", line.linenum, snapshot.height, "=>", curHeight);
}
this.checkLoad();
this.checkStateDiffLoad();
@ -479,7 +480,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
<div className="ts">{formattedTime}</div>
<div className="termopts">
({termOpts.rows}x{termOpts.cols})
<If condition={cmd.isRunning() && false}><i onClick={this.doResizeButton} className="resize-button fa fa-arrows-alt"/></If>
<If condition={cmd.isRunning() && false}><i onClick={this.handleResizeButton} className="resize-button fa fa-arrows-alt"/></If>
</div>
</div>
<div key="meta2" className="meta">
@ -631,8 +632,19 @@ class TextAreaInput extends React.Component<{}, {}> {
if (e.code == "Enter") {
e.preventDefault();
if (!ctrlMod) {
setTimeout(() => GlobalModel.inputModel.uiSubmitCommand(), 0);
return;
if (GlobalModel.inputModel.isEmpty()) {
let activeWindow = GlobalModel.getActiveWindow();
let activeSW = GlobalModel.getActiveSW();
if (activeSW != null && activeWindow != null && activeWindow.lines.length > 0) {
activeSW.setSelectedLine(0);
GlobalCommandRunner.swSelectLine("E");
}
return;
}
else {
setTimeout(() => GlobalModel.inputModel.uiSubmitCommand(), 0);
return;
}
}
e.target.setRangeText("\n", e.target.selectionStart, e.target.selectionEnd, "end");
GlobalModel.inputModel.setCurLine(e.target.value);
@ -1874,8 +1886,8 @@ class LinesView extends React.Component<{sw : ScreenWindow, width : number, line
lastOffsetWidth : number = 0;
ignoreNextScroll : boolean = false;
visibleMap : Map<string, OV<boolean>>; // lineid => OV<vis>
lastSelectedLine : number = 0;
lastLinesLength : number = 0;
lastSelectedLine : number = 0;
computeAnchorLine_throttled : () => void;
computeVisibleMap_debounced : () => void;
@ -2074,6 +2086,9 @@ class LinesView extends React.Component<{sw : ScreenWindow, width : number, line
return null;
}
let newLine = sw.selectedLine.get();
if (newLine == 0) {
return;
}
this.setLineVisible(newLine, true);
// console.log("update selected line", this.lastSelectedLine, "=>", newLine, sprintf("anchor=%d:%d", sw.anchorLine, sw.anchorOffset));
let viewInfo = this.getLineViewInfo(newLine);

View File

@ -422,6 +422,9 @@ class ScreenWindow {
if (lines == null || lines.length == 0) {
return null;
}
if (lineNum == 0) {
return null;
}
for (let i=0; i<lines.length; i++) {
let line = lines[i];
if (line.linenum == lineNum) {
@ -1406,6 +1409,10 @@ class InputModel {
})();
}
isEmpty() : boolean {
return this.getCurLine().trim() == "";
}
resetInputMode() : void {
mobx.action(() => {
this.setInputMode(null);
@ -2054,6 +2061,7 @@ class Model {
uicontext : this.getUIContext(),
interactive : interactive,
};
// console.log("CMD", pk.metacmd + (pk.metasubcmd != null ? ":" + pk.metasubcmd : ""), pk.args, pk.kwargs, pk.interactive);
this.submitCommandPacket(pk, interactive);
}
@ -2345,6 +2353,14 @@ class CommandRunner {
GlobalModel.submitCommand("sw", "set", null, kwargs, true);
}
setLineHeight(lineArg : string, height : number) {
let kwargs : Record<string, string> = {};
kwargs["line"] = lineArg;
kwargs["height"] = String(height);
kwargs["hohist"] = "1";
GlobalModel.submitCommand("line", "setheight", null, kwargs, false);
}
swSetAnchor(sessionId : string, screenId : string, windowId : string, anchorVal : string) : void {
let kwargs = {
"nohist": "1",