|  | 
| 15 | 15 | #include <QRegularExpression> | 
| 16 | 16 | #include <QTimer> | 
| 17 | 17 | 
 | 
|  | 18 | +#include "entities/notefolder.h" | 
| 18 | 19 | #include "services/settingsservice.h" | 
| 19 | 20 | #include "ui_linkdialog.h" | 
| 20 | 21 | #include "widgets/navigationwidget.h" | 
| @@ -125,7 +126,8 @@ QString LinkDialog::getSelectedHeading() const { | 
| 125 | 126 | QString LinkDialog::getURL() const { | 
| 126 | 127 |     QString url = ui->urlEdit->text().trimmed(); | 
| 127 | 128 | 
 | 
| 128 |  | -    if (!url.isEmpty() && !url.contains(QStringLiteral("://"))) { | 
|  | 129 | +    if (!url.isEmpty() && !url.contains(QStringLiteral("://")) && | 
|  | 130 | +        !url.startsWith(QStringLiteral("./"))) { | 
| 129 | 131 |         url = QStringLiteral("http://") + url; | 
| 130 | 132 |     } | 
| 131 | 133 | 
 | 
| @@ -317,6 +319,20 @@ void LinkDialog::addFileUrl() { | 
| 317 | 319 |         // store url for the next time | 
| 318 | 320 |         settings.setValue(QStringLiteral("LinkDialog/lastSelectedFileUrl"), fileUrlString); | 
| 319 | 321 | 
 | 
|  | 322 | +        // Check if the url is a file url and relative to the current note folder, if yes, convert | 
|  | 323 | +        // it to relative | 
|  | 324 | +        if (QUrl(fileUrlString).isLocalFile()) { | 
|  | 325 | +            QUrl fileUrl(fileUrlString); | 
|  | 326 | +            QString noteFolderPath = NoteFolder::currentLocalPath(); | 
|  | 327 | +            QString filePath = fileUrl.toLocalFile(); | 
|  | 328 | +            if (filePath.startsWith(noteFolderPath)) { | 
|  | 329 | +                fileUrlString = | 
|  | 330 | +                    QStringLiteral("./") + QDir(noteFolderPath).relativeFilePath(filePath); | 
|  | 331 | +            } | 
|  | 332 | +        } | 
|  | 333 | + | 
|  | 334 | +        qDebug() << __func__ << " - 'fileUrlString': " << fileUrlString; | 
|  | 335 | + | 
| 320 | 336 |         // write the file-url to the url text-edit | 
| 321 | 337 |         ui->urlEdit->setText(fileUrlString); | 
| 322 | 338 |     } | 
|  | 
0 commit comments