diff --git a/src/plugins/fakevim/fakevimactions.cpp b/src/plugins/fakevim/fakevimactions.cpp index a17fbe146c15f6f32c855d335634a3b359a6eb20..49db4d3b0163274d5f81692f307c2c34abd69af4 100644 --- a/src/plugins/fakevim/fakevimactions.cpp +++ b/src/plugins/fakevim/fakevimactions.cpp @@ -132,6 +132,13 @@ FakeVimSettings *theFakeVimSettings() item->setValue(false); instance->insertItem(ConfigReadVimRc, item); + item = new SavedAction(instance); + item->setValue(true); + item->setDefaultValue(true); + item->setSettingsKey(group, _("ExportSelection")); + item->setCheckable(true); + instance->insertItem(ConfigExportSelection, item); + item = new SavedAction(instance); item->setValue(true); item->setDefaultValue(true); diff --git a/src/plugins/fakevim/fakevimactions.h b/src/plugins/fakevim/fakevimactions.h index 5929376bc68f95a26d53c37d3c86c77c5811dad6..19284391ac584d79136ee339880ef37c9f0c9c2f 100644 --- a/src/plugins/fakevim/fakevimactions.h +++ b/src/plugins/fakevim/fakevimactions.h @@ -43,6 +43,8 @@ enum FakeVimSettingsCode { ConfigUseFakeVim, ConfigReadVimRc, + ConfigExportSelection, + ConfigStartOfLine, ConfigHlSearch, ConfigTabStop, diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index ab8a1a23a933d2a850c8ece1ae6d41ba3e7e3e86..f84cacd5351c53cf15418c552ce5e810163519e5 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -733,6 +733,7 @@ public: void selectQuotedStringTextObject(bool inner, int type); Q_SLOT void importSelection(); + void exportSelection(); void insertInInsertMode(const QString &text); public: @@ -1050,20 +1051,20 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev) // key = shift(key); //} - QTC_ASSERT(m_mode == InsertMode || m_mode == ReplaceMode - || !m_tc.atBlockEnd() || m_tc.block().length() <= 1, - qDebug() << "Cursor at EOL before key handler"); + //QTC_ASSERT(m_mode == InsertMode || m_mode == ReplaceMode + // || !m_tc.atBlockEnd() || m_tc.block().length() <= 1, + // qDebug() << "Cursor at EOL before key handler"); EventResult result = handleKey(Input(key, mods, ev->text())); - // the command might have destroyed the editor + // The command might have destroyed the editor. if (m_textedit || m_plaintextedit) { // We fake vi-style end-of-line behaviour m_fakeEnd = atEndOfLine() && m_mode == CommandMode && !isVisualBlockMode(); - QTC_ASSERT(m_mode == InsertMode || m_mode == ReplaceMode - || !m_tc.atBlockEnd() || m_tc.block().length() <= 1, - qDebug() << "Cursor at EOL after key handler"); + //QTC_ASSERT(m_mode == InsertMode || m_mode == ReplaceMode + // || !m_tc.atBlockEnd() || m_tc.block().length() <= 1, + // qDebug() << "Cursor at EOL after key handler"); if (m_fakeEnd) moveLeft(); @@ -1075,6 +1076,8 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev) if (hasConfig(ConfigShowMarks)) updateSelection(); + exportSelection(); + return result; } @@ -1100,6 +1103,41 @@ void FakeVimHandler::Private::setupWidget() updateCursor(); } +void FakeVimHandler::Private::exportSelection() +{ + if (!hasConfig(ConfigExportSelection)) + return; + + // FIXME: That's hacky and does not work for block selections + // and the clipboard is not filled if the selections are updated + // using the keyboard. + QTextCursor tc = EDITOR(textCursor()); + int pos = position(); + int anc = anchor(); + if (m_visualMode == VisualBlockMode) { + //tc.setPosition(anc, MoveAnchor); + //tc.setPosition(pos, KeepAnchor); + //EDITOR(setTextCursor(tc)); + } else if (m_visualMode == VisualLineMode) { + int posLine = lineForPosition(pos); + int ancLine = lineForPosition(anc); + if (anc < pos) { + pos = lastPositionInLine(posLine); + anc = firstPositionInLine(ancLine); + } else { + pos = firstPositionInLine(posLine); + anc = lastPositionInLine(ancLine); + } + tc.setPosition(anc, MoveAnchor); + tc.setPosition(pos, KeepAnchor); + EDITOR(setTextCursor(tc)); + } else if (m_visualMode == VisualCharMode) { + tc.setPosition(anc, MoveAnchor); + tc.setPosition(pos, KeepAnchor); + EDITOR(setTextCursor(tc)); + } +} + void FakeVimHandler::Private::importSelection() { QTextCursor tc = EDITOR(textCursor()); @@ -1130,6 +1168,7 @@ void FakeVimHandler::Private::importSelection() tc.clearSelection(); EDITOR(setTextCursor(tc)); updateSelection(); + exportSelection(); } void FakeVimHandler::Private::updateEditor() diff --git a/src/plugins/fakevim/fakevimoptions.ui b/src/plugins/fakevim/fakevimoptions.ui index 450a8629065d6f947f8b0e40c76c8e9d5a9eb98e..51f19c49111280c7db8b89d97ddd1270ac8fb0e6 100644 --- a/src/plugins/fakevim/fakevimoptions.ui +++ b/src/plugins/fakevim/fakevimoptions.ui @@ -73,6 +73,16 @@ </property> </widget> </item> + <item row="3" column="2"> + <widget class="QCheckBox" name="checkBoxExportSelection"> + <property name="text"> + <string>Export selected text automatically</string> + </property> + <property name="toolTip"> + <string>This might slow down editing</string> + </property> + </widget> + </item> <item row="3" column="0" colspan="2"> <widget class="QCheckBox" name="checkBoxSmartTab"> <property name="text"> diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 8883ada1fb8df73f7531c192198b9fccf27c157a..82fab17608727e1bf102d3a624bb582b5ed56021 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -169,6 +169,8 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent) m_ui.spinBoxShiftWidth); m_group.insert(theFakeVimSetting(ConfigShowMarks), m_ui.checkBoxShowMarks); + m_group.insert(theFakeVimSetting(ConfigExportSelection), + m_ui.checkBoxExportSelection); m_group.insert(theFakeVimSetting(ConfigSmartTab), m_ui.checkBoxSmartTab);