@@ -663,6 +663,31 @@ void CSVDoc::View::addSubView(const CSMWorld::UniversalId& id, const std::string
663663
664664 mSubViewWindow .addDockWidget (Qt::TopDockWidgetArea, view);
665665
666+ // Horizontal orientation doesn't respect layout direction, so we need to move the new view
667+ if (windows[" subview-open-direction" ].toString () == " Open Left" && mSubViews .size () > 1 )
668+ {
669+ // Get list of top-area dock widget subviews sorted by coordinates
670+ QList<SubView*> orderedTopViews;
671+ for (const auto & windowView : mSubViews )
672+ if (windowView != view && mSubViewWindow .dockWidgetArea (windowView) == Qt::TopDockWidgetArea)
673+ orderedTopViews.append (windowView);
674+ if (!orderedTopViews.isEmpty ())
675+ {
676+ std::sort (orderedTopViews.begin (), orderedTopViews.end (), [](auto * a, auto * b) {
677+ if (a->x () != b->x ())
678+ return a->x () < b->x ();
679+ else if (a->y () != b->y ())
680+ return a->y () < b->y ();
681+ return a->getUniversalId () < b->getUniversalId ();
682+ });
683+
684+ // Split twice to make the new view the leftmost.
685+ // If the leftmost view is nested, the new view will be added above it.
686+ mSubViewWindow .splitDockWidget (orderedTopViews[0 ], view, Qt::Orientation::Horizontal);
687+ mSubViewWindow .splitDockWidget (view, orderedTopViews[0 ], Qt::Orientation::Horizontal);
688+ }
689+ }
690+
666691 updateSubViewIndices ();
667692
668693 connect (view, &SubView::focusId, this , &View::addSubView);
@@ -706,7 +731,11 @@ void CSVDoc::View::moveScrollBarToEnd(int min, int max)
706731{
707732 if (mScroll )
708733 {
709- mScroll ->horizontalScrollBar ()->setValue (max);
734+ CSMPrefs::Category& windows = CSMPrefs::State::get ()[" Windows" ];
735+ if (windows[" subview-open-direction" ].toString () == " Open Left" )
736+ mScroll ->horizontalScrollBar ()->setValue (min);
737+ else
738+ mScroll ->horizontalScrollBar ()->setValue (max);
710739
711740 QObject::disconnect (mScroll ->horizontalScrollBar (), &QScrollBar::rangeChanged, this , &View::moveScrollBarToEnd);
712741 }
@@ -1122,7 +1151,8 @@ void CSVDoc::View::updateWidth(bool isGrowLimit, int minSubViewWidth)
11221151 if (newWidth + frameWidth <= rect.width ())
11231152 {
11241153 resize (newWidth, height ());
1125- // WARNING: below code assumes that new subviews are added to the right
1154+ // WARNING: below code assumes that the frame geometry expands to the right.
1155+ // This doesn't conflict with subview-open-direction.
11261156 if (x () > rect.width () - (newWidth + frameWidth))
11271157 move (rect.width () - (newWidth + frameWidth), y ()); // shift left to stay within the screen
11281158 }
0 commit comments