mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 20:49:01 +01:00
fix(collections/board): double entry on Enter + dismiss not working
This commit is contained in:
parent
ae46798d1d
commit
1ae81abf0a
@ -228,6 +228,7 @@ export function TitleEditor({ currentValue, placeholder, save, dismiss, multilin
|
|||||||
}) {
|
}) {
|
||||||
const inputRef = useRef<any>(null);
|
const inputRef = useRef<any>(null);
|
||||||
const dismissOnNextRefreshRef = useRef(false);
|
const dismissOnNextRefreshRef = useRef(false);
|
||||||
|
const shouldSave = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
@ -251,20 +252,14 @@ export function TitleEditor({ currentValue, placeholder, save, dismiss, multilin
|
|||||||
autoComplete="trilium-title-entry" // forces the auto-fill off better than the "off" value.
|
autoComplete="trilium-title-entry" // forces the auto-fill off better than the "off" value.
|
||||||
rows={multiline ? 4 : undefined}
|
rows={multiline ? 4 : undefined}
|
||||||
onKeyDown={(e: JSX.TargetedKeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
onKeyDown={(e: JSX.TargetedKeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter" || e.key === "Escape") {
|
||||||
const newValue = e.currentTarget?.value;
|
e.preventDefault();
|
||||||
if (newValue.trim() && (newValue !== currentValue || isNewItem)) {
|
shouldSave.current = (e.key === "Enter");
|
||||||
save(newValue);
|
e.currentTarget.blur();
|
||||||
dismissOnNextRefreshRef.current = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.key === "Escape") {
|
|
||||||
dismiss();
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onBlur={(newValue) => {
|
onBlur={(newValue) => {
|
||||||
if (newValue.trim() && (newValue !== currentValue || isNewItem)) {
|
if (shouldSave.current && newValue.trim() && (newValue !== currentValue || isNewItem)) {
|
||||||
save(newValue);
|
save(newValue);
|
||||||
dismissOnNextRefreshRef.current = true;
|
dismissOnNextRefreshRef.current = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user