@@ -21,32 +21,7 @@ import { MarkdownPreview } from "./preview-markdown";
2121import type { PreviewModel } from "./preview-model" ;
2222import { StreamingPreview } from "./preview-streaming" ;
2323import type { PreviewEnv } from "./previewenv" ;
24-
25- function posixEscapePath ( path : string ) : string {
26- if ( path === "~" ) return "~" ;
27- if ( path . startsWith ( "~/" ) ) {
28- return "~/" + "'" + path . slice ( 2 ) . replace ( / ' / g, "'\\''" ) + "'" ;
29- }
30- return "'" + path . replace ( / ' / g, "'\\''" ) + "'" ;
31- }
32-
33- function pwshEscapePath ( path : string ) : string {
34- return "'" + path . replace ( / ' / g, "''" ) + "'" ;
35- }
36-
37- function cmdEscapePath ( path : string ) : string {
38- return '"' + path . replace ( / " / g, '""' ) + '"' ;
39- }
40-
41- function buildCdCommand ( shellType : string , path : string ) : string {
42- if ( shellType === "pwsh" || shellType === "powershell" ) {
43- return "\x1bSet-Location -LiteralPath " + pwshEscapePath ( path ) + "\r" ;
44- }
45- if ( shellType === "cmd" ) {
46- return "\x1bcd /d " + cmdEscapePath ( path ) + "\r" ;
47- }
48- return "\x15cd " + posixEscapePath ( path ) + "\r" ;
49- }
24+ import { buildCdCommand } from "./shellescape" ;
5025
5126async function sendCdToTerminal ( termBlockId : string , path : string ) {
5227 const block = WOS . getObjectValue < Block > ( WOS . makeORef ( "block" , termBlockId ) , globalStore . get ) ;
@@ -188,16 +163,14 @@ function FollowTermDropdown({ model }: { model: PreviewModel }) {
188163
189164 const { pos, terms, currentFollowId, bidir } = menuData ;
190165 const linkTerm = ( blockId : string ) => {
191- BlockModel . getInstance ( ) . setBlockHighlight ( null ) ;
192166 fireAndForget ( async ( ) => {
193- const updates : Record < string , any > = { "preview:followtermid" : blockId } ;
167+ const updates : Record < string , string | boolean > = { "preview:followtermid" : blockId } ;
194168 if ( blockId !== currentFollowId ) {
195169 updates [ "preview:followterm:bidir" ] = false ;
196170 }
197171 await model . env . services . object . UpdateObjectMeta ( WOS . makeORef ( "block" , model . blockId ) , updates ) ;
172+ closeMenu ( ) ;
198173 } ) ;
199- globalStore . set ( model . followTermMenuDataAtom , null ) ;
200- restoreFocus ( ) ;
201174 } ;
202175 const toggleBidir = ( ) => {
203176 fireAndForget ( async ( ) => {
@@ -213,9 +186,8 @@ function FollowTermDropdown({ model }: { model: PreviewModel }) {
213186 "preview:followtermid" : null ,
214187 "preview:followterm:bidir" : null ,
215188 } ) ;
189+ closeMenu ( ) ;
216190 } ) ;
217- globalStore . set ( model . followTermMenuDataAtom , null ) ;
218- restoreFocus ( ) ;
219191 } ;
220192
221193 const dropdownStyle : React . CSSProperties = {
@@ -345,9 +317,16 @@ function PreviewView({
345317 if ( ! followTermId || ! followTermCwd ) return ;
346318 const currentPath = globalStore . get ( model . metaFilePath ) ?? "" ;
347319 if ( followTermCwd !== currentPath ) {
348- suppressBidirRef . current = true ;
320+ fireAndForget ( async ( ) => {
321+ const updated = await model . goHistory ( followTermCwd ) ;
322+ if ( updated ) {
323+ suppressBidirRef . current = true ;
324+ setTimeout ( ( ) => {
325+ suppressBidirRef . current = false ;
326+ } , 400 ) ;
327+ }
328+ } ) ;
349329 }
350- fireAndForget ( ( ) => model . goHistory ( followTermCwd ) ) ;
351330 } , [ followTermCwd , followTermId , model ] ) ;
352331
353332 useEffect ( ( ) => {
0 commit comments