Skip to content

Commit fd6c1e4

Browse files
committed
Merge branch 'dev'
2 parents 3b705b7 + 41cd164 commit fd6c1e4

18 files changed

+366
-129
lines changed

main.js

+137-41
Large diffs are not rendered by default.

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "obsidian-memos",
33
"name": "Obsidian Memos",
44
"description": "A quick idea capture plugin for Obsidian",
5-
"version": "1.2.0",
5+
"version": "1.3.0",
66
"author": "Bonianll",
77
"authorUrl": "https://github.com/Quorafind/",
88
"isDesktopOnly": false,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-memos",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "A Quick Capture Plugin For Obsidian Daily Notes",
55
"author": "boninall",
66
"main": "main.js",

src/components/Editor/Editor.tsx

+69-21
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import ReactTextareaAutocomplete from "@webscopeio/react-textarea-autocomplete";
1010
import { usedTags } from '../../obComponents/obTagSuggester';
1111
import "../../less/suggest.less";
1212
import { SaveMemoButtonLabel } from "../../memos";
13+
import { getSuggestions } from "../../obComponents/obFileSuggester";
14+
import { TFile } from "obsidian";
15+
import appStore from "../../stores/appStore";
1316

1417
type ItemProps = {
1518
entity: {
1619
char: string,
17-
name: string
20+
name: string,
21+
file?: TFile
1822
}
1923
};
2024

@@ -43,7 +47,7 @@ interface EditorProps {
4347
}
4448

4549
//eslint-disable-next-line
46-
const Item = ({ entity: { name, char } }: ItemProps) => { return <div>{`${char}`}</div>};
50+
const TItem = ({ entity: { name, char, file } }: ItemProps) => { return <div>{`${char}`}</div>};
4751
//eslint-disable-next-line
4852
const Loading = ({ data }: LoadingProps) => { return <div>Loading</div> };
4953

@@ -152,30 +156,62 @@ const Editor = forwardRef((props: EditorProps, ref: React.ForwardedRef<EditorRef
152156
[]
153157
);
154158

155-
const handleInsertTrigger = (event: { currentTrigger: string; item: string}) => {
159+
const handleInsertTrigger = (event: { currentTrigger: string; item: any}) => {
156160
if (!editorRef.current) {
157161
return;
158162
}
159163

160-
const prevValue = editorRef.current.value;
161-
let removeCharNum;
162-
if(actualToken !== null){
163-
removeCharNum = actualToken.length;
164-
}else{
165-
removeCharNum = 0;
166-
}
167-
let behindCharNum = editorRef.current.selectionStart;
168-
for(let i = 0; i < prevValue.length;i++){
169-
if(prevValue[behindCharNum] !== " " ){
170-
behindCharNum++;
164+
const { fileManager } = appStore.getState().dailyNotesState.app;
165+
166+
if(event.currentTrigger === "#") {
167+
const prevValue = editorRef.current.value;
168+
let removeCharNum;
169+
if(actualToken !== null && actualToken !== undefined){
170+
removeCharNum = actualToken.length;
171+
}else{
172+
removeCharNum = 0;
173+
}
174+
let behindCharNum = editorRef.current.selectionStart;
175+
for(let i = 0; i < prevValue.length;i++){
176+
if(prevValue[behindCharNum] !== " " ){
177+
behindCharNum++;
178+
}
171179
}
172-
}
173180

174-
editorRef.current.value =
175-
//eslint-disable-next-line
176-
prevValue.slice(0, editorRef.current.selectionStart - removeCharNum) + event.item.char + prevValue.slice(behindCharNum);
177-
handleContentChangeCallback(editorRef.current.value);
178-
refresh();
181+
editorRef.current.value =
182+
//eslint-disable-next-line
183+
prevValue.slice(0, editorRef.current.selectionStart - removeCharNum) + event.item.char + prevValue.slice(behindCharNum);
184+
handleContentChangeCallback(editorRef.current.value);
185+
refresh();
186+
}else if(event.currentTrigger === "[["){
187+
const filePath = fileManager.generateMarkdownLink(event.item.file, event.item.file.path, "","");
188+
189+
const prevValue = editorRef.current.value;
190+
let removeCharNum;
191+
if(actualToken !== null && actualToken !== undefined){
192+
if(filePath.contains("[[")){
193+
removeCharNum = actualToken.length + 1;
194+
}else if(event.item.file.extension !== "md"){
195+
removeCharNum = actualToken.length + 1;
196+
}else {
197+
removeCharNum = actualToken.length + 2;
198+
}
199+
}else{
200+
removeCharNum = 2;
201+
}
202+
let behindCharNum = editorRef.current.selectionStart;
203+
for(let i = 0; i < prevValue.length;i++){
204+
if(prevValue[behindCharNum] !== " " ){
205+
behindCharNum++;
206+
}
207+
}
208+
209+
editorRef.current.value =
210+
//eslint-disable-next-line
211+
prevValue.slice(0, editorRef.current.selectionStart - removeCharNum) + filePath + prevValue.slice(behindCharNum);
212+
handleContentChangeCallback(editorRef.current.value);
213+
refresh();
214+
}
179215
}
180216

181217
const handleEditorInput = useCallback(() => {
@@ -266,7 +302,19 @@ const Editor = forwardRef((props: EditorProps, ref: React.ForwardedRef<EditorRef
266302
.map(({ name, char }) => ({ name, char }));
267303
},
268304
//eslint-disable-next-line
269-
component: Item,
305+
component: TItem,
306+
afterWhitespace: true,
307+
output: (item) => item.char,
308+
},
309+
"[[": {
310+
dataProvider: token => {
311+
actualToken = token;
312+
return getSuggestions(token)
313+
.slice(0,10)
314+
.map(({ name, char, file }) => ({ name, char, file }));
315+
},
316+
//eslint-disable-next-line
317+
component: TItem,
270318
afterWhitespace: true,
271319
output: (item) => item.char,
272320
},

src/components/MemoEditor.tsx

+20-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { usePopper } from 'react-popper';
1717
// import { format, isValid, parse } from 'date-fns';
1818
import FocusTrap from 'focus-trap-react';
1919
import moment from "moment";
20-
import { DefaultPrefix } from "../memos";
20+
import { DefaultPrefix, InsertDateFormat } from "../memos";
2121
import useToggle from "../hooks/useToggle";
2222
// import dailyNotesService from '../services/dailyNotesService';
2323
// import { TagsSuggest } from "../obComponents/obTagSuggester";
@@ -267,6 +267,8 @@ const MemoEditor: React.FC<Props> = () => {
267267

268268
if (date) {
269269
closePopper();
270+
isList = true;
271+
toggleList(true);
270272
} else {
271273

272274
}
@@ -282,12 +284,21 @@ const MemoEditor: React.FC<Props> = () => {
282284
}
283285

284286
if (prevString.endsWith("@")) {
285-
editorRef.current.element.value =
286-
//eslint-disable-next-line
287-
currentValue.slice(0, editorRef.current.element.selectionStart-1) + "📆" + todayMoment.format("YYYY-MM-DD") + nextString;
288-
editorRef.current.element.setSelectionRange(selectionStart+11, selectionStart+11);
289-
editorRef.current.focus();
290-
handleContentChange(editorRef.current.element.value);
287+
if( InsertDateFormat === "Dataview") {
288+
editorRef.current.element.value =
289+
//eslint-disable-next-line
290+
currentValue.slice(0, editorRef.current.element.selectionStart-1) + "[due::" + todayMoment.format("YYYY-MM-DD") + "]"+ nextString;
291+
editorRef.current.element.setSelectionRange(selectionStart+17, selectionStart+17);
292+
editorRef.current.focus();
293+
handleContentChange(editorRef.current.element.value);
294+
}else if( InsertDateFormat === "Tasks" ) {
295+
editorRef.current.element.value =
296+
//eslint-disable-next-line
297+
currentValue.slice(0, editorRef.current.element.selectionStart-1) + "📆" + todayMoment.format("YYYY-MM-DD") + nextString;
298+
editorRef.current.element.setSelectionRange(selectionStart+11, selectionStart+11);
299+
editorRef.current.focus();
300+
handleContentChange(editorRef.current.element.value);
301+
}
291302
} else {
292303
editorRef.current.element.value =
293304
//eslint-disable-next-line
@@ -398,9 +409,9 @@ const MemoEditor: React.FC<Props> = () => {
398409
{...editorConfig}
399410
tools={
400411
<>
401-
<img className="action-btn file-upload" src={tag} onClick={handleTagTextBtnClick} />
412+
<img className="action-btn add-tag" src={tag} onClick={handleTagTextBtnClick} />
402413
<img className="action-btn file-upload" src={imageSvg} onClick={handleUploadFileBtnClick} />
403-
<img className={`action-btn`} src={`${!isListShown ? journalSvg : taskSvg}`} onClick={handleChangeStatus} />
414+
<img className="action-btn list-or-task" src={`${!isListShown ? journalSvg : taskSvg}`} onClick={handleChangeStatus} />
404415
{/* <img className={`action-btn ${isListShown ? "" : "hidden"}`} src={taskSvg} onClick={handleChangeStatus} /> */}
405416
</>
406417
}

src/components/MemoList.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import "../less/memolist.less";
1010
import React from "react";
1111
import dailyNotesService from '../services/dailyNotesService';
1212
import appStore from "../stores/appStore";
13+
import { Platform } from 'obsidian';
1314

1415
interface Props {}
1516

@@ -127,7 +128,11 @@ const MemoList: React.FC<Props> = () => {
127128
}
128129
}else if( targetEl.tagName === "A" && targetEl.className === "internal-link" ){
129130
const sourcePath = targetEl.getAttribute("data-filepath");
130-
workspace.openLinkText(sourcePath,sourcePath,true);
131+
if(Platform.isMobile) {
132+
workspace.openLinkText(sourcePath,sourcePath,false);
133+
}else{
134+
workspace.openLinkText(sourcePath,sourcePath,true);
135+
}
131136
}
132137
}, []);
133138

src/icons/journal.svg

+1-1
Loading

src/icons/task.svg

+1-1
Loading

src/less/daily-memo.less

+14
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,23 @@
117117
padding: 0;
118118
font-size: 16px;
119119
margin-top: -3px;
120+
display: -webkit-box;
121+
122+
120123

121124
> .memo-content-text {
122125
margin-top: -14px;
126+
text-overflow:clip;
127+
overflow: hidden;
128+
-webkit-line-clamp: 2; /*限制在一个块元素显示的文本的行数*/
129+
-webkit-box-orient: vertical;
130+
overflow: hidden;
131+
width: 80%;
132+
text-overflow: ellipsis;
133+
-o-text-overflow: ellipsis;
134+
-webkit-text-overflow: ellipsis;
135+
-moz-text-overflow: ellipsis;
136+
white-space: nowrap; /*规定段落中的文本不进行换行*/**
123137

124138
.tag-span {
125139
cursor: unset;

src/less/editor.less

+9-5
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@
137137

138138
> .common-tools-container {
139139
.flex(row, flex-start, center);
140-
141-
> .action-btn-icons {
142-
> img {
143-
filter: invert(0.5);
144-
}
140+
141+
> img {
142+
filter: invert(0.8);
143+
color: yellowgreen;
145144
}
145+
146146
}
147147

148148
> .btns-container {
@@ -160,6 +160,10 @@
160160
font-size: 13px;
161161
line-height: 32px;
162162

163+
> img {
164+
filter: invert(0.8);
165+
}
166+
163167
&:hover {
164168
opacity: 0.8;
165169
}

src/less/global.less

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
font-style: normal;
2323
}
2424

25+
div[data-type="memos_view"] .view-content:not(.images-wrapper) img {
26+
max-width: 100%;
27+
cursor: default;
28+
}
29+
2530
.theme-light div[data-type="memos_view"] {
2631
margin: 0;
2732
padding: 0;
@@ -59,7 +64,7 @@
5964
.theme-light div[data-type="memos_view"] input,
6065
.theme-light div[data-type="memos_view"] button:not(.rdp-day_selected),
6166
.theme-light div[data-type="memos_view"] textarea,
62-
.theme-light img {
67+
.theme-light div[data-type="memos_view"] img {
6368
background-color: transparent;
6469
user-select: none;
6570
-webkit-tap-highlight-color: transparent;
@@ -166,7 +171,7 @@
166171
.theme-dark div[data-type="memos_view"] input,
167172
.theme-dark div[data-type="memos_view"] button,
168173
.theme-dark div[data-type="memos_view"] textarea,
169-
.theme-dark img {
174+
.theme-dark div[data-type="memos_view"] img {
170175
background-color: transparent;
171176
user-select: none;
172177
-webkit-tap-highlight-color: transparent;

src/obComponents/obFileSuggester.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes
2+
import { TAbstractFile, TFile } from "obsidian";
3+
import dailyNotesService from '../services/dailyNotesService';
4+
5+
export const getSuggestions = (inputStr: string) => {
6+
const { app } = dailyNotesService.getState();
7+
8+
const abstractFiles = app.vault.getAllLoadedFiles();
9+
// const files: TFile[] = [];
10+
const files = [] as any;
11+
12+
let actualInput: string;
13+
14+
abstractFiles.forEach((file: TAbstractFile) => {
15+
if(inputStr === "[") {
16+
actualInput = "";
17+
const lowerCaseInputStr = actualInput.toLowerCase();
18+
if (
19+
file instanceof TFile &&
20+
(file.extension === "md" || file.extension === "png" || file.extension === "jpg" || file.extension === "jpeg" || file.extension === "gif") &&
21+
file.path.toLowerCase().contains(lowerCaseInputStr)
22+
) {
23+
files.push({
24+
name: file.basename as string,
25+
char: file.name as string,
26+
file: file as TFile,
27+
});
28+
}
29+
} else if ( inputStr.contains("[") ) {
30+
actualInput = inputStr.slice(1);
31+
const lowerCaseInputStr = actualInput.toLowerCase();
32+
if (
33+
file instanceof TFile &&
34+
(file.extension === "md" || file.extension === "png" || file.extension === "jpg" || file.extension === "jpeg" || file.extension === "gif") &&
35+
file.path.toLowerCase().contains(lowerCaseInputStr)
36+
) {
37+
files.push({
38+
name: file.basename as string,
39+
char: file.name as string,
40+
file: file as TFile,
41+
});
42+
}
43+
}
44+
});
45+
46+
return files;
47+
}

0 commit comments

Comments
 (0)