Beispiel #1
0
void CFLTKEditor::UnIndent()
{
	bool bChangedBuffer = false;
	int iSelStart = 0, iSelEnd = 0, iCurPos = 0, iTabSize, i;
	char *pcLine;
	Fl_Text_Buffer *pBuffer = GetTextBuffer();

	pBuffer->selection_position(&iSelStart, &iSelEnd);
	if (iSelEnd > iSelStart)
	{
		iCurPos = pBuffer->line_start(iSelStart);
		iTabSize = pBuffer->tab_distance();

		while (pBuffer->line_end(iCurPos) < iSelEnd)
		{
			pcLine = pBuffer->line_text(iCurPos);
			if (pcLine[0] == '\t')
			{
				bChangedBuffer = true;
				pBuffer->remove(iCurPos, iCurPos+1);
				--iSelEnd;
			}
			else if (pcLine[0] == ' ')
			{
				for (i = 1; i < iTabSize; i++)
				{
					if (pcLine[i] != ' ')
						break;
				}

				if (i == iTabSize) // same number of spaces as a tab
				{
					bChangedBuffer = true;
					pBuffer->remove(iCurPos, iCurPos + iTabSize);
					iSelEnd -= iTabSize;
				}
			}
			iCurPos = pBuffer->skip_lines(iCurPos, 1);
			free(pcLine);
		}

		if (bChangedBuffer)
			pBuffer->select(pBuffer->line_start(iSelStart), iSelEnd);
	}
}
Beispiel #2
0
void CFLTKEditor::Indent()
{
	bool bChangedBuffer = false;
	int iSelStart = 0, iSelEnd = 0, iCurPos = 0;
	Fl_Text_Buffer *pcBuffer = GetTextBuffer();

	pcBuffer->selection_position(&iSelStart, &iSelEnd);
	if (iSelEnd <= iSelStart)
		return;

	iCurPos = pcBuffer->line_start(iSelStart);
	while (pcBuffer->line_end(iCurPos) < iSelEnd)
	{
		bChangedBuffer = true;
		pcBuffer->insert(iCurPos, "\t");
		iCurPos = pcBuffer->skip_lines(iCurPos, 1);
		++iSelEnd;
	}

	if (bChangedBuffer)
		pcBuffer->select(pcBuffer->line_start(iSelStart), iSelEnd);
}