Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
2e2657b3
Unverified
Commit
2e2657b3
authored
Dec 24, 2022
by
Zeng1998
Committed by
GitHub
Dec 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add setting for power editor (#851)
parent
60ee6026
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
20 deletions
+34
-20
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+18
-16
PreferencesSection.tsx
web/src/components/Settings/PreferencesSection.tsx
+9
-1
en.json
web/src/locales/en.json
+1
-0
zh.json
web/src/locales/zh.json
+1
-0
user.ts
web/src/store/module/user.ts
+4
-3
setting.d.ts
web/src/types/modules/setting.d.ts
+1
-0
No files found.
web/src/components/MemoEditor.tsx
View file @
2e2657b3
...
...
@@ -59,6 +59,7 @@ const MemoEditor = () => {
const
tagSelectorRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
user
=
userStore
.
state
.
user
as
User
;
const
setting
=
user
.
setting
;
const
localSetting
=
user
.
localSetting
;
const
tags
=
tagStore
.
state
.
tags
;
const
memoVisibilityOptionSelectorItems
=
VISIBILITY_SELECTOR_ITEMS
.
map
((
item
)
=>
{
return
{
...
...
@@ -215,24 +216,25 @@ const MemoEditor = () => {
}
}
for
(
const
symbol
of
pairSymbols
)
{
if
(
event
.
key
===
symbol
[
0
])
{
event
.
preventDefault
();
editorRef
.
current
.
insertText
(
""
,
symbol
[
0
],
symbol
[
1
]);
return
;
if
(
localSetting
.
enablePowerfulEditor
)
{
for
(
const
symbol
of
pairSymbols
)
{
if
(
event
.
key
===
symbol
[
0
])
{
event
.
preventDefault
();
editorRef
.
current
.
insertText
(
""
,
symbol
[
0
],
symbol
[
1
]);
return
;
}
}
}
if
(
event
.
key
===
"Backspace"
)
{
const
cursor
=
editorRef
.
current
.
getCursorPosition
(
);
const
content
=
editorRef
.
current
.
getContent
(
);
const
deleteChar
=
content
?.
slice
(
cursor
-
1
,
cursor
);
const
nextChar
=
content
?.
slice
(
cursor
,
cursor
+
1
);
if
(
pairSymbols
.
includes
(
`
${
deleteChar
}${
nextChar
}
`
))
{
event
.
preventDefault
();
editorRef
.
current
.
removeText
(
cursor
-
1
,
2
)
;
if
(
event
.
key
===
"Backspace"
)
{
const
cursor
=
editorRef
.
current
.
getCursorPosition
();
const
content
=
editorRef
.
current
.
getContent
();
const
deleteChar
=
content
?.
slice
(
cursor
-
1
,
cursor
);
const
nextChar
=
content
?.
slice
(
cursor
,
cursor
+
1
);
if
(
pairSymbols
.
includes
(
`
${
deleteChar
}${
nextChar
}
`
))
{
event
.
preventDefault
(
);
editorRef
.
current
.
removeText
(
cursor
-
1
,
2
);
}
return
;
}
return
;
}
};
...
...
web/src/components/Settings/PreferencesSection.tsx
View file @
2e2657b3
...
...
@@ -45,7 +45,11 @@ const PreferencesSection = () => {
};
const
handleIsFoldingEnabledChanged
=
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
userStore
.
upsertLocalSetting
(
"enableFoldMemo"
,
event
.
target
.
checked
);
userStore
.
upsertLocalSetting
({
...
localSetting
,
enableFoldMemo
:
event
.
target
.
checked
});
};
const
handlePowerfulEditorEnabledChanged
=
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
userStore
.
upsertLocalSetting
({
...
localSetting
,
enablePowerfulEditor
:
event
.
target
.
checked
});
};
return
(
...
...
@@ -100,6 +104,10 @@ const PreferencesSection = () => {
<
span
className=
"normal-text"
>
{
t
(
"setting.preference-section.enable-folding-memo"
)
}
</
span
>
<
Switch
className=
"ml-2"
checked=
{
localSetting
.
enableFoldMemo
}
onChange=
{
handleIsFoldingEnabledChanged
}
/>
</
label
>
<
label
className=
"form-label selector"
>
<
span
className=
"normal-text"
>
{
t
(
"setting.preference-section.enable-powerful-editor"
)
}
</
span
>
<
Switch
className=
"ml-2"
checked=
{
localSetting
.
enablePowerfulEditor
}
onChange=
{
handlePowerfulEditorEnabledChanged
}
/>
</
label
>
</
div
>
);
};
...
...
web/src/locales/en.json
View file @
2e2657b3
...
...
@@ -161,6 +161,7 @@
"theme"
:
"Theme"
,
"default-memo-visibility"
:
"Default memo visibility"
,
"enable-folding-memo"
:
"Enable folding memo"
,
"enable-powerful-editor"
:
"Enable powerful editor"
,
"editor-font-style"
:
"Editor font style"
,
"mobile-editor-style"
:
"Mobile editor style"
,
"default-memo-sort-option"
:
"Memo display time"
,
...
...
web/src/locales/zh.json
View file @
2e2657b3
...
...
@@ -161,6 +161,7 @@
"theme"
:
"主题"
,
"default-memo-visibility"
:
"默认 Memo 可见性"
,
"enable-folding-memo"
:
"开启折叠 Memo"
,
"enable-powerful-editor"
:
"开启编辑器自动补全"
,
"editor-font-style"
:
"编辑器字体样式"
,
"mobile-editor-style"
:
"移动端编辑器样式"
,
"default-memo-sort-option"
:
"Memo 显示时间"
,
...
...
web/src/store/module/user.ts
View file @
2e2657b3
...
...
@@ -15,6 +15,7 @@ const defaultSetting: Setting = {
const
defaultLocalSetting
:
LocalSetting
=
{
enableFoldMemo
:
true
,
enablePowerfulEditor
:
true
,
};
export
const
convertResponseModelUser
=
(
user
:
User
):
User
=>
{
...
...
@@ -133,9 +134,9 @@ export const useUserStore = () => {
});
await
doSignIn
();
},
upsertLocalSetting
:
async
(
key
:
keyof
LocalSetting
,
value
:
any
)
=>
{
storage
.
set
({
localSetting
:
{
[
key
]:
value
}
});
store
.
dispatch
(
patchUser
({
localSetting
:
{
[
key
]:
value
}
}));
upsertLocalSetting
:
async
(
localSetting
:
LocalSetting
)
=>
{
storage
.
set
({
localSetting
});
store
.
dispatch
(
patchUser
({
localSetting
}));
},
patchUser
:
async
(
userPatch
:
UserPatch
):
Promise
<
void
>
=>
{
const
{
data
}
=
(
await
api
.
patchUser
(
userPatch
)).
data
;
...
...
web/src/types/modules/setting.d.ts
View file @
2e2657b3
...
...
@@ -9,6 +9,7 @@ interface Setting {
interface
LocalSetting
{
enableFoldMemo
:
boolean
;
enablePowerfulEditor
:
boolean
;
}
interface
UserLocaleSetting
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment