From 9bfb336eede73ce3f1b1a64c917d25410af3c138 Mon Sep 17 00:00:00 2001 From: Alex Hernandez Date: Fri, 22 May 2026 22:14:58 +1000 Subject: [PATCH] :lipstick: word number position --- src/renderer/components/Editor/Editor.css | 19 ++++++++++++++++++- .../components/Editor/MarkdownEditor.tsx | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/renderer/components/Editor/Editor.css b/src/renderer/components/Editor/Editor.css index 8076afc..28d1d67 100644 --- a/src/renderer/components/Editor/Editor.css +++ b/src/renderer/components/Editor/Editor.css @@ -4,10 +4,27 @@ min-width: 0; height: 100%; overflow: hidden; + display: flex; + flex-direction: column; } .codemirror-host { - height: 100%; + flex: 1; + min-height: 0; + overflow: hidden; +} + +.editor-statusbar { + flex-shrink: 0; + padding: 3px 14px; + font-family: var(--font-sans); + font-size: 11px; + color: var(--text-muted); + text-align: right; + opacity: 0.55; + border-top: 1px solid var(--border); + user-select: none; + pointer-events: none; } .codemirror-host .cm-editor { diff --git a/src/renderer/components/Editor/MarkdownEditor.tsx b/src/renderer/components/Editor/MarkdownEditor.tsx index 9aa2ab3..2b3b82a 100644 --- a/src/renderer/components/Editor/MarkdownEditor.tsx +++ b/src/renderer/components/Editor/MarkdownEditor.tsx @@ -622,6 +622,10 @@ function insertLink(view: EditorView): boolean { return true } +function countWords(text: string): number { + return text.trim() === '' ? 0 : text.trim().split(/\s+/).length +} + export function MarkdownEditor(): JSX.Element { const containerRef = useRef(null) const viewRef = useRef(null) @@ -629,6 +633,8 @@ export function MarkdownEditor(): JSX.Element { const [hasSelection, setHasSelection] = useState(false) const [pendingComment, setPendingComment] = useState<{ from: number; to: number; text: string } | null>(null) const [commentDraft, setCommentDraft] = useState('') + const [wordStats, setWordStats] = useState<{ atCursor: number; total: number }>({ atCursor: 0, total: 0 }) + const wordTotalRef = useRef(0) const { activeFilePath, activeFileContent, setContent, annotations, fontSize, theme, focusMode, scrollPositions, pendingScrollToLine, clearPendingScrollToLine } = useEditorStore() function saveComment(): void { @@ -694,6 +700,12 @@ export function MarkdownEditor(): JSX.Element { EditorView.updateListener.of((update) => { if (update.docChanged) { setContent(update.state.doc.toString()) + wordTotalRef.current = countWords(update.state.doc.toString()) + } + if (update.selectionSet || update.docChanged) { + const head = update.state.selection.main.head + const atCursor = countWords(update.state.doc.sliceString(0, head)) + setWordStats({ atCursor, total: wordTotalRef.current }) } if (update.selectionSet) { const { from, to } = update.state.selection.main @@ -1008,6 +1020,11 @@ export function MarkdownEditor(): JSX.Element { )} + {activeFilePath && ( +
+ word {wordStats.atCursor.toLocaleString()} of {wordStats.total.toLocaleString()} +
+ )} ) }