Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Set the cursor to the beginning of the first block.
- textCursor().setPosition(textCursor().block().position(), QTextCursor::KeepAnchor);
- // Grab the start of the selection
- int start_pos = textCursor().selectionStart();
- // Grab the selected text
- QString text = textCursor().selection().toPlainText();
- if(indent)
- {
- if(m_indent_use_spaces)
- {
- text.prepend(QString(m_tab_size, ' '));
- text.replace("\n", QString(m_tab_size, ' ').prepend("\n"));
- }
- else
- {
- text.prepend("\t");
- text.replace("\n", "\n\t");
- }
- }
- else
- {
- if(m_indent_use_spaces)
- {
- int num_remove = 0;
- while(num_remove < text.length() && num_remove < m_tab_size && text[num_remove] == ' ')
- ++num_remove;
- text.remove(0, num_remove);
- text.replace(QRegExp(tr("\n {0,%1}").arg(m_tab_size)), "\n");
- }
- else
- {
- if(text.startsWith("\t"))
- text.remove(0, 1);
- text.replace("\n\t", "\n");
- }
- }
- textCursor().removeSelectedText();
- textCursor().insertText(text);
- // We need to reset the selection
- textCursor().setPosition(start_pos);
- textCursor().setPosition(start_pos + text.length(), QTextCursor::KeepAnchor);
- // These numbers seem to be correct
- qDebug(tr("%1, %2").arg(start_pos).arg(start_pos + text.length()).toUtf8().data());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement