コード例 #1
0
bool CodeEditorComponent::deleteWhitespaceBackwardsToTabStop()
{
    if (getHighlightedRegion().isEmpty())
    {
        for (;;)
        {
            const int currentColumn = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());

            if (currentColumn <= 0 || (currentColumn % spacesPerTab) == 0)
                break;

            moveCaretLeft (false, true);
        }

        const String selected (getTextInRange (getHighlightedRegion()));

        if (selected.isNotEmpty() && selected.trim().isEmpty())
        {
            cut();
            return true;
        }
    }

    return false;
}
コード例 #2
0
void FixedHeightLayoutManager::moveTheCaret(UInt32 dir,bool isShiftPressed,bool isControlPressed)
{

	if(!rootElement || !rootElement->getElementCount()) return;
	UInt32 charactersToBeForwarded;
	PlainDocumentLeafElementRefPtr theElement;
	Int32 tempIndex;
	Int32 tempLine;
	switch(dir)
	{
	case LEFT:
		if(!isShiftPressed)
		{
			if(HSL != HEL || HSI != HEI) // something was highlighted before this
			{
				if(isStartLocationBeforeEndLocation())	
				{					
					_CaretLine = HSL;					// set caret position to the Highlight Starting position
					_CaretIndex = HSI;
					HEI = HSI;
					HEL = HSL;
				}
				else
				{
					_CaretLine = HEL;					// set caret position to the Highlight Ending position
					_CaretIndex = HEI;
					HSI = HEI;
					HSL = HEL;
				}
				recalculateCaretPositions();
			}
			else	// nothing was highlighted before this
			{
				if(!isControlPressed)moveCaretLeft();
				else	moveAndHighlightWord(LEFT);

				HSI = HEI = _CaretIndex;
				HSL = HEL = _CaretLine;
			}
		}
		else	// if shift is pressed
		{
			if(!isControlPressed)moveCaretLeft();
			else	moveAndHighlightWord(LEFT);

			HEI = _CaretIndex;
			HEL = _CaretLine;
		}
		break;
	case RIGHT:	
		if(!isShiftPressed)
		{
			if(HSL != HEL || HSI != HEI) // something was highlighted before this
			{
				if(isStartLocationBeforeEndLocation())	
				{					
					_CaretLine = HEL;					// set caret position to the Highlight Starting position
					_CaretIndex = HEI;
					HSI = HEI;
					HSL = HEL;
				}
				else
				{
					_CaretLine = HSL;					// set caret position to the Highlight Ending position
					_CaretIndex = HSI;
					HEI = HSI;
					HEL = HSL;
				}
				recalculateCaretPositions();
			}
			else	// nothing was highlighted before this
			{
				if(!isControlPressed)moveCaretRight();
				else	moveAndHighlightWord(RIGHT);

				HSI = HEI = _CaretIndex;
				HSL = HEL = _CaretLine;
			}
		}
		else	// if shift is pressed
		{
			if(!isControlPressed)moveCaretRight();
			else	moveAndHighlightWord(RIGHT);

			HEI = _CaretIndex;
			HEL = _CaretLine;
		}
		break;

	case UP:
		if(!isShiftPressed && !isControlPressed)
		{
			if(HSL != HEL || HSI != HEI) // something was highlighted before this
			{
				if(isStartLocationBeforeEndLocation())	
				{					
					_CaretLine = HSL;					// set caret position to the Highlight Starting position
					_CaretIndex = HSI;
					HEI = HSI;
					HEL = HSL;
				}
				else
				{
					_CaretLine = HEL;					// set caret position to the Highlight Ending position
					_CaretIndex = HEI;
					HSI = HEI;
					HSL = HEL;
				}
				moveCaretUp();
			}
			else	// nothing was highlighted before this
			{
				moveCaretUp();
				HSI = HEI = _CaretIndex;
				HSL = HEL = _CaretLine;
			}
		}
		else if(isShiftPressed && !isControlPressed)	// if shift is pressed
		{
			moveCaretUp();
			HEI = _CaretIndex;
			HEL = _CaretLine;
		}
		break;

	case DOWN:	

		if(!isShiftPressed && !isControlPressed)
		{
			if(HSL != HEL || HSI != HEI) // something was highlighted before this
			{
				if(isStartLocationBeforeEndLocation())	
				{					
					_CaretLine = HEL;					// set caret position to the Highlight Starting position
					_CaretIndex = HEI;
					HSI = HEI;
					HSL = HEL;
				}
				else
				{
					_CaretLine = HSL;					// set caret position to the Highlight Ending position
					_CaretIndex = HSI;
					HEI = HSI;
					HEL = HSL;
				}
				moveCaretDown();
			}
			else // nothing was highlighted before this
			{
				moveCaretDown();
				HSI = HEI = _CaretIndex;
				HSL = HEL = _CaretLine;
			}
		}
		else if(isShiftPressed && !isControlPressed)	// if shift is pressed
		{
			moveCaretDown();
			HEI = _CaretIndex;
			HEL = _CaretLine;
		}
		break;

	case HOME:
		moveCaretHome(isControlPressed);
		HEI = _CaretIndex;
		HEL = _CaretLine;
		if(!isShiftPressed)
		{
			HSI = HEI;
			HSL = HEL;
		}
		break;

	case HOMEOFNEXTLINE:
		
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
		 charactersToBeForwarded = theElement->getTextLength()-_CaretIndex;
		_CaretIndex = 0;
		_CaretLine++;
		recalculateCaretPositions();
		getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+ charactersToBeForwarded);

		break;

	case END:
		moveCaretEnd(isControlPressed);
		HEI = _CaretIndex;
		HEL = _CaretLine;
		if(!isShiftPressed)
		{
			HSI = HEI;
			HSL = HEL;
		}
		break;

	case PAGEUP:
		tempIndex = _CaretIndex;
		tempLine = _CaretLine;
		tempLine -= getLinesToBeDisplayed();
		if(tempLine<0)tempLine = 0;
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(tempLine));
		if(tempIndex > theElement->getTextLength()-2)tempIndex = theElement->getTextLength()-2;

		HEI = tempIndex;
		HEL = tempLine;
		if(!isShiftPressed)
		{
			HSI = HEI;
			HSL = HEL;
		}
		_CaretLine = HEL;					// set caret position to the Highlight Ending position
		_CaretIndex = HEI;
		recalculateCaretPositions();

		break;

	case PAGEDOWN:
		tempIndex = _CaretIndex;
		tempLine = _CaretLine;
		tempLine += getLinesToBeDisplayed();
		if(tempLine>=rootElement->getElementCount())tempLine = rootElement->getElementCount()-1;
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(tempLine));
		if(tempIndex > theElement->getTextLength()-2)tempIndex = theElement->getTextLength()-2;

		HEI = tempIndex;
		HEL = tempLine;
		if(!isShiftPressed)
		{
			HSI = HEI;
			HSL = HEL;
		}
		_CaretLine = HEL;					// set caret position to the Highlight Ending position
		_CaretIndex = HEI;
		recalculateCaretPositions();

		break;
	}
	checkCaretVisibility(dir);
}