diff --git a/src/vimode/appcommands.h b/src/vimode/appcommands.h --- a/src/vimode/appcommands.h +++ b/src/vimode/appcommands.h @@ -72,6 +72,7 @@ QRegExp re_quit; QRegExp re_exit; QRegExp re_edit; + QRegExp re_tabedit; QRegExp re_new; QRegExp re_split; QRegExp re_vsplit; diff --git a/src/vimode/appcommands.cpp b/src/vimode/appcommands.cpp --- a/src/vimode/appcommands.cpp +++ b/src/vimode/appcommands.cpp @@ -47,6 +47,7 @@ re_quit.setPattern(QStringLiteral("(w)?q(a|all)?(!)?")); re_exit.setPattern(QStringLiteral("x(a)?")); re_edit.setPattern(QStringLiteral("e(dit)?|tabe(dit)?|tabnew")); + re_tabedit.setPattern(QStringLiteral("tabe(dit)?|tabnew")); re_new.setPattern(QStringLiteral("(v)?new")); re_split.setPattern(QStringLiteral("sp(lit)?")); re_vsplit.setPattern(QStringLiteral("vs(plit)?")); @@ -80,7 +81,7 @@ } // Other buffer commands are implemented by the KateFileTree plugin else if (re_close.exactMatch(command)) { - app->closeDocument(view->document()); + QTimer::singleShot(0, [app, view](){ app->closeDocument(view->document()); }); } else if (re_quit.exactMatch(command)) { const bool save = !re_quit.cap(1).isEmpty(); // :[w]q const bool allDocuments = !re_quit.cap(2).isEmpty(); // :q[all] @@ -141,7 +142,13 @@ } else if (re_edit.exactMatch(command)) { QString argument = args.join(QLatin1Char(' ')); if (argument.isEmpty() || argument == QLatin1String("!")) { - view->document()->documentReload(); + if (re_tabedit.exactMatch(command)) { + if (auto doc = app->openUrl(QUrl())) { + QTimer::singleShot(0, [mainWin, doc](){ mainWin->activateView(doc); }); + } + } else { + view->document()->documentReload(); + } } else { QUrl base = view->document()->url(); QUrl url; @@ -155,12 +162,17 @@ KTextEditor::Document *doc = app->findUrl(url); + if (!doc) { + if (file.exists()) { + doc = app->openUrl(url); + } else { + if ((doc = app->openUrl(QUrl()))) { + doc->saveAs(url); + } + } + } if (doc) { - mainWin->activateView(doc); - } else if (file.exists()) { - app->openUrl(url); - } else { - app->openUrl(QUrl())->saveAs(url); + QTimer::singleShot(0, [mainWin, doc](){ mainWin->activateView(doc); }); } } // splitView() orientations are reversed from the usual editor convention. @@ -278,7 +290,7 @@ { KTextEditor::Application *app = KTextEditor::Editor::instance()->application(); KTextEditor::Document *doc = app->activeMainWindow()->activeView()->document(); - app->closeDocument(doc); + QTimer::singleShot(0, [app, doc](){ app->closeDocument(doc); }); } void AppCommands::closeCurrentView() @@ -390,7 +402,7 @@ } if (doc) { - activateDocument(view, docs.at(idx - 1)); + activateDocument(view, doc); } } } @@ -402,7 +414,7 @@ if (idx > 0) { activateDocument(view, docs.at(idx - 1)); - } else { // wrap + } else if (!docs.isEmpty()) { // wrap activateDocument(view, docs.last()); } } @@ -414,19 +426,25 @@ if (idx + 1 < docs.size()) { activateDocument(view, docs.at(idx + 1)); - } else { // wrap + } else if (!docs.isEmpty()) { // wrap activateDocument(view, docs.first()); } } void BufferCommands::firstBuffer(KTextEditor::View *view) { - activateDocument(view, documents().at(0)); + auto docs = documents(); + if (!docs.isEmpty()) { + activateDocument(view, documents().at(0)); + } } void BufferCommands::lastBuffer(KTextEditor::View *view) { - activateDocument(view, documents().last()); + auto docs = documents(); + if (!docs.isEmpty()) { + activateDocument(view, documents().last()); + } } void BufferCommands::prevTab(KTextEditor::View *view) @@ -452,7 +470,7 @@ void BufferCommands::activateDocument(KTextEditor::View *view, KTextEditor::Document *doc) { KTextEditor::MainWindow *mainWindow = view->mainWindow(); - mainWindow->activateView(doc); + QTimer::singleShot(0, [mainWindow, doc]() { mainWindow->activateView(doc); }); } QList< KTextEditor::Document * > BufferCommands::documents() diff --git a/src/vimode/emulatedcommandbar/commandmode.cpp b/src/vimode/emulatedcommandbar/commandmode.cpp --- a/src/vimode/emulatedcommandbar/commandmode.cpp +++ b/src/vimode/emulatedcommandbar/commandmode.cpp @@ -224,7 +224,7 @@ } // the following commands change the focus themselves - if (!QRegExp(QLatin1String("buffer|b|new|vnew|bp|bprev|bn|bnext|bf|bfirst|bl|blast|edit|e")).exactMatch(cmd.split(QLatin1String(" ")).at(0))) { + if (!QRegExp(QLatin1String("buffer|b|new|vnew|bp|bprev|tabp|tabprev|bn|bnext|tabn|tabnext|bf|bfirst|tabf|tabfirst|bl|blast|tabl|tablast|e|edit|tabe|tabedit|tabnew")).exactMatch(cmd.split(QLatin1Char(' ')).at(0))) { view()->setFocus(); }