Skip to content

Commit

Permalink
support vim e command in vmdtab and vvim (vnotex#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHate authored Feb 23, 2020
1 parent 8e75c40 commit 6158263
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/utils/vvim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
#include <QClipboard>
#include <QApplication>
#include <QMimeData>
#include <QDir>
#include "vconfigmanager.h"
#include "veditor.h"
#include "utils/veditutils.h"
#include "vconstants.h"
#include "vmdeditor.h"
#include "vmainwindow.h"
#include "vdirectory.h"
#include "vdirectorytree.h"

extern VConfigManager *g_config;
extern VMainWindow *g_mainWin;

const QChar VVim::c_unnamedRegister = QChar('"');
const QChar VVim::c_blackHoleRegister = QChar('_');
Expand Down Expand Up @@ -5953,6 +5958,27 @@ bool VVim::executeCommand(const QString &p_cmd)
} else if (p_cmd == "nohlsearch" || p_cmd == "noh") {
// :nohlsearch, clear highlight search.
clearSearchHighlight();
} else if (p_cmd.size() > 3 && p_cmd.left(2) == "e ") {
// :e <file>, open a note in edit mode.
auto filePath = p_cmd.mid(2).trimmed();

if(filePath.left(2) == "~/") {
filePath.remove(0, 1).insert(0, QDir::homePath());
} else if(filePath.left(2) == "./" || filePath[0] != '/') {
VDirectory *dir = g_mainWin->getDirectoryTree()->currentDirectory();
if(filePath.left(2) == "./") {
filePath.remove(0, 1);
} else {
filePath.insert(0, '/');
}
filePath.insert(0, dir->fetchPath());
}

if(g_mainWin->openFiles(QStringList(filePath), false, OpenFileMode::Edit).size()) {
msg = tr("Open %1 in edit mode.").arg(filePath);
} else {
msg = tr("Unable to open %1").arg(filePath);
}
} else {
validCommand = false;
}
Expand Down
26 changes: 26 additions & 0 deletions src/vmdtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "vsnippetlist.h"
#include "vlivepreviewhelper.h"
#include "vmathjaxinplacepreviewhelper.h"
#include "vdirectory.h"
#include "vdirectorytree.h"

extern VMainWindow *g_mainWin;

Expand Down Expand Up @@ -1457,6 +1459,30 @@ bool VMdTab::executeVimCommandInWebView(const QString &p_cmd)
} else if (p_cmd == "nohlsearch" || p_cmd == "noh") {
// :nohlsearch, clear highlight search.
m_webViewer->findText("");
} else if (p_cmd == "e") {
// :e, enter edit mode.
showFileEditMode();
} else if (p_cmd.size() > 2 && p_cmd.left(2) == "e ") {
// :e <file>, open a note in edit mode.
auto filePath = p_cmd.mid(2).trimmed();

if(filePath.left(2) == "~/") {
filePath.remove(0, 1).insert(0, QDir::homePath());
} else if(filePath.left(2) == "./" || filePath[0] != '/') {
VDirectory *dir = g_mainWin->getDirectoryTree()->currentDirectory();
if(filePath.left(2) == "./") {
filePath.remove(0, 1);
} else {
filePath.insert(0, '/');
}
filePath.insert(0, dir->fetchPath());
}

if(g_mainWin->openFiles(QStringList(filePath), false, OpenFileMode::Edit).size()) {
msg = tr("Open %1 in edit mode.").arg(filePath);
} else {
msg = tr("Unable to open %1").arg(filePath);
}
} else {
validCommand = false;
}
Expand Down

0 comments on commit 6158263

Please sign in to comment.