Commit 40a9463c authored by hjk's avatar hjk
Browse files

FakeVim: Expand ~ in some file names



For :read and :source.

Task-number: QTCREATORBUG-11160
Change-Id: I636593a16f9e39c25585c221c5d978e842f4c1d4
Reviewed-by: default avatarLukas Holecek <hluk@email.cz>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 6d978284
......@@ -84,6 +84,7 @@
#include <QTextEdit>
#include <QMimeData>
#include <QSharedPointer>
#include <QDir>
#include <algorithm>
#include <climits>
......@@ -373,6 +374,12 @@ struct SearchData
bool highlightMatches = true;
};
static QString replaceTildeWithHome(QString str)
{
str.replace("~", QDir::homePath());
return str;
}
// If string begins with given prefix remove it with trailing spaces and return true.
static bool eatString(const QString &prefix, QString *str)
{
......@@ -5899,6 +5906,7 @@ bool FakeVimHandler::Private::handleExJoinCommand(const ExCommand &cmd)
bool FakeVimHandler::Private::handleExWriteCommand(const ExCommand &cmd)
{
// Note: The cmd.args.isEmpty() case is handled by handleExPluginCommand.
// :w, :x, :wq, ...
//static QRegExp reWrite("^[wx]q?a?!?( (.*))?$");
if (cmd.cmd != "w" && cmd.cmd != "x" && cmd.cmd != "wq")
......@@ -5916,7 +5924,7 @@ bool FakeVimHandler::Private::handleExWriteCommand(const ExCommand &cmd)
const bool forced = cmd.hasBang;
//const bool quit = prefix.contains('q') || prefix.contains('x');
//const bool quitAll = quit && prefix.contains('a');
QString fileName = cmd.args;
QString fileName = replaceTildeWithHome(cmd.args);
if (fileName.isEmpty())
fileName = m_currentFileName;
QFile file1(fileName);
......@@ -5969,7 +5977,7 @@ bool FakeVimHandler::Private::handleExReadCommand(const ExCommand &cmd)
moveDown();
int pos = position();
m_currentFileName = cmd.args;
m_currentFileName = replaceTildeWithHome(cmd.args);
QFile file(m_currentFileName);
file.open(QIODevice::ReadOnly);
QTextStream ts(&file);
......@@ -6092,7 +6100,7 @@ bool FakeVimHandler::Private::handleExSourceCommand(const ExCommand &cmd)
if (cmd.cmd != "so" && cmd.cmd != "source")
return false;
QString fileName = cmd.args;
QString fileName = replaceTildeWithHome(cmd.args);
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
showMessage(MessageError, Tr::tr("Cannot open file %1").arg(fileName));
......
......@@ -1977,7 +1977,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
editor->setFocus();
*handled = true;
if (cmd.matches("w", "write") || cmd.cmd == "wq") {
if ((cmd.matches("w", "write") || cmd.cmd == "wq") && cmd.args.isEmpty()) {
// :w[rite]
IEditor *editor = m_editorToHandler.key(handler);
const QString fileName = handler->currentFileName();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment