mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-15 14:36:44 +00:00
Implement commentSelection() and uncommentSelection()
This commit is contained in:
parent
83ff7d162c
commit
61e374fdfc
1 changed files with 38 additions and 0 deletions
|
@ -287,12 +287,50 @@ void CSVWorld::ScriptEdit::updateLineNumberArea(const QRect &rect, int dy)
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::commentSelection()
|
void CSVWorld::ScriptEdit::commentSelection()
|
||||||
{
|
{
|
||||||
|
QTextCursor begin = textCursor();
|
||||||
|
QTextCursor end = begin;
|
||||||
|
begin.setPosition(begin.selectionStart());
|
||||||
|
begin.movePosition(QTextCursor::StartOfLine);
|
||||||
|
|
||||||
|
end.setPosition(end.selectionEnd());
|
||||||
|
end.movePosition(QTextCursor::StartOfLine);
|
||||||
|
|
||||||
|
for (; begin <= end; begin.movePosition(QTextCursor::StartOfLine), begin.movePosition(QTextCursor::Down))
|
||||||
|
{
|
||||||
|
begin.insertText(";");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::uncommentSelection()
|
void CSVWorld::ScriptEdit::uncommentSelection()
|
||||||
{
|
{
|
||||||
|
QTextCursor begin = textCursor();
|
||||||
|
QTextCursor end = begin;
|
||||||
|
begin.setPosition(begin.selectionStart());
|
||||||
|
begin.movePosition(QTextCursor::StartOfLine);
|
||||||
|
|
||||||
|
end.setPosition(end.selectionEnd());
|
||||||
|
end.movePosition(QTextCursor::StartOfLine);
|
||||||
|
|
||||||
|
for (; begin <= end; begin.movePosition(QTextCursor::StartOfLine), begin.movePosition(QTextCursor::Down)) {
|
||||||
|
// loop through line until a nonspace character is reached
|
||||||
|
begin.select(QTextCursor::LineUnderCursor);
|
||||||
|
QString line = begin.selectedText();
|
||||||
|
|
||||||
|
// get first nonspace character in line
|
||||||
|
int index;
|
||||||
|
for (index = 0; index != line.size(); ++index)
|
||||||
|
{
|
||||||
|
if (!line[index].isSpace())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index != line.size() && line[index] == ';')
|
||||||
|
{
|
||||||
|
line.remove(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
begin.insertText(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e)
|
void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e)
|
||||||
|
|
Loading…
Reference in a new issue