forked from qt-creator/qt-creator
fakevim: Implement special clipboard buffers
Introduces Vim's special registers "+ and "* and partial support for "clipboard" option - only values "unnamed" and "unnamedplus" and the behaviour is only similar. Task-number: QTCREATORBUG-6342 Change-Id: I1fa95b681edadacfe9690a2fd6eb2e98e7cc5dca Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -236,6 +236,13 @@ FakeVimSettings *theFakeVimSettings()
|
||||
item->setCheckable(true);
|
||||
instance->insertItem(ConfigPassControlKey, item, _("passcontrolkey"), _("pck"));
|
||||
|
||||
item = new SavedAction(instance);
|
||||
item->setDefaultValue(QString());
|
||||
item->setValue(QString());
|
||||
item->setSettingsKey(group, _("Clipboard"));
|
||||
item->setCheckable(true);
|
||||
instance->insertItem(ConfigClipboard, item, _("clipboard"), _("cb"));
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ enum FakeVimSettingsCode
|
||||
|
||||
// other actions
|
||||
ConfigShowMarks,
|
||||
ConfigPassControlKey
|
||||
ConfigPassControlKey,
|
||||
ConfigClipboard
|
||||
};
|
||||
|
||||
class FakeVimSettings : public QObject
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
#include <QStack>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QInputMethodEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QLineEdit>
|
||||
@@ -5267,11 +5268,41 @@ RangeMode FakeVimHandler::Private::registerRangeMode(int reg) const
|
||||
|
||||
void FakeVimHandler::Private::setRegisterContents(int reg, const QString &contents)
|
||||
{
|
||||
bool copyToClipboard = false;
|
||||
bool copyToSelection = false;
|
||||
if (reg == '"') {
|
||||
QStringList list = config(ConfigClipboard).toStringList();
|
||||
copyToClipboard = list.contains(QString("unnamedplus"));
|
||||
copyToSelection = list.contains(QString("unnamed"));
|
||||
} else if (reg == '+') {
|
||||
copyToClipboard = true;
|
||||
} else if (reg == '*') {
|
||||
copyToSelection = true;
|
||||
}
|
||||
|
||||
if (copyToClipboard || copyToSelection) {
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
bool hasSelection = clipboard->supportsSelection();
|
||||
if (copyToClipboard || (copyToSelection && !hasSelection))
|
||||
clipboard->setText(contents, QClipboard::Clipboard);
|
||||
if (copyToSelection && hasSelection)
|
||||
clipboard->setText(contents, QClipboard::Selection);
|
||||
} else {
|
||||
g.registers[reg].contents = contents;
|
||||
}
|
||||
}
|
||||
|
||||
QString FakeVimHandler::Private::registerContents(int reg) const
|
||||
{
|
||||
if (reg == '+')
|
||||
return QApplication::clipboard()->text(QClipboard::Clipboard);
|
||||
|
||||
if (reg == '*') {
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
return clipboard->text(clipboard->supportsSelection() ?
|
||||
QClipboard::Selection : QClipboard::Clipboard);
|
||||
}
|
||||
|
||||
return g.registers[reg].contents;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user