Exemplo n.º 1
0
void FormattedFile::checkTabs()
{
	if(mNewline)
	{
		mStream << getTabString();
		mNewline = false;
	}
}
Exemplo n.º 2
0
void FormattedFile::parseString( string s )
{
	if(mTabLevel > 0)
	{
		string tabs = getTabString();
		size_t pos = 0;
		while((pos = s.find('\n', pos)) != s.npos)
		{
			if(pos + 1 >= s.size())
				break;
			pos++;
			s.insert(pos, tabs);
		}
	}
	if(s[s.size() - 1] == '\n')
	{
		mNewline = true;
	}
	mStream << s;
}
void CodeEditorComponent::indentSelectedLines (const int spacesToAdd)
{
    newTransaction();

    CodeDocument::Position oldSelectionStart (selectionStart), oldSelectionEnd (selectionEnd), oldCaret (caretPos);
    oldSelectionStart.setPositionMaintained (true);
    oldSelectionEnd.setPositionMaintained (true);
    oldCaret.setPositionMaintained (true);

    const int lineStart = selectionStart.getLineNumber();
    int lineEnd = selectionEnd.getLineNumber();

    if (lineEnd > lineStart && selectionEnd.getIndexInLine() == 0)
        --lineEnd;

    for (int line = lineStart; line <= lineEnd; ++line)
    {
        const String lineText (document.getLine (line));
        const int nonWhitespaceStart = CodeEditorHelpers::findFirstNonWhitespaceChar (lineText);

        if (nonWhitespaceStart > 0 || lineText.trimStart().isNotEmpty())
        {
            const CodeDocument::Position wsStart (document, line, 0);
            const CodeDocument::Position wsEnd   (document, line, nonWhitespaceStart);

            const int numLeadingSpaces = indexToColumn (line, wsEnd.getIndexInLine());
            const int newNumLeadingSpaces = jmax (0, numLeadingSpaces + spacesToAdd);

            if (newNumLeadingSpaces != numLeadingSpaces)
            {
                document.deleteSection (wsStart, wsEnd);
                document.insertText (wsStart, getTabString (newNumLeadingSpaces));
            }
        }
    }

    selectionStart = oldSelectionStart;
    selectionEnd = oldSelectionEnd;
    caretPos = oldCaret;
}