diff --git a/src/main.tsx b/src/main.tsx index d7ffe35e..48744517 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -520,6 +520,14 @@ class TextAreaInput extends React.Component<{}, {}> { } this.lastFocusType = focusType; } + let inputModel = GlobalModel.inputModel; + if (inputModel.forceCursorPos.get() != null) { + if (this.mainInputRef.current != null) { + this.mainInputRef.current.selectionStart = inputModel.forceCursorPos.get(); + this.mainInputRef.current.selectionEnd = inputModel.forceCursorPos.get(); + } + mobx.action(() => inputModel.forceCursorPos.set(null))(); + } } getLinePos(elem : any) : {numLines : number, linePos : number} { @@ -768,6 +776,7 @@ class TextAreaInput extends React.Component<{}, {}> { let model = GlobalModel; let inputModel = model.inputModel; let curLine = inputModel.getCurLine(); + let fcp = inputModel.forceCursorPos.get(); // for reaction let numLines = curLine.split("\n").length; let displayLines = numLines; if (displayLines > 5) { diff --git a/src/model.ts b/src/model.ts index b020753f..eec71ab4 100644 --- a/src/model.ts +++ b/src/model.ts @@ -856,6 +856,9 @@ class InputModel { showNoInputTimeoutId : any = null; inputMode : OV = mobx.observable.box(null); + // cursor + forceCursorPos : OV = mobx.observable.box(null); + // focus inputFocused : OV = mobx.observable.box(false); lineFocused : OV = mobx.observable.box(false); @@ -1077,13 +1080,8 @@ class InputModel { updateCmdLine(cmdLine : CmdLineUpdateType) : void { mobx.action(() => { - let curLine = this.getCurLine(); - if (curLine.length < cmdLine.insertpos) { - return; - } - let pos = cmdLine.insertpos; - curLine = curLine.substr(0, pos) + cmdLine.insertchars + curLine.substr(pos); - this.setCurLine(curLine); + this.setCurLine(cmdLine.cmdline); + this.forceCursorPos.set(cmdLine.cursorpos); })(); } diff --git a/src/types.ts b/src/types.ts index 7d40de87..b7ccd320 100644 --- a/src/types.ts +++ b/src/types.ts @@ -284,8 +284,8 @@ type HistoryInfoType = { }; type CmdLineUpdateType = { - insertchars : string, - insertpos : number, + cmdline : string, + cursorpos : number, }; type RemoteEditType = {