forked from qt-creator/qt-creator
fakevim: improve selection interaction with main text editor
This commit is contained in:
@@ -132,6 +132,13 @@ FakeVimSettings *theFakeVimSettings()
|
|||||||
item->setValue(false);
|
item->setValue(false);
|
||||||
instance->insertItem(ConfigReadVimRc, item);
|
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 = new SavedAction(instance);
|
||||||
item->setValue(true);
|
item->setValue(true);
|
||||||
item->setDefaultValue(true);
|
item->setDefaultValue(true);
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ enum FakeVimSettingsCode
|
|||||||
{
|
{
|
||||||
ConfigUseFakeVim,
|
ConfigUseFakeVim,
|
||||||
ConfigReadVimRc,
|
ConfigReadVimRc,
|
||||||
|
ConfigExportSelection,
|
||||||
|
|
||||||
ConfigStartOfLine,
|
ConfigStartOfLine,
|
||||||
ConfigHlSearch,
|
ConfigHlSearch,
|
||||||
ConfigTabStop,
|
ConfigTabStop,
|
||||||
|
|||||||
@@ -733,6 +733,7 @@ public:
|
|||||||
void selectQuotedStringTextObject(bool inner, int type);
|
void selectQuotedStringTextObject(bool inner, int type);
|
||||||
|
|
||||||
Q_SLOT void importSelection();
|
Q_SLOT void importSelection();
|
||||||
|
void exportSelection();
|
||||||
void insertInInsertMode(const QString &text);
|
void insertInInsertMode(const QString &text);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -1050,20 +1051,20 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
|
|||||||
// key = shift(key);
|
// key = shift(key);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
QTC_ASSERT(m_mode == InsertMode || m_mode == ReplaceMode
|
//QTC_ASSERT(m_mode == InsertMode || m_mode == ReplaceMode
|
||||||
|| !m_tc.atBlockEnd() || m_tc.block().length() <= 1,
|
// || !m_tc.atBlockEnd() || m_tc.block().length() <= 1,
|
||||||
qDebug() << "Cursor at EOL before key handler");
|
// qDebug() << "Cursor at EOL before key handler");
|
||||||
|
|
||||||
EventResult result = handleKey(Input(key, mods, ev->text()));
|
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) {
|
if (m_textedit || m_plaintextedit) {
|
||||||
// We fake vi-style end-of-line behaviour
|
// We fake vi-style end-of-line behaviour
|
||||||
m_fakeEnd = atEndOfLine() && m_mode == CommandMode && !isVisualBlockMode();
|
m_fakeEnd = atEndOfLine() && m_mode == CommandMode && !isVisualBlockMode();
|
||||||
|
|
||||||
QTC_ASSERT(m_mode == InsertMode || m_mode == ReplaceMode
|
//QTC_ASSERT(m_mode == InsertMode || m_mode == ReplaceMode
|
||||||
|| !m_tc.atBlockEnd() || m_tc.block().length() <= 1,
|
// || !m_tc.atBlockEnd() || m_tc.block().length() <= 1,
|
||||||
qDebug() << "Cursor at EOL after key handler");
|
// qDebug() << "Cursor at EOL after key handler");
|
||||||
|
|
||||||
if (m_fakeEnd)
|
if (m_fakeEnd)
|
||||||
moveLeft();
|
moveLeft();
|
||||||
@@ -1075,6 +1076,8 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
|
|||||||
if (hasConfig(ConfigShowMarks))
|
if (hasConfig(ConfigShowMarks))
|
||||||
updateSelection();
|
updateSelection();
|
||||||
|
|
||||||
|
exportSelection();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1100,6 +1103,41 @@ void FakeVimHandler::Private::setupWidget()
|
|||||||
updateCursor();
|
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()
|
void FakeVimHandler::Private::importSelection()
|
||||||
{
|
{
|
||||||
QTextCursor tc = EDITOR(textCursor());
|
QTextCursor tc = EDITOR(textCursor());
|
||||||
@@ -1130,6 +1168,7 @@ void FakeVimHandler::Private::importSelection()
|
|||||||
tc.clearSelection();
|
tc.clearSelection();
|
||||||
EDITOR(setTextCursor(tc));
|
EDITOR(setTextCursor(tc));
|
||||||
updateSelection();
|
updateSelection();
|
||||||
|
exportSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::updateEditor()
|
void FakeVimHandler::Private::updateEditor()
|
||||||
|
|||||||
@@ -73,6 +73,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<item row="3" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="checkBoxSmartTab">
|
<widget class="QCheckBox" name="checkBoxSmartTab">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
@@ -169,6 +169,8 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent)
|
|||||||
m_ui.spinBoxShiftWidth);
|
m_ui.spinBoxShiftWidth);
|
||||||
m_group.insert(theFakeVimSetting(ConfigShowMarks),
|
m_group.insert(theFakeVimSetting(ConfigShowMarks),
|
||||||
m_ui.checkBoxShowMarks);
|
m_ui.checkBoxShowMarks);
|
||||||
|
m_group.insert(theFakeVimSetting(ConfigExportSelection),
|
||||||
|
m_ui.checkBoxExportSelection);
|
||||||
|
|
||||||
m_group.insert(theFakeVimSetting(ConfigSmartTab),
|
m_group.insert(theFakeVimSetting(ConfigSmartTab),
|
||||||
m_ui.checkBoxSmartTab);
|
m_ui.checkBoxSmartTab);
|
||||||
|
|||||||
Reference in New Issue
Block a user