Commits

Merov Linden committed ca27b19

EXP-1363 : Fix caret position in multiple lines or columns situation

Comments (0)

Files changed (3)

indra/llui/lltoolbar.cpp

 // Various drag data are stored in the toolbar object though are not exposed outside (and shouldn't).
 int LLToolBar::getRankFromPosition(S32 x, S32 y)
 {
+	if (mButtons.empty())
+	{
+		return RANK_NONE;
+	}
+	
 	int rank = 0;
 
 	// Convert the toolbar coord into button panel coords
 	LLRect button_rect;
 	while (it_button != end_button)
 	{
-		button_rect = (*it_button)->getRect();
-		mDragCommand = (*it_button)->mId;
-		S32 point_x, point_y;
-		if (orientation == LLLayoutStack::HORIZONTAL)
-		{
-			// Horizontal
-			point_x = (button_rect.mRight + button_rect.mLeft) / 2;
-			point_y = button_rect.mBottom - mPadBottom;
-		}
-		else
-		{
-			// Vertical
-			point_x = button_rect.mRight + mPadRight;
-			point_y = (button_rect.mTop + button_rect.mBottom) / 2;
-		}
+		button_rect  = (*it_button)->getRect();
+		S32 point_x = button_rect.mRight + mPadRight;
+		S32 point_y = button_rect.mBottom - mPadBottom;
 
 		if ((button_panel_x < point_x) && (button_panel_y > point_y))
 		{
 	// (different depending on toolbar orientation)
 	if (rank < mButtons.size())
 	{
-		mDragx = button_rect.mLeft - mPadLeft;
-		mDragy = button_rect.mTop + mPadTop;
+		if (orientation == LLLayoutStack::HORIZONTAL)
+		{
+			// Horizontal
+			S32 mid_point = (button_rect.mRight + button_rect.mLeft) / 2;
+			if (button_panel_x < mid_point)
+			{
+				mDragx = button_rect.mLeft - mPadLeft;
+				mDragy = button_rect.mTop + mPadTop;
+			}
+			else
+			{
+				rank++;
+				mDragx = button_rect.mRight + mPadRight - 1;
+				mDragy = button_rect.mTop + mPadTop;
+			}
+		}
+		else
+		{
+			// Vertical
+			S32 mid_point = (button_rect.mTop + button_rect.mBottom) / 2;
+			if (button_panel_y > mid_point)
+			{
+				mDragx = button_rect.mLeft - mPadLeft;
+				mDragy = button_rect.mTop + mPadTop;
+			}
+			else
+			{
+				rank++;
+				mDragx = button_rect.mLeft - mPadLeft;
+				mDragy = button_rect.mBottom - mPadBottom + 1;
+			}
+		}
 	}
 	else
 	{
 		// We hit passed the end of the list so put the insertion point at the end
 		if (orientation == LLLayoutStack::HORIZONTAL)
-	{
+		{
 			mDragx = button_rect.mRight + mPadRight;
 			mDragy = button_rect.mTop + mPadTop;
-	}
-	else
-	{
+		}
+		else
+		{
 			mDragx = button_rect.mLeft - mPadLeft;
 			mDragy = button_rect.mBottom - mPadBottom;
 		}
 			mDragRank = getRankFromPosition(x, y);
 			// Don't DaD if we're dragging a command on itself
 			mDragAndDropTarget = ((orig_rank != RANK_NONE) && ((mDragRank == orig_rank) || ((mDragRank-1) == orig_rank)) ? false : true);
-			llinfos << "Merov debug : DaD, rank = " << mDragRank << ", hit uuid = " << mDragCommand.uuid() << ", dragged uui = " << inv_item->getUUID() << llendl; 
+			//llinfos << "Merov debug : DaD, rank = " << mDragRank << ", dragged uui = " << inv_item->getUUID() << llendl; 
 			/* Do the following if you want to animate the button itself
 			LLCommandId dragged_command(inv_item->getUUID());
 			removeCommand(dragged_command);

indra/llui/lltoolbar.h

 	S32								mDragx,
 									mDragy,
 									mDragGirth;
-	LLCommandId						mDragCommand;
 
 public:
 	// Methods used in loading and saving toolbar settings

indra/newview/lltoolbarview.cpp

 			// Suppress the command from the toolbars (including the one it's dropped in, 
 			// this will handle move position).
 			int old_rank = LLToolBar::RANK_NONE;
+			LLToolBar* old_toolbar = NULL;
 			int rank;
 			if ((rank = gToolBarView->mToolbarLeft->removeCommand(command_id)) != LLToolBar::RANK_NONE)
 			{
 				old_rank = rank;
+				old_toolbar = gToolBarView->mToolbarLeft;
 			}
 			if ((rank = gToolBarView->mToolbarRight->removeCommand(command_id)) != LLToolBar::RANK_NONE)
 			{
 				old_rank = rank;
+				old_toolbar = gToolBarView->mToolbarRight;
 			}
 			if ((rank = gToolBarView->mToolbarBottom->removeCommand(command_id)) != LLToolBar::RANK_NONE)
 			{
 				old_rank = rank;
+				old_toolbar = gToolBarView->mToolbarBottom;
 			}
 			// Now insert it in the toolbar at the detected rank
 			if (!toolbar->isReadOnly())
 			{
-				if ((old_rank != LLToolBar::RANK_NONE) && (old_rank < new_rank))
+				if ((old_toolbar == toolbar) && (old_rank != LLToolBar::RANK_NONE) && (old_rank < new_rank))
 				{
+					// If we just removed the command from the same toolbar, we need to consider that it might
+					// change the target rank.
 					new_rank -= 1;
 				}
 				toolbar->addCommand(command->id(),new_rank);