@@ -1004,7 +1004,10 @@ QStringList DocumentController::documentTypes() const
10041004
10051005static const QRegularExpression& emptyDocumentPattern ()
10061006{
1007- static const QRegularExpression pattern (QStringLiteral (" ^/(.+/)?%1(?:\\ s\\ ((\\ d+)\\ ))?$" ).arg (EMPTY_DOCUMENT_URL));
1007+ /* A hack that binds empty document to directory tree.
1008+ * It must be always bound to root dir, otherwise it may clash with existing
1009+ * files. */
1010+ static const QRegularExpression pattern (QStringLiteral (" ^/%1(?:\\ s\\ ((\\ d+)\\ ))?$" ).arg (EMPTY_DOCUMENT_URL));
10081011 return pattern;
10091012}
10101013
@@ -1021,11 +1024,13 @@ void DocumentController::updateDirectoryHint(const QString& path)
10211024QString DocumentController::currentDirectory () const
10221025{
10231026 if ( activeDocument () ) {
1024- QUrl url = activeDocument ()->url ().adjusted (
1025- QUrl::RemoveScheme |
1026- QUrl::RemoveFilename |
1027- QUrl::StripTrailingSlash);
1028- return url.toString ();
1027+ QUrl url = activeDocument ()->url ();
1028+ if (!isEmptyDocumentUrl (url)) {
1029+ return url.adjusted (
1030+ QUrl::RemoveScheme |
1031+ QUrl::RemoveFilename |
1032+ QUrl::StripTrailingSlash).toString ();
1033+ }
10291034 }
10301035 if (!d->directoryHint .isEmpty ()) {
10311036 return d->directoryHint ;
@@ -1036,7 +1041,7 @@ QString DocumentController::currentDirectory() const
10361041 return QString ();
10371042}
10381043
1039- QUrl DocumentController::nextEmptyDocumentUrl () const
1044+ QUrl DocumentController::nextEmptyDocumentUrl ()
10401045{
10411046 int nextEmptyDocNumber = 0 ;
10421047 const auto & pattern = emptyDocumentPattern ();
@@ -1054,9 +1059,9 @@ QUrl DocumentController::nextEmptyDocumentUrl() const
10541059
10551060 QUrl url;
10561061 if (nextEmptyDocNumber > 0 )
1057- url = QUrl::fromLocalFile (currentDirectory () + ' / ' + QStringLiteral (" %1 (%2)" ).arg (EMPTY_DOCUMENT_URL).arg (nextEmptyDocNumber));
1062+ url = QUrl::fromLocalFile (QStringLiteral (" / %1 (%2)" ).arg (EMPTY_DOCUMENT_URL).arg (nextEmptyDocNumber));
10581063 else
1059- url = QUrl::fromLocalFile (currentDirectory () + ' /' + EMPTY_DOCUMENT_URL);
1064+ url = QUrl::fromLocalFile (' /' + EMPTY_DOCUMENT_URL);
10601065 return url;
10611066}
10621067
0 commit comments