mirror of https://github.com/vitalif/openscad
74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
|
#include "editor.h"
|
||
|
|
||
|
#ifndef _QCODE_EDIT_
|
||
|
void Editor::indentSelection()
|
||
|
{
|
||
|
QTextCursor cursor = textCursor();
|
||
|
int p1 = cursor.selectionStart();
|
||
|
QString txt = cursor.selectedText();
|
||
|
|
||
|
txt.replace(QString(QChar(8233)), QString(QChar(8233)) + QString("\t"));
|
||
|
if (txt.endsWith(QString(QChar(8233)) + QString("\t")))
|
||
|
txt.chop(1);
|
||
|
txt = QString("\t") + txt;
|
||
|
|
||
|
cursor.insertText(txt);
|
||
|
int p2 = cursor.position();
|
||
|
cursor.setPosition(p1, QTextCursor::MoveAnchor);
|
||
|
cursor.setPosition(p2, QTextCursor::KeepAnchor);
|
||
|
setTextCursor(cursor);
|
||
|
}
|
||
|
|
||
|
void Editor::unindentSelection()
|
||
|
{
|
||
|
QTextCursor cursor = textCursor();
|
||
|
int p1 = cursor.selectionStart();
|
||
|
QString txt = cursor.selectedText();
|
||
|
|
||
|
txt.replace(QString(QChar(8233)) + QString("\t"), QString(QChar(8233)));
|
||
|
if (txt.startsWith(QString("\t")))
|
||
|
txt.remove(0, 1);
|
||
|
|
||
|
cursor.insertText(txt);
|
||
|
int p2 = cursor.position();
|
||
|
cursor.setPosition(p1, QTextCursor::MoveAnchor);
|
||
|
cursor.setPosition(p2, QTextCursor::KeepAnchor);
|
||
|
setTextCursor(cursor);
|
||
|
}
|
||
|
|
||
|
void Editor::commentSelection()
|
||
|
{
|
||
|
QTextCursor cursor = textCursor();
|
||
|
int p1 = cursor.selectionStart();
|
||
|
QString txt = cursor.selectedText();
|
||
|
|
||
|
txt.replace(QString(QChar(8233)), QString(QChar(8233)) + QString("//"));
|
||
|
if (txt.endsWith(QString(QChar(8233)) + QString("//")))
|
||
|
txt.chop(2);
|
||
|
txt = QString("//") + txt;
|
||
|
|
||
|
cursor.insertText(txt);
|
||
|
int p2 = cursor.position();
|
||
|
cursor.setPosition(p1, QTextCursor::MoveAnchor);
|
||
|
cursor.setPosition(p2, QTextCursor::KeepAnchor);
|
||
|
setTextCursor(cursor);
|
||
|
}
|
||
|
|
||
|
void Editor::uncommentSelection()
|
||
|
{
|
||
|
QTextCursor cursor = textCursor();
|
||
|
int p1 = cursor.selectionStart();
|
||
|
QString txt = cursor.selectedText();
|
||
|
|
||
|
txt.replace(QString(QChar(8233)) + QString("//"), QString(QChar(8233)));
|
||
|
if (txt.startsWith(QString("//")))
|
||
|
txt.remove(0, 2);
|
||
|
|
||
|
cursor.insertText(txt);
|
||
|
int p2 = cursor.position();
|
||
|
cursor.setPosition(p1, QTextCursor::MoveAnchor);
|
||
|
cursor.setPosition(p2, QTextCursor::KeepAnchor);
|
||
|
setTextCursor(cursor);
|
||
|
}
|
||
|
#endif
|