Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(editor): keep the guide title on one line

davbio1d763787c594
diff --git a/src/ui/fullview/GuideContent.tsx b/src/ui/fullview/GuideContent.tsx
index 0632ce4..28c90da 100644
--- a/src/ui/fullview/GuideContent.tsx
+++ b/src/ui/fullview/GuideContent.tsx
@@ -14,6 +14,7 @@ import {
updateStepDescription,
} from '@/core/guides/service';
import type { SnapshotLike } from '@/core/guides/snapshot-diff';
+import { MAX_TITLE_LENGTH, sanitizeGuideTitle, stripTitleLineBreaks } from '@/core/guides/title';
import type { Guide, Screenshot, Snapshot, Step } from '@/core/guides/types';
import type { ScreenshotEdits } from '@/core/screenshot/types';
import { localStorage, openSidebar } from '@/lib/browser-api';
@@ -140,11 +141,16 @@ export default function GuideContent({ guideId, initialStepId, initialTool }: Gu
}, []);
const handleTitleBlur = useCallback(async () => {
- if (!data || title === data.guide.title) return;
- await updateGuideTitle(guideId, title);
- setData((prev) => (prev ? { ...prev, guide: { ...prev.guide, title } } : prev));
- document.title = `${title} β€” ${i18n.t('app_name')}`;
- }, [data, guideId, title]);
+ const next = sanitizeGuideTitle(title);
+ if (next !== title) {
+ setTitle(next);
+ setGuideTitle(next);
+ }
+ if (!data || next === data.guide.title) return;
+ await updateGuideTitle(guideId, next);
+ setData((prev) => (prev ? { ...prev, guide: { ...prev.guide, title: next } } : prev));
+ document.title = `${next} β€” ${i18n.t('app_name')}`;
+ }, [data, guideId, title, setGuideTitle]);
const handleGuideDescriptionBlur = useCallback(async () => {
if (data && description !== (data.guide.description ?? '')) {
@@ -357,13 +363,22 @@ export default function GuideContent({ guideId, initialStepId, initialTool }: Gu
}}
value={title}
rows={1}
+ maxLength={Math.max(MAX_TITLE_LENGTH, title.length)}
onChange={(e) => {
- setTitle(e.target.value);
- setGuideTitle(e.target.value);
+ const next = stripTitleLineBreaks(e.target.value);
+ setTitle(next);
+ setGuideTitle(next);
const el = e.target;
+ el.value = next;
el.style.height = '0';
el.style.height = `${el.scrollHeight}px`;
}}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' && !e.nativeEvent.isComposing) {
+ e.preventDefault();
+ e.currentTarget.blur();
+ }
+ }}
onBlur={handleTitleBlur}
className="text-[32px] font-extrabold bg-transparent border-b-2 border-transparent hover:border-border focus:outline-none focus:border-accent w-full p-0 text-foreground resize-none leading-tight overflow-hidden"
/>