mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
Desktop: Fixes #6145: Opening a file with ctrl-click in the editor results in a 'network error' dialogue
This commit is contained in:
parent
7c619df2ce
commit
f27d15a5a7
@ -9,6 +9,7 @@ import Tag from './Tag';
|
||||
import ItemChange from './ItemChange';
|
||||
import Resource from './Resource';
|
||||
import { ResourceEntity } from '../services/database/types';
|
||||
import { toForwardSlashes } from '../path-utils';
|
||||
const ArrayUtils = require('../ArrayUtils.js');
|
||||
|
||||
async function allItems() {
|
||||
@ -259,7 +260,8 @@ describe('models/Note', function() {
|
||||
const t1 = r1.updated_time;
|
||||
const t2 = r2.updated_time;
|
||||
|
||||
const resourceDirE = markdownUtils.escapeLinkUrl(resourceDir);
|
||||
const resourceDirE = markdownUtils.escapeLinkUrl(toForwardSlashes(resourceDir));
|
||||
const fileProtocol = `file://${process.platform === 'win32' ? '/' : ''}`;
|
||||
|
||||
const testCases = [
|
||||
[
|
||||
@ -285,17 +287,17 @@ describe('models/Note', function() {
|
||||
[
|
||||
true,
|
||||
`![](:/${r1.id})`,
|
||||
`![](file://${resourceDirE}/${r1.id}.jpg?t=${t1})`,
|
||||
`![](${fileProtocol}${resourceDirE}/${r1.id}.jpg?t=${t1})`,
|
||||
],
|
||||
[
|
||||
true,
|
||||
`![](:/${r1.id}) ![](:/${r1.id}) ![](:/${r2.id})`,
|
||||
`![](file://${resourceDirE}/${r1.id}.jpg?t=${t1}) ![](file://${resourceDirE}/${r1.id}.jpg?t=${t1}) ![](file://${resourceDirE}/${r2.id}.jpg?t=${t2})`,
|
||||
`![](${fileProtocol}${resourceDirE}/${r1.id}.jpg?t=${t1}) ![](${fileProtocol}${resourceDirE}/${r1.id}.jpg?t=${t1}) ![](${fileProtocol}${resourceDirE}/${r2.id}.jpg?t=${t2})`,
|
||||
],
|
||||
[
|
||||
true,
|
||||
`![](:/${r3.id})`,
|
||||
`![](file://${resourceDirE}/${r3.id}.pdf)`,
|
||||
`![](${fileProtocol}${resourceDirE}/${r3.id}.pdf)`,
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -11,6 +11,7 @@ import Tag from './Tag';
|
||||
const { sprintf } = require('sprintf-js');
|
||||
import Resource from './Resource';
|
||||
import syncDebugLog from '../services/synchronizer/syncDebugLog';
|
||||
import { toFileProtocolPath, toForwardSlashes } from '../path-utils';
|
||||
const { pregQuote, substrWithEllipsis } = require('../string-utils.js');
|
||||
const { _ } = require('../locale');
|
||||
const ArrayUtils = require('../ArrayUtils.js');
|
||||
@ -167,7 +168,7 @@ export default class Note extends BaseItem {
|
||||
// change, the preview is updated inside the note. This is not
|
||||
// needed for other resources since they are simple links.
|
||||
const timestampParam = isImage ? `?t=${resource.updated_time}` : '';
|
||||
const resourcePath = options.useAbsolutePaths ? `file://${Resource.fullPath(resource)}${timestampParam}` : Resource.relativePath(resource);
|
||||
const resourcePath = options.useAbsolutePaths ? toFileProtocolPath(Resource.fullPath(resource)) + timestampParam : Resource.relativePath(resource);
|
||||
body = body.replace(new RegExp(`:/${id}`, 'gi'), markdownUtils.escapeLinkUrl(resourcePath));
|
||||
}
|
||||
|
||||
@ -181,10 +182,14 @@ export default class Note extends BaseItem {
|
||||
useAbsolutePaths: false,
|
||||
}, options);
|
||||
|
||||
const resourceDir = toForwardSlashes(Setting.value('resourceDir'));
|
||||
|
||||
let pathsToTry = [];
|
||||
if (options.useAbsolutePaths) {
|
||||
pathsToTry.push(`file://${Setting.value('resourceDir')}`);
|
||||
pathsToTry.push(`file://${shim.pathRelativeToCwd(Setting.value('resourceDir'))}`);
|
||||
pathsToTry.push(`file://${resourceDir}`);
|
||||
pathsToTry.push(`file:///${resourceDir}`);
|
||||
pathsToTry.push(`file://${shim.pathRelativeToCwd(resourceDir)}`);
|
||||
pathsToTry.push(`file:///${shim.pathRelativeToCwd(resourceDir)}`);
|
||||
} else {
|
||||
pathsToTry.push(Resource.baseRelativeDirectoryPath());
|
||||
}
|
||||
|
@ -146,6 +146,10 @@ export function toSystemSlashes(path: string, os: string = null) {
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
export function toForwardSlashes(path: string) {
|
||||
return toSystemSlashes(path, 'linux');
|
||||
}
|
||||
|
||||
export function rtrimSlashes(path: string) {
|
||||
return path.replace(/[\/\\]+$/, '');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user