forked from qt-creator/qt-creator
fakevim: remove some basetextedit dependencies
This commit is contained in:
@@ -45,6 +45,7 @@ const char * const ConfigTabStop = "tabstop";
|
|||||||
const char * const ConfigSmartTab = "smarttab";
|
const char * const ConfigSmartTab = "smarttab";
|
||||||
const char * const ConfigShiftWidth = "shiftwidth";
|
const char * const ConfigShiftWidth = "shiftwidth";
|
||||||
const char * const ConfigExpandTab = "expandtab";
|
const char * const ConfigExpandTab = "expandtab";
|
||||||
|
const char * const ConfigAutoIndent = "autoindent";
|
||||||
|
|
||||||
} // namespace Constants
|
} // namespace Constants
|
||||||
} // namespace FakeVim
|
} // namespace FakeVim
|
||||||
|
|||||||
@@ -53,11 +53,11 @@
|
|||||||
#include <QtGui/QTextDocumentFragment>
|
#include <QtGui/QTextDocumentFragment>
|
||||||
#include <QtGui/QTextEdit>
|
#include <QtGui/QTextEdit>
|
||||||
|
|
||||||
#include <texteditor/basetexteditor.h>
|
//#include <texteditor/basetexteditor.h>
|
||||||
#include <texteditor/textblockiterator.h>
|
//#include <texteditor/textblockiterator.h>
|
||||||
#include <cppeditor/cppeditor.h>
|
//#include <cppeditor/cppeditor.h>
|
||||||
|
|
||||||
#include <indenter.h>
|
//#include <indenter.h>
|
||||||
|
|
||||||
using namespace FakeVim::Internal;
|
using namespace FakeVim::Internal;
|
||||||
using namespace FakeVim::Constants;
|
using namespace FakeVim::Constants;
|
||||||
@@ -190,13 +190,13 @@ private:
|
|||||||
// helper functions for indenting
|
// helper functions for indenting
|
||||||
bool isElectricCharacter(QChar c) const { return (c == '{' || c == '}' || c == '#'); }
|
bool isElectricCharacter(QChar c) const { return (c == '{' || c == '}' || c == '#'); }
|
||||||
int indentDist() const;
|
int indentDist() const;
|
||||||
void insertIndent();
|
|
||||||
void indentRegion(QTextBlock first, QTextBlock last, QChar typedChar=0);
|
void indentRegion(QTextBlock first, QTextBlock last, QChar typedChar=0);
|
||||||
void indentCurrentLine(QChar typedChar);
|
void indentCurrentLine(QChar typedChar);
|
||||||
|
|
||||||
void moveToFirstNonBlankOnLine();
|
void moveToFirstNonBlankOnLine();
|
||||||
void moveToDesiredColumn();
|
void moveToDesiredColumn();
|
||||||
void moveToNextWord(bool simple);
|
void moveToNextWord(bool simple);
|
||||||
|
void moveToMatchingParanthesis();
|
||||||
void moveToWordBoundary(bool simple, bool forward);
|
void moveToWordBoundary(bool simple, bool forward);
|
||||||
void handleFfTt(int key);
|
void handleFfTt(int key);
|
||||||
|
|
||||||
@@ -217,7 +217,6 @@ private:
|
|||||||
public:
|
public:
|
||||||
QTextEdit *m_textedit;
|
QTextEdit *m_textedit;
|
||||||
QPlainTextEdit *m_plaintextedit;
|
QPlainTextEdit *m_plaintextedit;
|
||||||
TextEditor::BaseTextEditor *m_texteditor;
|
|
||||||
bool m_wasReadOnly; // saves read-only state of document
|
bool m_wasReadOnly; // saves read-only state of document
|
||||||
|
|
||||||
FakeVimHandler *q;
|
FakeVimHandler *q;
|
||||||
@@ -299,7 +298,6 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent)
|
|||||||
m_gflag = false;
|
m_gflag = false;
|
||||||
m_textedit = 0;
|
m_textedit = 0;
|
||||||
m_plaintextedit = 0;
|
m_plaintextedit = 0;
|
||||||
m_texteditor = 0;
|
|
||||||
m_visualMode = NoVisualMode;
|
m_visualMode = NoVisualMode;
|
||||||
m_desiredColumn = 0;
|
m_desiredColumn = 0;
|
||||||
|
|
||||||
@@ -308,6 +306,7 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent)
|
|||||||
m_config[ConfigSmartTab] = ConfigOff;
|
m_config[ConfigSmartTab] = ConfigOff;
|
||||||
m_config[ConfigShiftWidth] = "8";
|
m_config[ConfigShiftWidth] = "8";
|
||||||
m_config[ConfigExpandTab] = ConfigOff;
|
m_config[ConfigExpandTab] = ConfigOff;
|
||||||
|
m_config[ConfigAutoIndent] = ConfigOff;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
|
bool FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
|
||||||
@@ -670,31 +669,7 @@ bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
|
|||||||
} else if (key == '=') {
|
} else if (key == '=') {
|
||||||
m_submode = IndentSubMode;
|
m_submode = IndentSubMode;
|
||||||
} else if (key == '%') {
|
} else if (key == '%') {
|
||||||
bool undoFakeEOL = false;
|
moveToMatchingParanthesis();
|
||||||
if (atEol()) {
|
|
||||||
m_tc.movePosition(Left, KeepAnchor, 1);
|
|
||||||
undoFakeEOL = true;
|
|
||||||
}
|
|
||||||
TextEditor::TextBlockUserData::MatchType match
|
|
||||||
= TextEditor::TextBlockUserData::matchCursorForward(&m_tc);
|
|
||||||
if (match == TextEditor::TextBlockUserData::Match) {
|
|
||||||
if (m_submode == NoSubMode || m_submode == ZSubMode || m_submode == RegisterSubMode)
|
|
||||||
m_tc.movePosition(Left, KeepAnchor, 1);
|
|
||||||
} else {
|
|
||||||
if (undoFakeEOL)
|
|
||||||
m_tc.movePosition(Right, KeepAnchor, 1);
|
|
||||||
if (match == TextEditor::TextBlockUserData::NoMatch) {
|
|
||||||
// backward matching is according to the character before the cursor
|
|
||||||
bool undoMove = false;
|
|
||||||
if (!m_tc.atBlockEnd()) {
|
|
||||||
m_tc.movePosition(Right, KeepAnchor, 1);
|
|
||||||
undoMove = true;
|
|
||||||
}
|
|
||||||
match = TextEditor::TextBlockUserData::matchCursorBackward(&m_tc);
|
|
||||||
if (match != TextEditor::TextBlockUserData::Match && undoMove)
|
|
||||||
m_tc.movePosition(Left, KeepAnchor, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finishMovement();
|
finishMovement();
|
||||||
} else if (key == 'a') {
|
} else if (key == 'a') {
|
||||||
m_mode = InsertMode;
|
m_mode = InsertMode;
|
||||||
@@ -836,11 +811,10 @@ bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
|
|||||||
m_tc.movePosition(EndOfLine, MoveAnchor);
|
m_tc.movePosition(EndOfLine, MoveAnchor);
|
||||||
m_tc.insertText("\n");
|
m_tc.insertText("\n");
|
||||||
m_tc.movePosition(StartOfLine, MoveAnchor);
|
m_tc.movePosition(StartOfLine, MoveAnchor);
|
||||||
if (m_texteditor && m_texteditor->tabSettings().m_autoIndent) {
|
if (m_config[ConfigAutoIndent] == ConfigOn)
|
||||||
insertIndent();
|
m_tc.insertText(QString(indentDist(), ' '));
|
||||||
} else {
|
else
|
||||||
m_tc.insertText(QString(numSpaces, ' '));
|
m_tc.insertText(QString(numSpaces, ' '));
|
||||||
}
|
|
||||||
} else if (key == 'p' || key == 'P') {
|
} else if (key == 'p' || key == 'P') {
|
||||||
QString text = m_registers[m_register];
|
QString text = m_registers[m_register];
|
||||||
int n = text.count(QChar(ParagraphSeparator));
|
int n = text.count(QChar(ParagraphSeparator));
|
||||||
@@ -996,22 +970,21 @@ bool FakeVimHandler::Private::handleInsertMode(int key, const QString &text)
|
|||||||
m_tc.deleteChar();
|
m_tc.deleteChar();
|
||||||
}
|
}
|
||||||
m_tc.insertText(text);
|
m_tc.insertText(text);
|
||||||
if (m_texteditor && m_texteditor->tabSettings().m_autoIndent && isElectricCharacter(text.at(0))) {
|
if (m_config[ConfigAutoIndent] == ConfigOn
|
||||||
|
&& isElectricCharacter(text.at(0))) {
|
||||||
const QString leftText = m_tc.block().text()
|
const QString leftText = m_tc.block().text()
|
||||||
.left(m_tc.position() - 1 - m_tc.block().position());
|
.left(m_tc.position() - 1 - m_tc.block().position());
|
||||||
if (leftText.simplified().isEmpty())
|
if (leftText.simplified().isEmpty()) {
|
||||||
{
|
if (m_tc.hasSelection()) {
|
||||||
if (m_tc.hasSelection())
|
|
||||||
{
|
|
||||||
QTextDocument *doc = EDITOR(document());
|
QTextDocument *doc = EDITOR(document());
|
||||||
QTextBlock block = doc->findBlock(qMin(m_tc.selectionStart(),
|
QTextBlock block = doc->findBlock(qMin(m_tc.selectionStart(),
|
||||||
m_tc.selectionEnd()));
|
m_tc.selectionEnd()));
|
||||||
const QTextBlock end = doc->findBlock(qMax(m_tc.selectionStart(),
|
const QTextBlock end = doc->findBlock(qMax(m_tc.selectionStart(),
|
||||||
m_tc.selectionEnd())).next();
|
m_tc.selectionEnd())).next();
|
||||||
indentRegion(block, end, text.at(0));
|
indentRegion(block, end, text.at(0));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
indentCurrentLine(text.at(0));
|
indentCurrentLine(text.at(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1339,6 +1312,8 @@ void FakeVimHandler::Private::moveToFirstNonBlankOnLine()
|
|||||||
|
|
||||||
int FakeVimHandler::Private::indentDist() const
|
int FakeVimHandler::Private::indentDist() const
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
|
// FIXME: Make independent of TextEditor
|
||||||
if (!m_texteditor)
|
if (!m_texteditor)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -1353,27 +1328,20 @@ int FakeVimHandler::Private::indentDist() const
|
|||||||
const TextEditor::TextBlockIterator begin(doc->begin());
|
const TextEditor::TextBlockIterator begin(doc->begin());
|
||||||
const TextEditor::TextBlockIterator end(m_tc.block().next());
|
const TextEditor::TextBlockIterator end(m_tc.block().next());
|
||||||
return indenter.indentForBottomLine(current, begin, end, QChar(' '));
|
return indenter.indentForBottomLine(current, begin, end, QChar(' '));
|
||||||
}
|
#endif
|
||||||
|
return 0;
|
||||||
void FakeVimHandler::Private::insertIndent()
|
|
||||||
{
|
|
||||||
const int indent = indentDist();
|
|
||||||
QString text;
|
|
||||||
for(int i = 0; i < indent; ++i)
|
|
||||||
text += ' ';
|
|
||||||
m_tc.insertText(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::indentRegion(QTextBlock begin, QTextBlock end, QChar typedChar)
|
void FakeVimHandler::Private::indentRegion(QTextBlock begin, QTextBlock end, QChar typedChar)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
|
// FIXME: Make independent of TextEditor
|
||||||
if (!m_texteditor)
|
if (!m_texteditor)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
TextEditor::TabSettings ts = m_texteditor->tabSettings();
|
|
||||||
typedef SharedTools::Indenter<TextEditor::TextBlockIterator> Indenter;
|
typedef SharedTools::Indenter<TextEditor::TextBlockIterator> Indenter;
|
||||||
Indenter &indenter = Indenter::instance();
|
Indenter &indenter = Indenter::instance();
|
||||||
indenter.setIndentSize(ts.m_indentSize);
|
indenter.setIndentSize(m_config[ConfigShiftWidth].toInt());
|
||||||
indenter.setTabSize(ts.m_tabSize);
|
indenter.setTabSize(m_config[ConfigTabStop].toInt());
|
||||||
|
|
||||||
QTextDocument *doc = EDITOR(document());
|
QTextDocument *doc = EDITOR(document());
|
||||||
const TextEditor::TextBlockIterator docStart(doc->begin());
|
const TextEditor::TextBlockIterator docStart(doc->begin());
|
||||||
@@ -1389,6 +1357,10 @@ void FakeVimHandler::Private::indentRegion(QTextBlock begin, QTextBlock end, QCh
|
|||||||
ts.indentLine(cur, indent);
|
ts.indentLine(cur, indent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
Q_UNUSED(begin);
|
||||||
|
Q_UNUSED(end);
|
||||||
|
Q_UNUSED(typedChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::indentCurrentLine(QChar typedChar)
|
void FakeVimHandler::Private::indentCurrentLine(QChar typedChar)
|
||||||
@@ -1398,11 +1370,10 @@ void FakeVimHandler::Private::indentCurrentLine(QChar typedChar)
|
|||||||
|
|
||||||
void FakeVimHandler::Private::moveToDesiredColumn()
|
void FakeVimHandler::Private::moveToDesiredColumn()
|
||||||
{
|
{
|
||||||
if (m_desiredColumn == -1 || m_tc.block().length() <= m_desiredColumn) {
|
if (m_desiredColumn == -1 || m_tc.block().length() <= m_desiredColumn)
|
||||||
m_tc.movePosition(EndOfLine, KeepAnchor);
|
m_tc.movePosition(EndOfLine, KeepAnchor);
|
||||||
} else {
|
else
|
||||||
m_tc.setPosition(m_tc.block().position() + m_desiredColumn, KeepAnchor);
|
m_tc.setPosition(m_tc.block().position() + m_desiredColumn, KeepAnchor);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int charClass(QChar c, bool simple)
|
static int charClass(QChar c, bool simple)
|
||||||
@@ -1498,6 +1469,38 @@ void FakeVimHandler::Private::moveToNextWord(bool simple)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::Private::moveToMatchingParanthesis()
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
// FIXME: remove TextEditor dependency
|
||||||
|
bool undoFakeEOL = false;
|
||||||
|
if (atEol()) {
|
||||||
|
m_tc.movePosition(Left, KeepAnchor, 1);
|
||||||
|
undoFakeEOL = true;
|
||||||
|
}
|
||||||
|
TextEditor::TextBlockUserData::MatchType match
|
||||||
|
= TextEditor::TextBlockUserData::matchCursorForward(&m_tc);
|
||||||
|
if (match == TextEditor::TextBlockUserData::Match) {
|
||||||
|
if (m_submode == NoSubMode || m_submode == ZSubMode || m_submode == RegisterSubMode)
|
||||||
|
m_tc.movePosition(Left, KeepAnchor, 1);
|
||||||
|
} else {
|
||||||
|
if (undoFakeEOL)
|
||||||
|
m_tc.movePosition(Right, KeepAnchor, 1);
|
||||||
|
if (match == TextEditor::TextBlockUserData::NoMatch) {
|
||||||
|
// backward matching is according to the character before the cursor
|
||||||
|
bool undoMove = false;
|
||||||
|
if (!m_tc.atBlockEnd()) {
|
||||||
|
m_tc.movePosition(Right, KeepAnchor, 1);
|
||||||
|
undoMove = true;
|
||||||
|
}
|
||||||
|
match = TextEditor::TextBlockUserData::matchCursorBackward(&m_tc);
|
||||||
|
if (match != TextEditor::TextBlockUserData::Match && undoMove)
|
||||||
|
m_tc.movePosition(Left, KeepAnchor, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int FakeVimHandler::Private::cursorLineOnScreen() const
|
int FakeVimHandler::Private::cursorLineOnScreen() const
|
||||||
{
|
{
|
||||||
if (!editor())
|
if (!editor())
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ void FakeVimPlugin::installHandler(QWidget *widget)
|
|||||||
settings.m_spacesForTabs ? ConfigOn : ConfigOff);
|
settings.m_spacesForTabs ? ConfigOn : ConfigOff);
|
||||||
m_handler->setConfigValue(ConfigSmartTab,
|
m_handler->setConfigValue(ConfigSmartTab,
|
||||||
settings.m_smartBackspace ? ConfigOn : ConfigOff);
|
settings.m_smartBackspace ? ConfigOn : ConfigOff);
|
||||||
//m_handler->setConfigValue(ConfigSmartTab,
|
m_handler->setConfigValue(ConfigAutoIndent,
|
||||||
// settings.m_autoIndent ? ConfigOn : ConfigOff);
|
settings.m_autoIndent ? ConfigOn : ConfigOff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user