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
e526cef7
Unverified
Commit
e526cef7
authored
Mar 17, 2023
by
boojack
Committed by
GitHub
Mar 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: handle IME mode in editor (#1371)
* fix: handle IME mode in editor * chore: update
parent
2ba0dbf5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
5 deletions
+26
-5
AskAIDialog.tsx
web/src/components/AskAIDialog.tsx
+20
-2
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+4
-1
SystemSection.tsx
web/src/components/Settings/SystemSection.tsx
+2
-2
No files found.
web/src/components/AskAIDialog.tsx
View file @
e526cef7
...
...
@@ -20,6 +20,7 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
const
fetchingState
=
useLoading
(
false
);
const
[
historyList
,
setHistoryList
]
=
useState
<
History
[]
>
([]);
const
[
isEnabled
,
setIsEnabled
]
=
useState
<
boolean
>
(
true
);
const
[
isInIME
,
setIsInIME
]
=
useState
(
false
);
const
[
question
,
setQuestion
]
=
useState
<
string
>
(
""
);
useEffect
(()
=>
{
...
...
@@ -38,15 +39,22 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
setQuestion
(
event
.
currentTarget
.
value
);
};
const
handleKeyDown
=
(
event
:
React
.
KeyboardEvent
)
=>
{
if
(
event
.
key
===
"Enter"
&&
!
event
.
shiftKey
&&
!
isInIME
)
{
event
.
preventDefault
();
handleSendQuestionButtonClick
();
}
};
const
handleSendQuestionButtonClick
=
async
()
=>
{
fetchingState
.
setLoading
();
setQuestion
(
""
);
try
{
await
askQuestion
(
question
);
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toast
.
error
(
error
.
response
.
data
.
error
);
}
setQuestion
(
""
);
fetchingState
.
setFinish
();
};
...
...
@@ -80,7 +88,17 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
</
div
>
<
div
className=
"dialog-content-container !w-112 max-w-full"
>
<
div
className=
"w-full relative"
>
<
Textarea
className=
"w-full"
placeholder=
"Ask anything…"
value=
{
question
}
onChange=
{
handleQuestionTextareaChange
}
/>
<
Textarea
className=
"w-full"
placeholder=
"Ask anything…"
value=
{
question
}
minRows=
{
1
}
maxRows=
{
5
}
onChange=
{
handleQuestionTextareaChange
}
onCompositionStart=
{
()
=>
setIsInIME
(
true
)
}
onCompositionEnd=
{
()
=>
setIsInIME
(
false
)
}
onKeyDown=
{
handleKeyDown
}
/>
<
Icon
.
Send
className=
"cursor-pointer w-7 p-1 h-auto rounded-md bg-gray-100 dark:bg-zinc-800 absolute right-2 bottom-1.5 shadow hover:opacity-80"
onClick=
{
handleSendQuestionButtonClick
}
...
...
web/src/components/MemoEditor.tsx
View file @
e526cef7
...
...
@@ -52,6 +52,7 @@ const MemoEditor = () => {
isRequesting
:
false
,
});
const
[
allowSave
,
setAllowSave
]
=
useState
<
boolean
>
(
false
);
const
[
isInIME
,
setIsInIME
]
=
useState
(
false
);
const
editorState
=
editorStore
.
state
;
const
prevEditorStateRef
=
useRef
(
editorState
);
const
editorRef
=
useRef
<
EditorRefActions
>
(
null
);
...
...
@@ -113,7 +114,7 @@ const MemoEditor = () => {
return
;
}
}
if
(
event
.
key
===
"Enter"
)
{
if
(
event
.
key
===
"Enter"
&&
!
isInIME
)
{
const
cursorPosition
=
editorRef
.
current
.
getCursorPosition
();
const
contentBeforeCursor
=
editorRef
.
current
.
getContent
().
slice
(
0
,
cursorPosition
);
const
rowValue
=
last
(
contentBeforeCursor
.
split
(
"
\n
"
));
...
...
@@ -394,6 +395,8 @@ const MemoEditor = () => {
onDrop=
{
handleDropEvent
}
onFocus=
{
handleEditorFocus
}
onBlur=
{
handleEditorBlur
}
onCompositionStart=
{
()
=>
setIsInIME
(
true
)
}
onCompositionEnd=
{
()
=>
setIsInIME
(
false
)
}
>
<
Editor
ref=
{
editorRef
}
{
...
editorConfig
}
/>
<
div
className=
"common-tools-wrapper"
>
...
...
web/src/components/Settings/SystemSection.tsx
View file @
e526cef7
...
...
@@ -204,7 +204,7 @@ const SystemSection = () => {
fontFamily
:
"monospace"
,
fontSize
:
"14px"
,
}
}
placeholder=
"
Write onl
y"
placeholder=
"
OpenAI API Ke
y"
value=
{
openAIConfig
.
key
}
onChange=
{
(
event
)
=>
handleOpenAIConfigKeyChanged
(
event
.
target
.
value
)
}
/>
...
...
@@ -217,7 +217,7 @@ const SystemSection = () => {
fontFamily
:
"monospace"
,
fontSize
:
"14px"
,
}
}
placeholder=
"OpenAI Host. Default: https://api.openai.com"
placeholder=
"OpenAI
API
Host. Default: https://api.openai.com"
value=
{
openAIConfig
.
host
}
onChange=
{
(
event
)
=>
handleOpenAIConfigHostChanged
(
event
.
target
.
value
)
}
/>
...
...
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