Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

Commit b9a9e37

Browse files
authored
Merge pull request #5 from 0xGG/fix/windows-path
fix: Windows path issue
2 parents 7be909d + 1a88acf commit b9a9e37

File tree

9 files changed

+39
-16
lines changed

9 files changed

+39
-16
lines changed

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ webpack.config.js
1212
**/*.ts
1313
**/*.tsx
1414
*.vsix
15+
*.zip
1516

1617
# Manually include the node modules that we used
1718
node_modules

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"react-dom": "^16.13.1",
122122
"react-i18next": "^11.3.4",
123123
"react-lazyload": "^2.6.7",
124+
"slash": "^3.0.0",
124125
"styled-components": "^5.1.0",
125126
"subscriptions-transport-ws": "^0.9.16",
126127
"super-react-gist": "^1.0.4",
@@ -130,7 +131,7 @@
130131
"typeface-roboto": "^0.0.75",
131132
"typescript": "^3.8.3",
132133
"unstated-next": "^1.1.0",
133-
"vickymd": "^0.1.15",
134+
"vickymd": "^0.1.16",
134135
"yamljs": "^0.3.0"
135136
},
136137
"devDependencies": {

src/extension/TreeView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class CrossnoteTreeViewProvider
3333
this.crossnote.refreshNotesPanelWebview();
3434
const treeItems: CrossnoteTreeItem[] = [
3535
new CrossnoteTreeItem(
36-
"🗓 " + "Today",
36+
"📅 " + "Today",
3737
vscode.TreeItemCollapsibleState.None,
3838
notebook,
3939
CrossnoteSectionType.Today,

src/lib/crossnote.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export class Crossnote {
211211
}
212212
let needsToRefreshTagNode = false;
213213
let needsToRefreshTreeView = false;
214+
let needsToRefreshNotesPanelImmediately = false;
214215
let oldNote = notebook.notes.find((n) => n.filePath === newNote.filePath);
215216
if (!oldNote) {
216217
notebook.notes = [newNote, ...notebook.notes];
@@ -225,6 +226,15 @@ export class Crossnote {
225226
needsToRefreshTreeView = true;
226227
}
227228

229+
const oldNoteHasEncription = !!oldNote.config.encryption;
230+
const newNoteHasEncryption = !!newNote.config.encryption;
231+
if (
232+
oldNote.config.pinned !== newNote.config.pinned ||
233+
oldNoteHasEncription !== newNoteHasEncryption
234+
) {
235+
needsToRefreshNotesPanelImmediately = true;
236+
}
237+
228238
oldNote.config = newNote.config;
229239
oldNote.markdown = newNote.markdown;
230240
this.needsToRefreshNotesPanel = true;
@@ -242,6 +252,10 @@ export class Crossnote {
242252
if (needsToRefreshTreeView) {
243253
this.refreshTreeView();
244254
}
255+
256+
if (needsToRefreshNotesPanelImmediately) {
257+
this.sendNotesToNotesPanelWebview();
258+
}
245259
}
246260

247261
private startNotesPanelRefreshTimer() {

src/lib/notebook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import YAML from "yamljs";
44
import { Note, NoteConfig, getHeaderFromMarkdown } from "./note";
55
import AES from "crypto-js/aes";
66
import mkdirp from "mkdirp";
7+
import slash from "slash";
78
import { SelectedSection, CrossnoteSectionType } from "./section";
89
import { randomID } from "../util/util";
910

@@ -138,7 +139,7 @@ ${markdown}`;
138139
// Create note
139140
const note: Note = {
140141
notebookPath: this.dir,
141-
filePath: path.relative(this.dir, absFilePath),
142+
filePath: slash(path.relative(this.dir, absFilePath)),
142143
markdown: notFullMarkdown ? markdown.slice(0, 1000) : markdown,
143144
config: noteConfig,
144145
};

src/views/components/ChangeFilePathDialog.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useTranslation } from "react-i18next";
1111
import { Note } from "../../lib/note";
1212
import { vscode } from "../util/util";
1313
import { MessageAction } from "../../lib/message";
14+
import slash from "slash";
1415

1516
interface Props {
1617
open: boolean;
@@ -36,6 +37,7 @@ export default function ChangeFilePathDialog(props: Props) {
3637
if (!newFilePath.endsWith(".md")) {
3738
newFilePath = newFilePath + ".md";
3839
}
40+
newFilePath = slash(newFilePath);
3941
if (note.filePath !== newFilePath) {
4042
vscode.postMessage({
4143
action: MessageAction.ChangeNoteFilePath,

src/views/components/EditorPanel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,19 +620,19 @@ export default function EditorPanel(props: Props) {
620620
};
621621
editor.on("imageClicked", imageClickedHandler);
622622

623-
const imageRendered = (args: any) => {
623+
const loadImage = (args: any) => {
624624
const element = args.element;
625625
const imageSrc = element.getAttribute("data-src");
626626
element.setAttribute("src", resolveNoteImageSrc(note, imageSrc));
627627
};
628-
editor.on("imageRendered", imageRendered);
628+
editor.on("imageReadyToLoad", loadImage);
629629

630630
return () => {
631631
editor.off("changes", changesHandler);
632632
editor.off("keyup", keyupHandler);
633633
editor.off("linkIconClicked", linkIconClickedHandler);
634634
editor.off("imageClicked", imageClickedHandler);
635-
editor.off("imageRendered", imageRendered);
635+
editor.off("imageReadyToLoad", loadImage);
636636
};
637637
}, [editor, note, decryptionPassword, isDecrypted, openURL]);
638638

src/views/util/util.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Message } from "../../lib/message";
22
import { Note } from "../../lib/note";
33
import * as path from "path";
4+
import slash from "slash";
45

56
interface VSCodeWebviewAPI {
67
postMessage: (message: Message) => void;
@@ -18,14 +19,12 @@ export function resolveNoteImageSrc(note: Note, imageSrc: string) {
1819
} else if (imageSrc.startsWith("http://")) {
1920
return "";
2021
} else if (imageSrc.startsWith("/")) {
21-
return `vscode-resource://file//${path.resolve(
22-
note.notebookPath,
23-
"." + imageSrc
22+
return `vscode-resource://file//${slash(
23+
path.resolve(note.notebookPath, "." + imageSrc)
2424
)}`;
2525
} else {
26-
return `vscode-resource://file//${path.resolve(
27-
note.notebookPath,
28-
imageSrc
26+
return `vscode-resource://file//${slash(
27+
path.resolve(note.notebookPath, imageSrc)
2928
)}`;
3029
}
3130
}

yarn.lock

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6820,6 +6820,11 @@ simple-get@^3.0.2:
68206820
once "^1.3.1"
68216821
simple-concat "^1.0.0"
68226822

6823+
slash@^3.0.0:
6824+
version "3.0.0"
6825+
resolved "https://registry.npm.taobao.org/slash/download/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
6826+
integrity sha1-ZTm+hwwWWtvVJAIg2+Nh8bxNRjQ=
6827+
68236828
slugify@^1.3.1:
68246829
version "1.4.0"
68256830
resolved "https://registry.npm.taobao.org/slugify/download/slugify-1.4.0.tgz#c9557c653c54b0c7f7a8e786ef3431add676d2cb"
@@ -8108,10 +8113,10 @@ verror@1.10.0:
81088113
core-util-is "1.0.2"
81098114
extsprintf "^1.2.0"
81108115

8111-
vickymd@^0.1.15:
8112-
version "0.1.15"
8113-
resolved "https://registry.npm.taobao.org/vickymd/download/vickymd-0.1.15.tgz#09bde76fc414e72be3b096cfbb8fc419c5776cbf"
8114-
integrity sha1-Cb3nb8QU5yvjsJbPu4/EGcV3bL8=
8116+
vickymd@^0.1.16:
8117+
version "0.1.16"
8118+
resolved "https://registry.npm.taobao.org/vickymd/download/vickymd-0.1.16.tgz#6116b9523a893949a9afd3bf07c505de269add8d"
8119+
integrity sha1-YRa5UjqJOUmpr9O/B8UF3iaa3Y0=
81158120
optionalDependencies:
81168121
echarts "^4.7.0"
81178122
emojione "^4.5.0"

0 commit comments

Comments
 (0)