Skip to content

Commit e18fc41

Browse files
committed
Merge remote-tracking branch 'stash/main'
2 parents 77c2cb1 + 552aaeb commit e18fc41

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Source/Chatbook/ChatModes/ShowNotebookAssistance.wl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,22 +577,37 @@ setWindowInputAndEvaluate // endDefinition;
577577
attachToLeft // beginDefinition;
578578

579579
attachToLeft[ source_NotebookObject, current_NotebookObject ] := Enclose[
580-
Module[ { mag, width, margins, left, bottom, top },
580+
Module[ { mag, width, margins, left, bottom, top, displayindex, displayleftedge },
581581

582582
mag = Replace[ AbsoluteCurrentValue[ source, Magnification ], Except[ _? NumberQ ] :> 1.0 ];
583583
width = Ceiling @ ConfirmBy[ $workspaceChatWidth * mag, NumberQ, "Width" ];
584584
margins = ConfirmMatch[ windowMargins @ source, { { _, _ }, { _, _ } }, "Margins" ];
585+
586+
displayindex = NotebookTools`NotebookDisplayIndex[source];
587+
displayleftedge = If[IntegerQ[displayindex],
588+
Replace[CurrentValue["ConnectedDisplays"][[displayindex]], {
589+
{___, "FullRegion" -> {{xmin_, _}, {_, _}}, ___} :> xmin,
590+
_ :> 0
591+
}],
592+
0
593+
];
585594

586595
left = margins[[ 1, 1 ]];
587596
bottom = margins[[ 2, 1 ]];
588597
top = margins[[ 2, 2 ]];
589598

590-
If[ NonPositive[ left - width ], left = width ];
599+
left = left - width;
600+
If[ left < displayleftedge,
601+
(* prevent the assistant from falling off the left edge of the display *)
602+
left = displayleftedge;
603+
(* Uncomment this to also slide the source notebook right, to avoid overlapping with the assistant *)
604+
(* SetOptions[source, WindowMargins -> ReplacePart[margins, {1,1} -> (left + width)]] *)
605+
];
591606

592607
SetOptions[
593608
current,
594609
Magnification -> 0.85 * mag,
595-
WindowMargins -> { { left - width, Automatic }, { bottom, top } },
610+
WindowMargins -> { { left, Automatic }, { bottom, top } },
596611
WindowSize -> { width, Automatic }
597612
];
598613

0 commit comments

Comments
 (0)